diff options
Diffstat (limited to 'spec/frontend/artifacts_settings/components/keep_latest_artifact_checkbox_spec.js')
-rw-r--r-- | spec/frontend/artifacts_settings/components/keep_latest_artifact_checkbox_spec.js | 96 |
1 files changed, 75 insertions, 21 deletions
diff --git a/spec/frontend/artifacts_settings/components/keep_latest_artifact_checkbox_spec.js b/spec/frontend/artifacts_settings/components/keep_latest_artifact_checkbox_spec.js index d7f07526b58..fe2886d6c95 100644 --- a/spec/frontend/artifacts_settings/components/keep_latest_artifact_checkbox_spec.js +++ b/spec/frontend/artifacts_settings/components/keep_latest_artifact_checkbox_spec.js @@ -2,14 +2,15 @@ import { GlFormCheckbox, GlLink } from '@gitlab/ui'; import { shallowMount, createLocalVue } from '@vue/test-utils'; import VueApollo from 'vue-apollo'; import createMockApollo from 'helpers/mock_apollo_helper'; -import KeepLatestArtifactCheckbox from '~/artifacts_settings/keep_latest_artifact_checkbox.vue'; -import GetKeepLatestArtifactProjectSetting from '~/artifacts_settings/graphql/queries/get_keep_latest_artifact_project_setting.query.graphql'; 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'; const localVue = createLocalVue(); localVue.use(VueApollo); -const keepLatestArtifactMock = { +const keepLatestArtifactProjectMock = { data: { project: { ciCdSettings: { keepLatestArtifact: true }, @@ -17,6 +18,14 @@ const keepLatestArtifactMock = { }, }; +const keepLatestArtifactApplicationMock = { + data: { + ciApplicationSettings: { + keepLatestArtifact: true, + }, + }, +}; + const keepLatestArtifactMockResponse = { data: { ciCdSettingsUpdate: { errors: [], __typename: 'CiCdSettingsUpdatePayload' } }, }; @@ -34,7 +43,12 @@ describe('Keep latest artifact checkbox', () => { const createComponent = (handlers) => { requestHandlers = { - keepLatestArtifactQueryHandler: jest.fn().mockResolvedValue(keepLatestArtifactMock), + keepLatestArtifactProjectQueryHandler: jest + .fn() + .mockResolvedValue(keepLatestArtifactProjectMock), + keepLatestArtifactApplicationQueryHandler: jest + .fn() + .mockResolvedValue(keepLatestArtifactApplicationMock), keepLatestArtifactMutationHandler: jest .fn() .mockResolvedValue(keepLatestArtifactMockResponse), @@ -42,7 +56,11 @@ describe('Keep latest artifact checkbox', () => { }; apolloProvider = createMockApollo([ - [GetKeepLatestArtifactProjectSetting, requestHandlers.keepLatestArtifactQueryHandler], + [GetKeepLatestArtifactProjectSetting, requestHandlers.keepLatestArtifactProjectQueryHandler], + [ + GetKeepLatestArtifactApplicationSetting, + requestHandlers.keepLatestArtifactApplicationQueryHandler, + ], [UpdateKeepLatestArtifactProjectSetting, requestHandlers.keepLatestArtifactMutationHandler], ]); @@ -51,38 +69,74 @@ describe('Keep latest artifact checkbox', () => { fullPath, helpPagePath, }, + stubs: { + GlFormCheckbox, + }, localVue, apolloProvider, }); }; - beforeEach(() => { - createComponent(); - }); - afterEach(() => { wrapper.destroy(); wrapper = null; apolloProvider = null; }); - it('displays the checkbox and the help link', () => { - expect(findCheckbox().exists()).toBe(true); - expect(findHelpLink().exists()).toBe(true); - }); + describe('default', () => { + beforeEach(() => { + createComponent(); + }); + + it('displays the checkbox and the help link', () => { + expect(findCheckbox().exists()).toBe(true); + expect(findHelpLink().exists()).toBe(true); + }); - it('sets correct setting value in checkbox with query result', async () => { - await wrapper.vm.$nextTick(); + it('calls mutation on artifact setting change with correct payload', () => { + findCheckbox().vm.$emit('change', false); - expect(wrapper.element).toMatchSnapshot(); + expect(requestHandlers.keepLatestArtifactMutationHandler).toHaveBeenCalledWith({ + fullPath, + keepLatestArtifact: false, + }); + }); }); - it('calls mutation on artifact setting change with correct payload', () => { - findCheckbox().vm.$emit('change', false); + describe('when application keep latest artifact setting is enabled', () => { + beforeEach(() => { + createComponent(); + }); + + it('sets correct setting value in checkbox with query result', async () => { + await wrapper.vm.$nextTick(); + + expect(wrapper.element).toMatchSnapshot(); + }); + + it('checkbox is enabled when application setting is enabled', async () => { + await wrapper.vm.$nextTick(); + + expect(findCheckbox().attributes('disabled')).toBeUndefined(); + }); + }); - expect(requestHandlers.keepLatestArtifactMutationHandler).toHaveBeenCalledWith({ - fullPath, - keepLatestArtifact: false, + describe('when application keep latest artifact setting is disabled', () => { + it('checkbox is disabled when application setting is disabled', async () => { + createComponent({ + keepLatestArtifactApplicationQueryHandler: jest.fn().mockResolvedValue({ + data: { + ciApplicationSettings: { + keepLatestArtifact: false, + }, + }, + }), + }); + + await wrapper.vm.$nextTick(); + + expect(wrapper.element).toMatchSnapshot(); + expect(findCheckbox().attributes('disabled')).toBe('true'); }); }); }); |