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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
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';
import ActionButtons from '~/vue_merge_request_widget/components/action_buttons.vue';
import HelpPopover from '~/vue_shared/components/help_popover.vue';
describe('~/vue_merge_request_widget/components/widget/widget_content_row.vue', () => {
let wrapper;
const findStatusIcon = () => wrapper.findComponent(StatusIcon);
const findHelpPopover = () => wrapper.findComponent(HelpPopover);
const findActionButtons = () => wrapper.findComponent(ActionButtons);
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);
});
it('renders a help popover', () => {
createComponent({
propsData: {
helpPopover: {
options: { title: 'Help popover title' },
content: { text: 'Help popover content', learnMorePath: '/path/to/docs' },
},
},
});
expect(findHelpPopover().props('options')).toEqual({ title: 'Help popover title' });
expect(wrapper.findByText('Help popover content').exists()).toBe(true);
expect(wrapper.findByText('Learn more').attributes('href')).toBe('/path/to/docs');
expect(wrapper.findByText('Learn more').attributes('target')).toBe('_blank');
});
it('does not render help popover when it is not provided', () => {
createComponent({});
expect(findHelpPopover().exists()).toBe(false);
});
it('does not display action buttons if actionButtons is not provided', () => {
createComponent({});
expect(findActionButtons().exists()).toBe(false);
});
it('does display action buttons if actionButtons is provided', () => {
const actionButtons = [{ text: 'click-me', href: '#' }];
createComponent({ propsData: { actionButtons } });
expect(findActionButtons().props('tertiaryButtons')).toEqual(actionButtons);
});
});
});
|