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
|
import timezoneMock from 'timezone-mock';
import { GlIcon, GlDropdown } from '@gitlab/ui';
import { nextTick } from 'vue';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import IncidentTimelineEventItem from '~/issues/show/components/incidents/timeline_events_item.vue';
import { mockEvents } from './mock_data';
describe('IncidentTimelineEventList', () => {
let wrapper;
const mountComponent = ({ propsData, provide } = {}) => {
const { action, noteHtml, occurredAt } = mockEvents[0];
wrapper = mountExtended(IncidentTimelineEventItem, {
propsData: {
action,
noteHtml,
occurredAt,
isLastItem: false,
...propsData,
},
provide: {
canUpdate: false,
...provide,
},
});
};
const findCommentIcon = () => wrapper.findComponent(GlIcon);
const findTextContainer = () => wrapper.findByTestId('event-text-container');
const findEventTime = () => wrapper.findByTestId('event-time');
const findDropdown = () => wrapper.findComponent(GlDropdown);
const findDeleteButton = () => wrapper.findByText('Delete');
describe('template', () => {
it('shows comment icon', () => {
mountComponent();
expect(findCommentIcon().exists()).toBe(true);
});
it('sets correct props for icon', () => {
mountComponent();
expect(findCommentIcon().props('name')).toBe(mockEvents[0].action);
});
it('displays the correct time', () => {
mountComponent();
expect(findEventTime().text()).toBe('15:59 UTC');
});
describe('last item in list', () => {
it('shows a bottom border when not the last item', () => {
mountComponent();
expect(findTextContainer().classes()).toContain('gl-border-1');
});
it('does not show a bottom border when the last item', () => {
mountComponent({ propsData: { isLastItem: true } });
expect(wrapper.classes()).not.toContain('gl-border-1');
});
});
describe.each`
timezone
${'Europe/London'}
${'US/Pacific'}
${'Australia/Adelaide'}
`('when viewing in timezone', ({ timezone }) => {
describe(timezone, () => {
beforeEach(() => {
timezoneMock.register(timezone);
mountComponent();
});
afterEach(() => {
timezoneMock.unregister();
});
it('displays the correct time', () => {
expect(findEventTime().text()).toBe('15:59 UTC');
});
});
});
describe('action dropdown', () => {
it('does not show the action dropdown by default', () => {
mountComponent();
expect(findDropdown().exists()).toBe(false);
expect(findDeleteButton().exists()).toBe(false);
});
it('shows dropdown and delete item when user has update permission', () => {
mountComponent({ provide: { canUpdate: true } });
expect(findDropdown().exists()).toBe(true);
expect(findDeleteButton().exists()).toBe(true);
});
it('triggers a delete when the delete button is clicked', async () => {
mountComponent({ provide: { canUpdate: true } });
findDeleteButton().trigger('click');
await nextTick();
expect(wrapper.emitted().delete).toBeTruthy();
});
});
});
});
|