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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
|
import { GlEmptyState, GlLoadingIcon, GlTable } from '@gitlab/ui';
import { shallowMount, mount } from '@vue/test-utils';
import { nextTick } from 'vue';
import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import StageTable from '~/cycle_analytics/components/stage_table.vue';
import { PAGINATION_SORT_FIELD_DURATION } from '~/cycle_analytics/constants';
import { issueEvents, issueStage, reviewStage, reviewEvents } from './mock_data';
let wrapper = null;
let trackingSpy = null;
const noDataSvgPath = 'path/to/no/data';
const emptyStateTitle = 'Too much data';
const notEnoughDataError = "We don't have enough data to show this stage.";
const issueEventItems = issueEvents.events;
const reviewEventItems = reviewEvents.events;
const [firstIssueEvent] = issueEventItems;
const [firstReviewEvent] = reviewEventItems;
const pagination = { page: 1, hasNextPage: true };
const findStageEvents = () => wrapper.findAllByTestId('vsa-stage-event');
const findPagination = () => wrapper.findByTestId('vsa-stage-pagination');
const findTable = () => wrapper.findComponent(GlTable);
const findTableHead = () => wrapper.find('thead');
const findTableHeadColumns = () => findTableHead().findAll('th');
const findStageEventTitle = (ev) => extendedWrapper(ev).findByTestId('vsa-stage-event-title');
const findStageEventLink = (ev) => extendedWrapper(ev).findByTestId('vsa-stage-event-link');
const findStageTime = () => wrapper.findByTestId('vsa-stage-event-time');
const findStageLastEvent = () => wrapper.findByTestId('vsa-stage-last-event');
const findIcon = (name) => wrapper.findByTestId(`${name}-icon`);
function createComponent(props = {}, shallow = false) {
const func = shallow ? shallowMount : mount;
return extendedWrapper(
func(StageTable, {
propsData: {
isLoading: false,
stageEvents: issueEventItems,
noDataSvgPath,
selectedStage: issueStage,
pagination,
...props,
},
stubs: {
GlLoadingIcon,
GlEmptyState,
},
}),
);
}
describe('StageTable', () => {
afterEach(() => {
wrapper.destroy();
});
describe('is loaded with data', () => {
beforeEach(() => {
wrapper = createComponent();
});
it('will render the correct events', () => {
const evs = findStageEvents();
expect(evs).toHaveLength(issueEventItems.length);
const titles = evs.wrappers.map((ev) => findStageEventTitle(ev).text());
issueEventItems.forEach((ev, index) => {
expect(titles[index]).toBe(ev.title);
});
});
it('will not display the default data message', () => {
expect(wrapper.html()).not.toContain(notEnoughDataError);
});
});
describe('with minimal stage data', () => {
beforeEach(() => {
wrapper = createComponent({ currentStage: { title: 'New stage title' } });
});
it('will render the correct events', () => {
const evs = findStageEvents();
expect(evs).toHaveLength(issueEventItems.length);
const titles = evs.wrappers.map((ev) => findStageEventTitle(ev).text());
issueEventItems.forEach((ev, index) => {
expect(titles[index]).toBe(ev.title);
});
});
it('will not display the project name in the record link', () => {
const evs = findStageEvents();
const links = evs.wrappers.map((ev) => findStageEventLink(ev).text());
issueEventItems.forEach((ev, index) => {
expect(links[index]).toBe(`#${ev.iid}`);
});
});
});
describe('default event', () => {
beforeEach(() => {
wrapper = createComponent({
stageEvents: [{ ...firstIssueEvent }],
selectedStage: { ...issueStage, custom: false },
});
});
it('will render the event title', () => {
expect(wrapper.findByTestId('vsa-stage-event-title').text()).toBe(firstIssueEvent.title);
});
it('will set the workflow title to "Issues"', () => {
expect(findTableHead().text()).toContain('Issues');
});
it('does not render the fork icon', () => {
expect(findIcon('fork').exists()).toBe(false);
});
it('does not render the branch icon', () => {
expect(findIcon('commit').exists()).toBe(false);
});
it('will render the total time', () => {
const createdAt = firstIssueEvent.createdAt.replace(' ago', '');
expect(findStageTime().text()).toBe(createdAt);
});
it('will render the end event', () => {
expect(findStageLastEvent().text()).toBe(firstIssueEvent.endEventTimestamp);
});
it('will render the author', () => {
expect(wrapper.findByTestId('vsa-stage-event-author').text()).toContain(
firstIssueEvent.author.name,
);
});
it('will render the created at date', () => {
expect(wrapper.findByTestId('vsa-stage-event-date').text()).toContain(
firstIssueEvent.createdAt,
);
});
});
describe('merge request event', () => {
beforeEach(() => {
wrapper = createComponent({
stageEvents: [{ ...firstReviewEvent }],
selectedStage: { ...reviewStage, custom: false },
});
});
it('will set the workflow title to "Merge requests"', () => {
expect(findTableHead().text()).toContain('Merge requests');
expect(findTableHead().text()).not.toContain('Issues');
});
});
describe('isLoading = true', () => {
beforeEach(() => {
wrapper = createComponent({ isLoading: true }, true);
});
it('will display the loading icon', () => {
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(true);
});
it('will not display pagination', () => {
expect(findPagination().exists()).toBe(false);
});
});
describe('with no stageEvents', () => {
beforeEach(() => {
wrapper = createComponent({ stageEvents: [] });
});
it('will render the empty state', () => {
expect(wrapper.findComponent(GlEmptyState).exists()).toBe(true);
});
it('will display the default no data message', () => {
expect(wrapper.html()).toContain(notEnoughDataError);
});
it('will not display the pagination component', () => {
expect(findPagination().exists()).toBe(false);
});
});
describe('emptyStateTitle set', () => {
beforeEach(() => {
wrapper = createComponent({ stageEvents: [], emptyStateTitle });
});
it('will display the custom message', () => {
expect(wrapper.html()).not.toContain(notEnoughDataError);
expect(wrapper.html()).toContain(emptyStateTitle);
});
});
describe('includeProjectName set', () => {
const fakenamespace = 'some/fake/path';
beforeEach(() => {
wrapper = createComponent({ includeProjectName: true });
});
it('will display the project name in the record link', () => {
const evs = findStageEvents();
const links = evs.wrappers.map((ev) => findStageEventLink(ev).text());
issueEventItems.forEach((ev, index) => {
expect(links[index]).toBe(`${ev.projectPath}#${ev.iid}`);
});
});
describe.each`
namespaceFullPath | hasFullPath
${'fake'} | ${false}
${fakenamespace} | ${true}
`('with a namespace', ({ namespaceFullPath, hasFullPath }) => {
let evs = null;
let links = null;
beforeEach(() => {
wrapper = createComponent({
includeProjectName: true,
stageEvents: issueEventItems.map((ie) => ({ ...ie, namespaceFullPath })),
});
evs = findStageEvents();
links = evs.wrappers.map((ev) => findStageEventLink(ev).text());
});
it(`with namespaceFullPath='${namespaceFullPath}' ${
hasFullPath ? 'will' : 'does not'
} include the namespace`, () => {
issueEventItems.forEach((ev, index) => {
if (hasFullPath) {
expect(links[index]).toBe(`${namespaceFullPath}/${ev.projectPath}#${ev.iid}`);
} else {
expect(links[index]).toBe(`${ev.projectPath}#${ev.iid}`);
}
});
});
});
});
describe('Pagination', () => {
beforeEach(() => {
wrapper = createComponent();
trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);
});
afterEach(() => {
unmockTracking();
wrapper.destroy();
});
it('will display the pagination component', () => {
expect(findPagination().exists()).toBe(true);
});
it('clicking prev or next will emit an event', async () => {
expect(wrapper.emitted('handleUpdatePagination')).toBeUndefined();
findPagination().vm.$emit('input', 2);
await nextTick();
expect(wrapper.emitted('handleUpdatePagination')[0]).toEqual([{ page: 2 }]);
});
it('clicking prev or next will send tracking information', () => {
findPagination().vm.$emit('input', 2);
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_button', { label: 'pagination' });
});
describe('with `hasNextPage=false', () => {
beforeEach(() => {
wrapper = createComponent({ pagination: { page: 1, hasNextPage: false } });
});
it('will not display the pagination component', () => {
expect(findPagination().exists()).toBe(false);
});
});
});
describe('Sorting', () => {
const triggerTableSort = (sortDesc = true) =>
findTable().vm.$emit('sort-changed', {
sortBy: PAGINATION_SORT_FIELD_DURATION,
sortDesc,
});
beforeEach(() => {
wrapper = createComponent();
trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);
});
afterEach(() => {
unmockTracking();
wrapper.destroy();
});
it('can sort the end event or duration', () => {
findTableHeadColumns()
.wrappers.slice(1)
.forEach((w) => {
expect(w.attributes('aria-sort')).toBe('none');
});
});
it('cannot be sorted by title', () => {
findTableHeadColumns()
.wrappers.slice(0, 1)
.forEach((w) => {
expect(w.attributes('aria-sort')).toBeUndefined();
});
});
it('clicking a table column will send tracking information', () => {
triggerTableSort();
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_button', {
label: 'sort_duration_desc',
});
});
it('clicking a table column will update the sort field', () => {
expect(wrapper.emitted('handleUpdatePagination')).toBeUndefined();
triggerTableSort();
expect(wrapper.emitted('handleUpdatePagination')[0]).toEqual([
{
direction: 'desc',
sort: 'duration',
},
]);
});
it('with sortDesc=false will toggle the direction field', () => {
expect(wrapper.emitted('handleUpdatePagination')).toBeUndefined();
triggerTableSort(false);
expect(wrapper.emitted('handleUpdatePagination')[0]).toEqual([
{
direction: 'asc',
sort: 'duration',
},
]);
});
describe('with sortable=false', () => {
beforeEach(() => {
wrapper = createComponent({ sortable: false });
});
it('cannot sort the table', () => {
findTableHeadColumns().wrappers.forEach((w) => {
expect(w.attributes('aria-sort')).toBeUndefined();
});
});
});
});
});
|