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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
import { GlIcon, GlLink, GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { TEST_HOST } from 'helpers/test_constants';
import IssueDueDate from '~/boards/components/issue_due_date.vue';
import { formatDate } from '~/lib/utils/datetime_utility';
import { updateHistory } from '~/lib/utils/url_utility';
import { __ } from '~/locale';
import RelatedIssuableItem from '~/issuable/components/related_issuable_item.vue';
import IssueMilestone from '~/issuable/components/issue_milestone.vue';
import IssueAssignees from '~/issuable/components/issue_assignees.vue';
import WorkItemDetailModal from '~/work_items/components/work_item_detail_modal.vue';
import { defaultAssignees, defaultMilestone } from './related_issuable_mock_data';
jest.mock('~/lib/utils/url_utility', () => ({
...jest.requireActual('~/lib/utils/url_utility'),
updateHistory: jest.fn(),
}));
describe('RelatedIssuableItem', () => {
let wrapper;
const defaultProps = {
idKey: 1,
displayReference: 'gitlab-org/gitlab-test#1',
pathIdSeparator: '#',
path: `${TEST_HOST}/path`,
title: 'title',
confidential: true,
dueDate: '1990-12-31',
weight: 10,
createdAt: '2018-12-01T00:00:00.00Z',
milestone: defaultMilestone,
assignees: defaultAssignees,
eventNamespace: 'relatedIssue',
};
const findIcon = () => wrapper.findComponent(GlIcon);
const findIssueDueDate = () => wrapper.findComponent(IssueDueDate);
const findLockIcon = () => wrapper.find('[data-testid="lockIcon"]');
const findRemoveButton = () => wrapper.findComponent(GlButton);
const findTitleLink = () => wrapper.findComponent(GlLink);
const findWorkItemDetailModal = () => wrapper.findComponent(WorkItemDetailModal);
function mountComponent({ data = {}, props = {} } = {}) {
wrapper = shallowMount(RelatedIssuableItem, {
propsData: {
...defaultProps,
...props,
},
data() {
return data;
},
});
}
it('contains issuable-info-container class when canReorder is false', () => {
mountComponent({ props: { canReorder: false } });
expect(wrapper.classes('issuable-info-container')).toBe(true);
});
it('does not render token state', () => {
mountComponent();
expect(wrapper.find('.text-secondary svg').exists()).toBe(false);
});
it('does not render remove button', () => {
mountComponent();
expect(findRemoveButton().exists()).toBe(false);
});
describe('token title', () => {
beforeEach(() => {
mountComponent();
});
it('links to computedPath', () => {
expect(findTitleLink().attributes('href')).toBe(defaultProps.path);
});
it('renders confidential icon', () => {
expect(findIcon().attributes('title')).toBe(__('Confidential'));
});
it('renders title', () => {
expect(findTitleLink().text()).toBe(defaultProps.title);
});
});
describe('token state', () => {
it('renders state title', () => {
mountComponent({ props: { state: 'opened' } });
const stateTitle = findIcon().attributes('title');
const formattedCreateDate = formatDate(defaultProps.createdAt);
expect(stateTitle).toContain('<span class="bold">Created</span>');
expect(stateTitle).toContain(`<span class="text-tertiary">${formattedCreateDate}</span>`);
});
it('renders aria label', () => {
mountComponent({ props: { state: 'opened' } });
expect(findIcon().attributes('arialabel')).toBe('opened');
});
it('renders open icon when open state', () => {
mountComponent({ props: { state: 'opened' } });
expect(findIcon().props('name')).toBe('issue-open-m');
expect(findIcon().classes('issue-token-state-icon-open')).toBe(true);
});
it('renders close icon when close state', () => {
mountComponent({ props: { state: 'closed', closedAt: '2018-12-01T00:00:00.00Z' } });
expect(findIcon().props('name')).toBe('issue-close');
expect(findIcon().classes('issue-token-state-icon-closed')).toBe(true);
});
});
describe('token metadata', () => {
const tokenMetadata = () => wrapper.find('.item-meta');
it('renders item path and ID', () => {
mountComponent();
const pathAndID = tokenMetadata().find('.item-path-id').text();
expect(pathAndID).toContain('gitlab-org/gitlab-test');
expect(pathAndID).toContain('#1');
});
it('renders milestone', () => {
mountComponent();
expect(wrapper.findComponent(IssueMilestone).props('milestone')).toEqual(
defaultProps.milestone,
);
});
it('renders due date component with correct due date', () => {
mountComponent();
expect(findIssueDueDate().props('date')).toBe(defaultProps.dueDate);
});
it('does not render red icon for overdue issue that is closed', () => {
mountComponent({ props: { closedAt: '2018-12-01T00:00:00.00Z' } });
expect(findIssueDueDate().props('closed')).toBe(true);
});
});
describe('token assignees', () => {
it('renders assignees avatars', () => {
mountComponent();
expect(wrapper.findComponent(IssueAssignees).props('assignees')).toEqual(
defaultProps.assignees,
);
});
});
describe('remove button', () => {
beforeEach(() => {
mountComponent({ props: { canRemove: true }, data: { removeDisabled: true } });
});
it('renders if canRemove', () => {
expect(findRemoveButton().props('icon')).toBe('close');
expect(findRemoveButton().attributes('aria-label')).toBe(__('Remove'));
});
it('does not render the lock icon', () => {
expect(findLockIcon().exists()).toBe(false);
});
it('renders disabled button when removeDisabled', () => {
expect(findRemoveButton().attributes('disabled')).toBe('true');
});
it('triggers onRemoveRequest when clicked', () => {
findRemoveButton().vm.$emit('click');
expect(wrapper.emitted('relatedIssueRemoveRequest')).toEqual([[defaultProps.idKey]]);
});
});
describe('when issue is locked', () => {
const lockedMessage = 'Issues created from a vulnerability cannot be removed';
beforeEach(() => {
mountComponent({ props: { isLocked: true, lockedMessage } });
});
it('does not render the remove button', () => {
expect(findRemoveButton().exists()).toBe(false);
});
it('renders the lock icon with the correct title', () => {
expect(findLockIcon().attributes('title')).toBe(lockedMessage);
});
});
describe('work item modal', () => {
const workItem = 'gid://gitlab/WorkItem/1';
it('renders', () => {
mountComponent();
expect(findWorkItemDetailModal().props('workItemId')).toBe(workItem);
});
describe('when work item is issue and the related issue title is clicked', () => {
it('does not open', () => {
mountComponent({ props: { workItemType: 'ISSUE' } });
wrapper.vm.$refs.modal.show = jest.fn();
findTitleLink().vm.$emit('click', { preventDefault: () => {} });
expect(wrapper.vm.$refs.modal.show).not.toHaveBeenCalled();
});
});
describe('when work item is task and the related issue title is clicked', () => {
beforeEach(() => {
mountComponent({ props: { workItemType: 'TASK' } });
wrapper.vm.$refs.modal.show = jest.fn();
findTitleLink().vm.$emit('click', { preventDefault: () => {} });
});
it('opens', () => {
expect(wrapper.vm.$refs.modal.show).toHaveBeenCalled();
});
it('updates the url params with the work item id', () => {
expect(updateHistory).toHaveBeenCalledWith({
url: `${TEST_HOST}/?work_item_id=1`,
replace: true,
});
});
});
describe('when it emits "workItemDeleted" event', () => {
it('emits "relatedIssueRemoveRequest" event', () => {
mountComponent();
findWorkItemDetailModal().vm.$emit('workItemDeleted', workItem);
expect(wrapper.emitted('relatedIssueRemoveRequest')).toEqual([[workItem]]);
});
});
describe('when it emits "close" event', () => {
it('removes the work item id from the url params', () => {
mountComponent();
findWorkItemDetailModal().vm.$emit('close');
expect(updateHistory).toHaveBeenCalledWith({
url: `${TEST_HOST}/`,
replace: true,
});
});
});
});
});
|