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
|
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import SidebarHeader from '~/ci/job_details/components/sidebar/sidebar_header.vue';
import JobRetryButton from '~/ci/job_details/components/sidebar/job_sidebar_retry_button.vue';
import getJobQuery from '~/ci/job_details/graphql/queries/get_job.query.graphql';
import { mockFullPath, mockId, mockJobResponse } from '../../mock_data';
Vue.use(VueApollo);
const defaultProvide = {
projectPath: mockFullPath,
};
describe('Sidebar Header', () => {
let wrapper;
const createComponent = ({ options = {}, props = {}, restJob = {} } = {}) => {
wrapper = shallowMountExtended(SidebarHeader, {
propsData: {
...props,
jobId: mockId,
restJob,
},
provide: {
...defaultProvide,
},
...options,
});
};
const createComponentWithApollo = ({ props = {}, restJob = {} } = {}) => {
const getJobQueryResponse = jest.fn().mockResolvedValue(mockJobResponse);
const requestHandlers = [[getJobQuery, getJobQueryResponse]];
const apolloProvider = createMockApollo(requestHandlers);
const options = {
apolloProvider,
};
createComponent({
props,
restJob,
options,
});
return waitForPromises();
};
const findCancelButton = () => wrapper.findByTestId('cancel-button');
const findEraseButton = () => wrapper.findByTestId('job-log-erase-link');
const findNewIssueButton = () => wrapper.findByTestId('job-new-issue');
const findTerminalLink = () => wrapper.findByTestId('terminal-link');
const findJobName = () => wrapper.findByTestId('job-name');
const findRetryButton = () => wrapper.findComponent(JobRetryButton);
describe('when rendering contents', () => {
it('renders the correct job name', async () => {
await createComponentWithApollo();
expect(findJobName().text()).toBe(mockJobResponse.data.project.job.name);
});
it('does not render buttons with no paths', async () => {
await createComponentWithApollo();
expect(findCancelButton().exists()).toBe(false);
expect(findEraseButton().exists()).toBe(false);
expect(findRetryButton().exists()).toBe(false);
expect(findNewIssueButton().exists()).toBe(false);
expect(findTerminalLink().exists()).toBe(false);
});
it('renders a retry button with a path', async () => {
await createComponentWithApollo({ restJob: { retry_path: 'retry/path' } });
expect(findRetryButton().exists()).toBe(true);
});
it('renders a cancel button with a path', async () => {
await createComponentWithApollo({ restJob: { cancel_path: 'cancel/path' } });
expect(findCancelButton().exists()).toBe(true);
});
it('renders an erase button with a path', async () => {
await createComponentWithApollo({ restJob: { erase_path: 'erase/path' } });
expect(findEraseButton().exists()).toBe(true);
});
it('should render link to new issue', async () => {
await createComponentWithApollo({ restJob: { new_issue_path: 'new/issue/path' } });
expect(findNewIssueButton().attributes('href')).toBe('new/issue/path');
});
it('should render terminal link', async () => {
await createComponentWithApollo({ restJob: { terminal_path: 'terminal/path' } });
expect(findTerminalLink().attributes('href')).toBe('terminal/path');
});
});
});
|