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

artifact_row_spec.js « components « artifacts « ci « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 96ddedc3a9d598d91925f0d9edec46ee72934589 (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
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
122
123
124
125
126
127
import { GlBadge, GlFriendlyWrap, GlFormCheckbox } from '@gitlab/ui';
import mockGetJobArtifactsResponse from 'test_fixtures/graphql/ci/artifacts/graphql/queries/get_job_artifacts.query.graphql.json';
import { numberToHumanSize } from '~/lib/utils/number_utils';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises';
import ArtifactRow from '~/ci/artifacts/components/artifact_row.vue';
import { BULK_DELETE_FEATURE_FLAG, I18N_BULK_DELETE_MAX_SELECTED } from '~/ci/artifacts/constants';

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

  const artifact = mockGetJobArtifactsResponse.data.project.jobs.nodes[0].artifacts.nodes[0];

  const findName = () => wrapper.findByTestId('job-artifact-row-name');
  const findBadge = () => wrapper.findComponent(GlBadge);
  const findSize = () => wrapper.findByTestId('job-artifact-row-size');
  const findDownloadButton = () => wrapper.findByTestId('job-artifact-row-download-button');
  const findDeleteButton = () => wrapper.findByTestId('job-artifact-row-delete-button');
  const findCheckbox = () => wrapper.findComponent(GlFormCheckbox);

  const createComponent = ({ canDestroyArtifacts = true, glFeatures = {}, props = {} } = {}) => {
    wrapper = shallowMountExtended(ArtifactRow, {
      propsData: {
        artifact,
        isSelected: false,
        isLoading: false,
        isLastRow: false,
        isSelectedArtifactsLimitReached: false,
        ...props,
      },
      provide: { canDestroyArtifacts, glFeatures },
      stubs: { GlBadge, GlFriendlyWrap },
    });
  };

  describe('artifact details', () => {
    beforeEach(async () => {
      createComponent();

      await waitForPromises();
    });

    it('displays the artifact name and type', () => {
      expect(findName().text()).toContain(artifact.name);
      expect(findBadge().text()).toBe(artifact.fileType.toLowerCase());
    });

    it('displays the artifact size', () => {
      expect(findSize().text()).toBe(numberToHumanSize(artifact.size));
    });

    it('displays the download button as a link to the download path', () => {
      expect(findDownloadButton().attributes('href')).toBe(artifact.downloadPath);
    });
  });

  describe('delete button', () => {
    it('does not show when user does not have permission', () => {
      createComponent({ canDestroyArtifacts: false });

      expect(findDeleteButton().exists()).toBe(false);
    });

    it('shows when user has permission', () => {
      createComponent();

      expect(findDeleteButton().exists()).toBe(true);
    });

    it('emits the delete event when clicked', async () => {
      createComponent();

      expect(wrapper.emitted('delete')).toBeUndefined();

      findDeleteButton().vm.$emit('click');
      await waitForPromises();

      expect(wrapper.emitted('delete')).toBeDefined();
    });
  });

  describe('bulk delete checkbox', () => {
    describe('with permission and feature flag enabled', () => {
      it('emits selectArtifact when toggled', () => {
        createComponent({ glFeatures: { [BULK_DELETE_FEATURE_FLAG]: true } });

        findCheckbox().vm.$emit('input', true);

        expect(wrapper.emitted('selectArtifact')).toStrictEqual([[artifact, true]]);
      });

      describe('when the selected artifacts limit is reached', () => {
        it('remains enabled if the artifact was selected', () => {
          createComponent({
            glFeatures: { [BULK_DELETE_FEATURE_FLAG]: true },
            props: { isSelected: true, isSelectedArtifactsLimitReached: true },
          });

          expect(findCheckbox().attributes('disabled')).toBeUndefined();
          expect(findCheckbox().attributes('title')).toBe('');
        });

        it('is disabled if the artifact was not selected', () => {
          createComponent({
            glFeatures: { [BULK_DELETE_FEATURE_FLAG]: true },
            props: { isSelected: false, isSelectedArtifactsLimitReached: true },
          });

          expect(findCheckbox().attributes('disabled')).toBeDefined();
          expect(findCheckbox().attributes('title')).toBe(I18N_BULK_DELETE_MAX_SELECTED);
        });
      });
    });

    it('is not shown without permission', () => {
      createComponent({ canDestroyArtifacts: false });

      expect(findCheckbox().exists()).toBe(false);
    });

    it('is not shown with feature flag disabled', () => {
      createComponent();

      expect(findCheckbox().exists()).toBe(false);
    });
  });
});