Welcome to mirror list, hosted at ThFree Co, Russian Federation.

keep_latest_artifact_checkbox_spec.js « components « artifacts_settings « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d7f07526b586139181c524c897ac91042a4efc74 (plain)
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
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';

const localVue = createLocalVue();
localVue.use(VueApollo);

const keepLatestArtifactMock = {
  data: {
    project: {
      ciCdSettings: { 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.find(GlFormCheckbox);
  const findHelpLink = () => wrapper.find(GlLink);

  const createComponent = (handlers) => {
    requestHandlers = {
      keepLatestArtifactQueryHandler: jest.fn().mockResolvedValue(keepLatestArtifactMock),
      keepLatestArtifactMutationHandler: jest
        .fn()
        .mockResolvedValue(keepLatestArtifactMockResponse),
      ...handlers,
    };

    apolloProvider = createMockApollo([
      [GetKeepLatestArtifactProjectSetting, requestHandlers.keepLatestArtifactQueryHandler],
      [UpdateKeepLatestArtifactProjectSetting, requestHandlers.keepLatestArtifactMutationHandler],
    ]);

    wrapper = shallowMount(KeepLatestArtifactCheckbox, {
      provide: {
        fullPath,
        helpPagePath,
      },
      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);
  });

  it('sets correct setting value in checkbox with query result', async () => {
    await wrapper.vm.$nextTick();

    expect(wrapper.element).toMatchSnapshot();
  });

  it('calls mutation on artifact setting change with correct payload', () => {
    findCheckbox().vm.$emit('change', false);

    expect(requestHandlers.keepLatestArtifactMutationHandler).toHaveBeenCalledWith({
      fullPath,
      keepLatestArtifact: false,
    });
  });
});