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
|
import { GlEmptyState, GlLoadingIcon } from '@gitlab/ui';
import VueApollo from 'vue-apollo';
import Vue from 'vue';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises';
import TimelineEventsTab from '~/issues/show/components/incidents/timeline_events_tab.vue';
import IncidentTimelineEventsList from '~/issues/show/components/incidents/timeline_events_list.vue';
import timelineEventsQuery from '~/issues/show/components/incidents/graphql/queries/get_timeline_events.query.graphql';
import createMockApollo from 'helpers/mock_apollo_helper';
import { createAlert } from '~/flash';
import { timelineEventsQueryListResponse, timelineEventsQueryEmptyResponse } from './mock_data';
Vue.use(VueApollo);
jest.mock('~/flash');
const graphQLError = new Error('GraphQL error');
const listResponse = jest.fn().mockResolvedValue(timelineEventsQueryListResponse);
const emptyResponse = jest.fn().mockResolvedValue(timelineEventsQueryEmptyResponse);
const errorResponse = jest.fn().mockRejectedValue(graphQLError);
function createMockApolloProvider(response = listResponse) {
const requestHandlers = [[timelineEventsQuery, response]];
return createMockApollo(requestHandlers);
}
describe('TimelineEventsTab', () => {
let wrapper;
const mountComponent = (options = {}) => {
const { mockApollo, mountMethod = shallowMountExtended } = options;
wrapper = mountMethod(TimelineEventsTab, {
provide: {
fullPath: 'group/project',
issuableId: '1',
},
apolloProvider: mockApollo,
});
};
afterEach(() => {
if (wrapper) {
wrapper.destroy();
}
});
const findLoadingSpinner = () => wrapper.findComponent(GlLoadingIcon);
const findEmptyState = () => wrapper.findComponent(GlEmptyState);
const findTimelineEventsList = () => wrapper.findComponent(IncidentTimelineEventsList);
describe('Timeline events tab', () => {
describe('empty state', () => {
let mockApollo;
it('should show an empty list', async () => {
mockApollo = createMockApolloProvider(emptyResponse);
mountComponent({ mockApollo });
await waitForPromises();
expect(findEmptyState().exists()).toBe(true);
});
});
describe('error state', () => {
let mockApollo;
it('should show an error state', async () => {
mockApollo = createMockApolloProvider(errorResponse);
mountComponent({ mockApollo });
await waitForPromises();
expect(createAlert).toHaveBeenCalledWith({
captureError: true,
error: graphQLError,
message: 'Something went wrong while fetching incident timeline events.',
});
});
});
});
describe('timelineEventsQuery', () => {
let mockApollo;
beforeEach(() => {
mockApollo = createMockApolloProvider();
mountComponent({ mockApollo });
});
it('should request data', () => {
expect(listResponse).toHaveBeenCalled();
});
it('should show the loading state', () => {
expect(findEmptyState().exists()).toBe(false);
expect(findLoadingSpinner().exists()).toBe(true);
});
it('should render the list', async () => {
await waitForPromises();
expect(findEmptyState().exists()).toBe(false);
expect(findTimelineEventsList().props('timelineEvents')).toHaveLength(3);
});
});
});
|