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

job_checkbox_spec.js « components « artifacts « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 95cc548b8c8a3a665e2f11b4af565c6955decf6a (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
import { GlFormCheckbox } from '@gitlab/ui';
import mockGetJobArtifactsResponse from 'test_fixtures/graphql/artifacts/graphql/queries/get_job_artifacts.query.graphql.json';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import JobCheckbox from '~/artifacts/components/job_checkbox.vue';

describe('JobCheckbox component', () => {
  let wrapper;

  const mockArtifactNodes = mockGetJobArtifactsResponse.data.project.jobs.nodes[0].artifacts.nodes;
  const mockSelectedArtifacts = [mockArtifactNodes[0], mockArtifactNodes[1]];
  const mockUnselectedArtifacts = [mockArtifactNodes[2]];

  const findCheckbox = () => wrapper.findComponent(GlFormCheckbox);

  const createComponent = ({
    hasArtifacts = true,
    selectedArtifacts = mockSelectedArtifacts,
    unselectedArtifacts = mockUnselectedArtifacts,
  } = {}) => {
    wrapper = shallowMountExtended(JobCheckbox, {
      propsData: {
        hasArtifacts,
        selectedArtifacts,
        unselectedArtifacts,
      },
      mocks: { GlFormCheckbox },
    });
  };

  it('is disabled when the job has no artifacts', () => {
    createComponent({ hasArtifacts: false });

    expect(findCheckbox().attributes('disabled')).toBe('true');
  });

  describe('when some artifacts are selected', () => {
    beforeEach(() => {
      createComponent();
    });

    it('is indeterminate', () => {
      expect(findCheckbox().attributes('indeterminate')).toBe('true');
      expect(findCheckbox().attributes('checked')).toBeUndefined();
    });

    it('selects the unselected artifacts on click', () => {
      findCheckbox().vm.$emit('input', true);

      expect(wrapper.emitted('selectArtifact')).toMatchObject([[mockUnselectedArtifacts[0], true]]);
    });
  });

  describe('when all artifacts are selected', () => {
    beforeEach(() => {
      createComponent({ unselectedArtifacts: [] });
    });

    it('is checked', () => {
      expect(findCheckbox().attributes('checked')).toBe('true');
    });

    it('deselects the selected artifacts on click', () => {
      findCheckbox().vm.$emit('input', false);

      expect(wrapper.emitted('selectArtifact')).toMatchObject([
        [mockSelectedArtifacts[0], false],
        [mockSelectedArtifacts[1], false],
      ]);
    });
  });
});