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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
import { GlBadge } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import IssuableBody from '~/vue_shared/issuable/show/components/issuable_body.vue';
import IssuableHeader from '~/vue_shared/issuable/show/components/issuable_header.vue';
import IssuableShowRoot from '~/vue_shared/issuable/show/components/issuable_show_root.vue';
import IssuableSidebar from '~/vue_shared/issuable/sidebar/components/issuable_sidebar_root.vue';
import { mockIssuableShowProps, mockIssuable } from '../mock_data';
const createComponent = (propsData = mockIssuableShowProps) =>
shallowMount(IssuableShowRoot, {
propsData,
stubs: {
IssuableHeader,
IssuableBody,
IssuableSidebar,
},
slots: {
'status-badge': 'Open',
'header-actions': `
<button class="js-close">Close issuable</button>
<a class="js-new" href="/gitlab-org/gitlab-shell/-/issues/new">New issuable</a>
`,
'edit-form-actions': `
<button class="js-save">Save changes</button>
<button class="js-cancel">Cancel</button>
`,
'right-sidebar-items': `
<div class="js-todo">
To Do <button class="js-add-todo">Add a To Do</button>
</div>
`,
},
});
describe('IssuableShowRoot', () => {
let wrapper;
beforeEach(() => {
wrapper = createComponent();
});
describe('template', () => {
const {
statusIcon,
statusIconClass,
enableEdit,
enableAutocomplete,
editFormVisible,
descriptionPreviewPath,
descriptionHelpPath,
taskCompletionStatus,
workspaceType,
} = mockIssuableShowProps;
const { state, blocked, confidential, createdAt, author } = mockIssuable;
it('renders component container element with class `issuable-show-container`', () => {
expect(wrapper.classes()).toContain('issuable-show-container');
});
it('renders issuable-header component', () => {
const issuableHeader = wrapper.findComponent(IssuableHeader);
expect(issuableHeader.exists()).toBe(true);
expect(issuableHeader.props()).toMatchObject({
issuableState: state,
statusIcon,
statusIconClass,
blocked,
confidential,
createdAt,
author,
taskCompletionStatus,
});
expect(issuableHeader.findComponent(GlBadge).text()).toBe('Open');
expect(issuableHeader.find('.detail-page-header-actions button.js-close').exists()).toBe(
true,
);
expect(issuableHeader.find('.detail-page-header-actions a.js-new').exists()).toBe(true);
});
it('renders issuable-body component', () => {
const issuableBody = wrapper.findComponent(IssuableBody);
expect(issuableBody.exists()).toBe(true);
expect(issuableBody.props()).toMatchObject({
issuable: mockIssuable,
statusIcon,
enableEdit,
enableAutocomplete,
editFormVisible,
descriptionPreviewPath,
descriptionHelpPath,
workspaceType,
});
});
it('renders issuable-sidebar component', () => {
const issuableSidebar = wrapper.findComponent(IssuableSidebar);
expect(issuableSidebar.exists()).toBe(true);
});
describe('events', () => {
it('component emits `edit-issuable` event bubbled via issuable-body', () => {
const issuableBody = wrapper.findComponent(IssuableBody);
issuableBody.vm.$emit('edit-issuable');
expect(wrapper.emitted('edit-issuable')).toHaveLength(1);
});
it('component emits `task-list-update-success` event bubbled via issuable-body', () => {
const issuableBody = wrapper.findComponent(IssuableBody);
const eventParam = {
foo: 'bar',
};
issuableBody.vm.$emit('task-list-update-success', eventParam);
expect(wrapper.emitted('task-list-update-success')).toHaveLength(1);
expect(wrapper.emitted('task-list-update-success')[0]).toEqual([eventParam]);
});
it('component emits `task-list-update-failure` event bubbled via issuable-body', () => {
const issuableBody = wrapper.findComponent(IssuableBody);
issuableBody.vm.$emit('task-list-update-failure');
expect(wrapper.emitted('task-list-update-failure')).toHaveLength(1);
});
it.each(['keydown-title', 'keydown-description'])(
'component emits `%s` event with event object and issuableMeta params via issuable-body',
(eventName) => {
const eventObj = {
preventDefault: jest.fn(),
stopPropagation: jest.fn(),
};
const issuableMeta = {
issuableTitle: 'foo',
issuableDescription: 'foobar',
};
const issuableBody = wrapper.findComponent(IssuableBody);
issuableBody.vm.$emit(eventName, eventObj, issuableMeta);
expect(wrapper.emitted()).toHaveProperty(eventName);
expect(wrapper.emitted(eventName)[0]).toMatchObject([eventObj, issuableMeta]);
},
);
});
});
});
|