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

artifacts_block_spec.js « components « jobs « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a709a59cadda7bc7b6fa6e37008832d87ee2a84e (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { mount } from '@vue/test-utils';
import { getTimeago } from '~/lib/utils/datetime_utility';
import ArtifactsBlock from '~/jobs/components/artifacts_block.vue';
import { trimText } from '../../helpers/text_helper';

describe('Artifacts block', () => {
  let wrapper;

  const createWrapper = propsData =>
    mount(ArtifactsBlock, {
      propsData: {
        helpUrl: 'help-url',
        ...propsData,
      },
    });

  const findArtifactRemoveElt = () => wrapper.find('[data-testid="artifacts-remove-timeline"]');
  const findJobLockedElt = () => wrapper.find('[data-testid="job-locked-message"]');
  const findKeepBtn = () => wrapper.find('[data-testid="keep-artifacts"]');
  const findDownloadBtn = () => wrapper.find('[data-testid="download-artifacts"]');
  const findBrowseBtn = () => wrapper.find('[data-testid="browse-artifacts"]');

  const expireAt = '2018-08-14T09:38:49.157Z';
  const timeago = getTimeago();
  const formattedDate = timeago.format(expireAt);
  const lockedText =
    'These artifacts are the latest. They will not be deleted (even if expired) until newer artifacts are available.';

  const expiredArtifact = {
    expire_at: expireAt,
    expired: true,
    locked: false,
  };

  const nonExpiredArtifact = {
    download_path: '/gitlab-org/gitlab-foss/-/jobs/98314558/artifacts/download',
    browse_path: '/gitlab-org/gitlab-foss/-/jobs/98314558/artifacts/browse',
    keep_path: '/gitlab-org/gitlab-foss/-/jobs/98314558/artifacts/keep',
    expire_at: expireAt,
    expired: false,
    locked: false,
  };

  const lockedExpiredArtifact = {
    ...expiredArtifact,
    download_path: '/gitlab-org/gitlab-foss/-/jobs/98314558/artifacts/download',
    browse_path: '/gitlab-org/gitlab-foss/-/jobs/98314558/artifacts/browse',
    expired: true,
    locked: true,
  };

  const lockedNonExpiredArtifact = {
    ...nonExpiredArtifact,
    keep_path: undefined,
    locked: true,
  };

  afterEach(() => {
    wrapper.destroy();
    wrapper = null;
  });

  describe('with expired artifacts that are not locked', () => {
    beforeEach(() => {
      wrapper = createWrapper({
        artifact: expiredArtifact,
      });
    });

    it('renders expired artifact date and info', () => {
      expect(trimText(findArtifactRemoveElt().text())).toBe(
        `The artifacts were removed ${formattedDate}`,
      );

      expect(
        findArtifactRemoveElt()
          .find('[data-testid="artifact-expired-help-link"]')
          .attributes('href'),
      ).toBe('help-url');
    });

    it('does not show the keep button', () => {
      expect(findKeepBtn().exists()).toBe(false);
    });

    it('does not show the download button', () => {
      expect(findDownloadBtn().exists()).toBe(false);
    });

    it('does not show the browse button', () => {
      expect(findBrowseBtn().exists()).toBe(false);
    });
  });

  describe('with artifacts that will expire', () => {
    beforeEach(() => {
      wrapper = createWrapper({
        artifact: nonExpiredArtifact,
      });
    });

    it('renders will expire artifact date and info', () => {
      expect(trimText(findArtifactRemoveElt().text())).toBe(
        `The artifacts will be removed ${formattedDate}`,
      );

      expect(
        findArtifactRemoveElt()
          .find('[data-testid="artifact-expired-help-link"]')
          .attributes('href'),
      ).toBe('help-url');
    });

    it('renders the keep button', () => {
      expect(findKeepBtn().exists()).toBe(true);
    });

    it('renders the download button', () => {
      expect(findDownloadBtn().exists()).toBe(true);
    });

    it('renders the browse button', () => {
      expect(findBrowseBtn().exists()).toBe(true);
    });
  });

  describe('with expired locked artifacts', () => {
    beforeEach(() => {
      wrapper = createWrapper({
        artifact: lockedExpiredArtifact,
      });
    });

    it('renders the information that the artefacts are locked', () => {
      expect(findArtifactRemoveElt().exists()).toBe(false);
      expect(trimText(findJobLockedElt().text())).toBe(lockedText);
    });

    it('does not render the keep button', () => {
      expect(findKeepBtn().exists()).toBe(false);
    });

    it('renders the download button', () => {
      expect(findDownloadBtn().exists()).toBe(true);
    });

    it('renders the browse button', () => {
      expect(findBrowseBtn().exists()).toBe(true);
    });
  });

  describe('with non expired locked artifacts', () => {
    beforeEach(() => {
      wrapper = createWrapper({
        artifact: lockedNonExpiredArtifact,
      });
    });

    it('renders the information that the artefacts are locked', () => {
      expect(findArtifactRemoveElt().exists()).toBe(false);
      expect(trimText(findJobLockedElt().text())).toBe(lockedText);
    });

    it('does not render the keep button', () => {
      expect(findKeepBtn().exists()).toBe(false);
    });

    it('renders the download button', () => {
      expect(findDownloadBtn().exists()).toBe(true);
    });

    it('renders the browse button', () => {
      expect(findBrowseBtn().exists()).toBe(true);
    });
  });
});