2020-07-28 23:09:34 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2021-04-17 20:07:23 +05:30
|
|
|
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
|
2022-06-21 17:19:12 +05:30
|
|
|
import HelpPopover from '~/vue_shared/components/help_popover.vue';
|
2020-07-28 23:09:34 +05:30
|
|
|
import SummaryRow from '~/reports/components/summary_row.vue';
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
describe('Summary row', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
let wrapper;
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
const summary = 'SAST detected 1 new vulnerability and 1 fixed vulnerability';
|
|
|
|
const popoverOptions = {
|
|
|
|
title: 'Static Application Security Testing (SAST)',
|
|
|
|
content: '<a>Learn more about SAST</a>',
|
2018-11-18 11:00:15 +05:30
|
|
|
};
|
2022-06-21 17:19:12 +05:30
|
|
|
const statusIcon = 'warning';
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
const createComponent = ({ props = {}, slots = {} } = {}) => {
|
2021-04-17 20:07:23 +05:30
|
|
|
wrapper = extendedWrapper(
|
|
|
|
mount(SummaryRow, {
|
|
|
|
propsData: {
|
2022-06-21 17:19:12 +05:30
|
|
|
summary,
|
|
|
|
popoverOptions,
|
|
|
|
statusIcon,
|
2021-04-17 20:07:23 +05:30
|
|
|
...props,
|
|
|
|
},
|
|
|
|
slots,
|
|
|
|
}),
|
|
|
|
);
|
2020-07-28 23:09:34 +05:30
|
|
|
};
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
const findSummary = () => wrapper.findByTestId('summary-row-description');
|
|
|
|
const findStatusIcon = () => wrapper.findByTestId('summary-row-icon');
|
2022-06-21 17:19:12 +05:30
|
|
|
const findHelpPopover = () => wrapper.findComponent(HelpPopover);
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
afterEach(() => {
|
2020-07-28 23:09:34 +05:30
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
2018-11-18 11:00:15 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders provided summary', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
createComponent();
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(findSummary().text()).toContain(summary);
|
2018-11-18 11:00:15 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders provided icon', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
createComponent();
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(findStatusIcon().classes()).toContain('js-ci-status-icon-warning');
|
2018-11-18 11:00:15 +05:30
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it('renders help popover if popoverOptions are provided', () => {
|
|
|
|
createComponent();
|
|
|
|
expect(findHelpPopover().props('options')).toEqual(popoverOptions);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render help popover if popoverOptions are not provided', () => {
|
|
|
|
createComponent({ props: { popoverOptions: null } });
|
|
|
|
expect(findHelpPopover().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
describe('summary slot', () => {
|
|
|
|
it('replaces the summary prop', () => {
|
|
|
|
const summarySlotContent = 'Summary slot content';
|
|
|
|
createComponent({ slots: { summary: summarySlotContent } });
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(wrapper.text()).not.toContain(summary);
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(findSummary().text()).toContain(summarySlotContent);
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
});
|