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
|
import { GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import TimeAgo from '~/pipelines/components/pipelines_list/time_ago.vue';
describe('Timeago component', () => {
let wrapper;
const defaultProps = { duration: 0, finished_at: '' };
const createComponent = (props = defaultProps, stuck = false, extraProps) => {
wrapper = extendedWrapper(
shallowMount(TimeAgo, {
propsData: {
pipeline: {
details: {
...props,
},
flags: {
stuck,
},
},
...extraProps,
},
data() {
return {
iconTimerSvg: `<svg></svg>`,
};
},
}),
);
};
const duration = () => wrapper.find('.duration');
const finishedAt = () => wrapper.find('.finished-at');
const findInProgress = () => wrapper.findByTestId('pipeline-in-progress');
const findSkipped = () => wrapper.findByTestId('pipeline-skipped');
const findHourGlassIcon = () => wrapper.findByTestId('hourglass-icon');
const findWarningIcon = () => wrapper.findByTestId('warning-icon');
const findCalendarIcon = () => wrapper.findByTestId('calendar-icon');
describe('with duration', () => {
beforeEach(() => {
createComponent({ duration: 10, finished_at: '' });
});
it('should render duration and timer svg', () => {
const icon = duration().findComponent(GlIcon);
expect(duration().exists()).toBe(true);
expect(icon.props('name')).toBe('timer');
});
});
describe('without duration', () => {
beforeEach(() => {
createComponent();
});
it('should not render duration and timer svg', () => {
expect(duration().exists()).toBe(false);
});
});
describe('with finishedTime', () => {
it('should render time', () => {
createComponent({ duration: 0, finished_at: '2017-04-26T12:40:23.277Z' });
const time = finishedAt().find('time');
expect(finishedAt().exists()).toBe(true);
expect(time.exists()).toBe(true);
});
it('should display calendar icon by default', () => {
createComponent({ duration: 0, finished_at: '2017-04-26T12:40:23.277Z' });
expect(findCalendarIcon().exists()).toBe(true);
});
it('should hide calendar icon if correct prop is passed', () => {
createComponent({ duration: 0, finished_at: '2017-04-26T12:40:23.277Z' }, false, {
displayCalendarIcon: false,
});
expect(findCalendarIcon().exists()).toBe(false);
});
});
describe('without finishedTime', () => {
beforeEach(() => {
createComponent();
});
it('should not render time and calendar icon', () => {
expect(finishedAt().exists()).toBe(false);
expect(findCalendarIcon().exists()).toBe(false);
});
});
describe('in progress', () => {
it.each`
durationTime | finishedAtTime | shouldShow
${10} | ${'2017-04-26T12:40:23.277Z'} | ${false}
${10} | ${''} | ${false}
${0} | ${'2017-04-26T12:40:23.277Z'} | ${false}
${0} | ${''} | ${true}
`(
'progress state shown: $shouldShow when pipeline duration is $durationTime and finished_at is $finishedAtTime',
({ durationTime, finishedAtTime, shouldShow }) => {
createComponent({
duration: durationTime,
finished_at: finishedAtTime,
});
expect(findInProgress().exists()).toBe(shouldShow);
expect(findSkipped().exists()).toBe(false);
},
);
it('should show warning icon beside in progress if pipeline is stuck', () => {
const stuck = true;
createComponent(defaultProps, stuck);
expect(findWarningIcon().exists()).toBe(true);
expect(findHourGlassIcon().exists()).toBe(false);
});
});
describe('skipped', () => {
it('should show skipped if pipeline was skipped', () => {
createComponent({
status: { label: 'skipped' },
});
expect(findSkipped().exists()).toBe(true);
expect(findInProgress().exists()).toBe(false);
});
});
});
|