summaryrefslogtreecommitdiff
path: root/spec/frontend/artifacts_settings
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/artifacts_settings')
-rw-r--r--spec/frontend/artifacts_settings/components/__snapshots__/keep_latest_artifact_checkbox_spec.js.snap55
-rw-r--r--spec/frontend/artifacts_settings/components/keep_latest_artifact_checkbox_spec.js96
2 files changed, 120 insertions, 31 deletions
diff --git a/spec/frontend/artifacts_settings/components/__snapshots__/keep_latest_artifact_checkbox_spec.js.snap b/spec/frontend/artifacts_settings/components/__snapshots__/keep_latest_artifact_checkbox_spec.js.snap
index 9d05e6d99f6..bfe7e40fb32 100644
--- a/spec/frontend/artifacts_settings/components/__snapshots__/keep_latest_artifact_checkbox_spec.js.snap
+++ b/spec/frontend/artifacts_settings/components/__snapshots__/keep_latest_artifact_checkbox_spec.js.snap
@@ -1,29 +1,64 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`Keep latest artifact checkbox sets correct setting value in checkbox with query result 1`] = `
+exports[`Keep latest artifact checkbox when application keep latest artifact setting is disabled checkbox is disabled when application setting is disabled 1`] = `
<div>
<!---->
- <gl-form-checkbox-stub
+ <b-form-checkbox-stub
checked="true"
+ class="gl-form-checkbox"
+ disabled="true"
+ plain="true"
+ value="true"
>
- <b
+ <strong
class="gl-mr-3"
>
Keep artifacts from most recent successful jobs
- </b>
+ </strong>
<gl-link-stub
href="/help/ci/pipelines/job_artifacts"
>
More information
</gl-link-stub>
- </gl-form-checkbox-stub>
+
+ <p
+ class="help-text"
+ >
+ This feature is disabled at the instance level.
+ </p>
+ </b-form-checkbox-stub>
+</div>
+`;
+
+exports[`Keep latest artifact checkbox when application keep latest artifact setting is enabled sets correct setting value in checkbox with query result 1`] = `
+<div>
+ <!---->
- <p>
-
- The latest artifacts created by jobs in the most recent successful pipeline will be stored.
-
- </p>
+ <b-form-checkbox-stub
+ checked="true"
+ class="gl-form-checkbox"
+ plain="true"
+ value="true"
+ >
+ <strong
+ class="gl-mr-3"
+ >
+ Keep artifacts from most recent successful jobs
+ </strong>
+
+ <gl-link-stub
+ href="/help/ci/pipelines/job_artifacts"
+ >
+ More information
+ </gl-link-stub>
+
+ <p
+ class="help-text"
+ >
+ The latest artifacts created by jobs in the most recent successful pipeline will be stored.
+ </p>
+ </b-form-checkbox-stub>
</div>
`;
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');
});
});
});