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
|
import { GlFormCheckbox, GlLink } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper';
import UpdateKeepLatestArtifactProjectSetting from '~/artifacts_settings/graphql/mutations/update_keep_latest_artifact_project_setting.mutation.graphql';
import GetKeepLatestArtifactApplicationSetting from '~/artifacts_settings/graphql/queries/get_keep_latest_artifact_application_setting.query.graphql';
import GetKeepLatestArtifactProjectSetting from '~/artifacts_settings/graphql/queries/get_keep_latest_artifact_project_setting.query.graphql';
import KeepLatestArtifactCheckbox from '~/artifacts_settings/keep_latest_artifact_checkbox.vue';
Vue.use(VueApollo);
const keepLatestArtifactProjectMock = {
data: {
project: {
id: '1',
ciCdSettings: { keepLatestArtifact: true },
},
},
};
const keepLatestArtifactApplicationMock = {
data: {
ciApplicationSettings: {
keepLatestArtifact: true,
},
},
};
const keepLatestArtifactMockResponse = {
data: { ciCdSettingsUpdate: { errors: [], __typename: 'CiCdSettingsUpdatePayload' } },
};
describe('Keep latest artifact checkbox', () => {
let wrapper;
let apolloProvider;
let requestHandlers;
const fullPath = 'gitlab-org/gitlab';
const helpPagePath = '/help/ci/pipelines/job_artifacts';
const findCheckbox = () => wrapper.findComponent(GlFormCheckbox);
const findHelpLink = () => wrapper.findComponent(GlLink);
const createComponent = (handlers) => {
requestHandlers = {
keepLatestArtifactProjectQueryHandler: jest
.fn()
.mockResolvedValue(keepLatestArtifactProjectMock),
keepLatestArtifactApplicationQueryHandler: jest
.fn()
.mockResolvedValue(keepLatestArtifactApplicationMock),
keepLatestArtifactMutationHandler: jest
.fn()
.mockResolvedValue(keepLatestArtifactMockResponse),
...handlers,
};
apolloProvider = createMockApollo([
[GetKeepLatestArtifactProjectSetting, requestHandlers.keepLatestArtifactProjectQueryHandler],
[
GetKeepLatestArtifactApplicationSetting,
requestHandlers.keepLatestArtifactApplicationQueryHandler,
],
[UpdateKeepLatestArtifactProjectSetting, requestHandlers.keepLatestArtifactMutationHandler],
]);
wrapper = shallowMount(KeepLatestArtifactCheckbox, {
provide: {
fullPath,
helpPagePath,
},
stubs: {
GlFormCheckbox,
},
apolloProvider,
});
};
afterEach(() => {
apolloProvider = null;
});
describe('default', () => {
beforeEach(() => {
createComponent();
});
it('displays the checkbox and the help link', () => {
expect(findCheckbox().exists()).toBe(true);
expect(findHelpLink().exists()).toBe(true);
});
it('calls mutation on artifact setting change with correct payload', () => {
findCheckbox().vm.$emit('change', false);
expect(requestHandlers.keepLatestArtifactMutationHandler).toHaveBeenCalledWith({
fullPath,
keepLatestArtifact: false,
});
});
});
describe('when application keep latest artifact setting is enabled', () => {
beforeEach(() => {
createComponent();
});
it('sets correct setting value in checkbox with query result', async () => {
await nextTick();
expect(wrapper.element).toMatchSnapshot();
});
it('checkbox is enabled when application setting is enabled', async () => {
await nextTick();
expect(findCheckbox().attributes('disabled')).toBeUndefined();
});
});
});
|