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
|
import { GlLoadingIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import { createAlert } from '~/alert';
import FailedJobsApp from '~/pipelines/components/jobs/failed_jobs_app.vue';
import FailedJobsTable from '~/pipelines/components/jobs/failed_jobs_table.vue';
import GetFailedJobsQuery from '~/pipelines/graphql/queries/get_failed_jobs.query.graphql';
import { mockFailedJobsQueryResponse, mockFailedJobsSummaryData } from '../../mock_data';
Vue.use(VueApollo);
jest.mock('~/alert');
describe('Failed Jobs App', () => {
let wrapper;
let resolverSpy;
const findLoadingSpinner = () => wrapper.findComponent(GlLoadingIcon);
const findJobsTable = () => wrapper.findComponent(FailedJobsTable);
const createMockApolloProvider = (resolver) => {
const requestHandlers = [[GetFailedJobsQuery, resolver]];
return createMockApollo(requestHandlers);
};
const createComponent = (resolver, failedJobsSummaryData = mockFailedJobsSummaryData) => {
wrapper = shallowMount(FailedJobsApp, {
provide: {
fullPath: 'root/ci-project',
pipelineIid: 1,
},
propsData: {
failedJobsSummary: failedJobsSummaryData,
},
apolloProvider: createMockApolloProvider(resolver),
});
};
beforeEach(() => {
resolverSpy = jest.fn().mockResolvedValue(mockFailedJobsQueryResponse);
});
describe('loading spinner', () => {
it('displays loading spinner when fetching failed jobs', () => {
createComponent(resolverSpy);
expect(findLoadingSpinner().exists()).toBe(true);
});
it('hides loading spinner after the failed jobs have been fetched', async () => {
createComponent(resolverSpy);
await waitForPromises();
expect(findLoadingSpinner().exists()).toBe(false);
});
});
it('displays the failed jobs table', async () => {
createComponent(resolverSpy);
await waitForPromises();
expect(findJobsTable().exists()).toBe(true);
expect(createAlert).not.toHaveBeenCalled();
});
it('handles query fetch error correctly', async () => {
resolverSpy = jest.fn().mockRejectedValue(new Error('GraphQL error'));
createComponent(resolverSpy);
await waitForPromises();
expect(createAlert).toHaveBeenCalledWith({
message: 'There was a problem fetching the failed jobs.',
});
});
});
|