1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import WidgetContentRow from '~/vue_merge_request_widget/components/widget/widget_content_row.vue';
import StatusIcon from '~/vue_merge_request_widget/components/widget/status_icon.vue';
describe('~/vue_merge_request_widget/components/widget/widget_content_row.vue', () => {
let wrapper;
const findStatusIcon = () => wrapper.findComponent(StatusIcon);
const createComponent = ({ propsData, slots } = {}) => {
wrapper = shallowMountExtended(WidgetContentRow, {
propsData: {
widgetName: 'MyWidget',
level: 2,
...propsData,
},
slots,
});
};
describe('body', () => {
it('renders the status icon when provided', () => {
createComponent({ propsData: { statusIconName: 'failed' } });
expect(findStatusIcon().exists()).toBe(true);
});
it('does not render the status icon when it is not provided', () => {
createComponent();
expect(findStatusIcon().exists()).toBe(false);
});
it('renders slots properly', () => {
createComponent({
propsData: {
statusIconName: 'success',
},
slots: {
header: '<span>this is a header</span>',
body: '<span>this is a body</span>',
},
});
expect(wrapper.findByText('this is a body').exists()).toBe(true);
expect(wrapper.findByText('this is a header').exists()).toBe(true);
});
});
describe('header', () => {
it('renders an array of header and subheader', () => {
createComponent({ propsData: { header: ['this is a header', 'this is a subheader'] } });
expect(wrapper.findByText('this is a header').exists()).toBe(true);
expect(wrapper.findByText('this is a subheader').exists()).toBe(true);
});
it('renders a string', () => {
createComponent({ propsData: { header: 'this is a header' } });
expect(wrapper.findByText('this is a header').exists()).toBe(true);
});
it('escapes html injection properly', () => {
createComponent({ propsData: { header: '<b role="header">this is a header</b>' } });
expect(wrapper.findByText('<b role="header">this is a header</b>').exists()).toBe(true);
});
});
});
|