debian-mirror-gitlab/spec/frontend/jobs/components/artifacts_block_spec.js

177 lines
5 KiB
JavaScript
Raw Normal View History

2020-06-23 00:09:42 +05:30
import { mount } from '@vue/test-utils';
2021-03-08 18:12:59 +05:30
import { trimText } from 'helpers/text_helper';
2020-06-23 00:09:42 +05:30
import ArtifactsBlock from '~/jobs/components/artifacts_block.vue';
2021-03-11 19:13:27 +05:30
import { getTimeago } from '~/lib/utils/datetime_utility';
2018-11-20 20:47:30 +05:30
describe('Artifacts block', () => {
2020-06-23 00:09:42 +05:30
let wrapper;
2021-03-08 18:12:59 +05:30
const createWrapper = (propsData) =>
2020-06-23 00:09:42 +05:30
mount(ArtifactsBlock, {
2020-11-24 15:15:51 +05:30
propsData: {
helpUrl: 'help-url',
...propsData,
},
2020-06-23 00:09:42 +05:30
});
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"]');
2018-11-20 20:47:30 +05:30
const expireAt = '2018-08-14T09:38:49.157Z';
const timeago = getTimeago();
2019-02-15 15:39:39 +05:30
const formattedDate = timeago.format(expireAt);
2020-06-23 00:09:42 +05:30
const lockedText =
'These artifacts are the latest. They will not be deleted (even if expired) until newer artifacts are available.';
2018-11-20 20:47:30 +05:30
2018-12-05 23:21:45 +05:30
const expiredArtifact = {
expire_at: expireAt,
expired: true,
2020-06-23 00:09:42 +05:30
locked: false,
2018-12-05 23:21:45 +05:30
};
const nonExpiredArtifact = {
2019-12-04 20:38:33 +05:30
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',
2018-12-05 23:21:45 +05:30
expire_at: expireAt,
expired: false,
2020-06-23 00:09:42 +05:30
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,
2018-12-05 23:21:45 +05:30
};
2018-11-20 20:47:30 +05:30
afterEach(() => {
2020-06-23 00:09:42 +05:30
wrapper.destroy();
wrapper = null;
2018-11-20 20:47:30 +05:30
});
2020-06-23 00:09:42 +05:30
describe('with expired artifacts that are not locked', () => {
beforeEach(() => {
wrapper = createWrapper({
2018-12-05 23:21:45 +05:30
artifact: expiredArtifact,
2018-11-20 20:47:30 +05:30
});
2020-06-23 00:09:42 +05:30
});
2018-11-20 20:47:30 +05:30
2020-06-23 00:09:42 +05:30
it('renders expired artifact date and info', () => {
expect(trimText(findArtifactRemoveElt().text())).toBe(
2019-02-15 15:39:39 +05:30
`The artifacts were removed ${formattedDate}`,
2018-12-05 23:21:45 +05:30
);
2020-11-24 15:15:51 +05:30
expect(
findArtifactRemoveElt()
.find('[data-testid="artifact-expired-help-link"]')
.attributes('href'),
).toBe('help-url');
2018-11-20 20:47:30 +05:30
});
2020-06-23 00:09:42 +05:30
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);
});
2018-11-20 20:47:30 +05:30
});
describe('with artifacts that will expire', () => {
2020-06-23 00:09:42 +05:30
beforeEach(() => {
wrapper = createWrapper({
2018-12-05 23:21:45 +05:30
artifact: nonExpiredArtifact,
2018-11-20 20:47:30 +05:30
});
2020-06-23 00:09:42 +05:30
});
2018-11-20 20:47:30 +05:30
2020-06-23 00:09:42 +05:30
it('renders will expire artifact date and info', () => {
expect(trimText(findArtifactRemoveElt().text())).toBe(
2019-02-15 15:39:39 +05:30
`The artifacts will be removed ${formattedDate}`,
2018-12-05 23:21:45 +05:30
);
2020-11-24 15:15:51 +05:30
expect(
findArtifactRemoveElt()
.find('[data-testid="artifact-expired-help-link"]')
.attributes('href'),
).toBe('help-url');
2018-11-20 20:47:30 +05:30
});
it('renders the keep button', () => {
2020-06-23 00:09:42 +05:30
expect(findKeepBtn().exists()).toBe(true);
2018-11-20 20:47:30 +05:30
});
2020-06-23 00:09:42 +05:30
it('renders the download button', () => {
expect(findDownloadBtn().exists()).toBe(true);
});
2018-11-20 20:47:30 +05:30
2020-06-23 00:09:42 +05:30
it('renders the browse button', () => {
expect(findBrowseBtn().exists()).toBe(true);
2018-11-20 20:47:30 +05:30
});
});
2020-06-23 00:09:42 +05:30
describe('with expired locked artifacts', () => {
beforeEach(() => {
wrapper = createWrapper({
artifact: lockedExpiredArtifact,
2018-11-20 20:47:30 +05:30
});
2020-06-23 00:09:42 +05:30
});
2018-11-20 20:47:30 +05:30
2020-06-23 00:09:42 +05:30
it('renders the information that the artefacts are locked', () => {
expect(findArtifactRemoveElt().exists()).toBe(false);
expect(trimText(findJobLockedElt().text())).toBe(lockedText);
2018-11-20 20:47:30 +05:30
});
it('does not render the keep button', () => {
2020-06-23 00:09:42 +05:30
expect(findKeepBtn().exists()).toBe(false);
});
2018-11-20 20:47:30 +05:30
2020-06-23 00:09:42 +05:30
it('renders the download button', () => {
expect(findDownloadBtn().exists()).toBe(true);
});
it('renders the browse button', () => {
expect(findBrowseBtn().exists()).toBe(true);
2018-11-20 20:47:30 +05:30
});
});
2020-06-23 00:09:42 +05:30
describe('with non expired locked artifacts', () => {
beforeEach(() => {
wrapper = createWrapper({
artifact: lockedNonExpiredArtifact,
2018-11-20 20:47:30 +05:30
});
2020-06-23 00:09:42 +05:30
});
2018-11-20 20:47:30 +05:30
2020-06-23 00:09:42 +05:30
it('renders the information that the artefacts are locked', () => {
expect(findArtifactRemoveElt().exists()).toBe(false);
expect(trimText(findJobLockedElt().text())).toBe(lockedText);
2018-11-20 20:47:30 +05:30
});
2020-06-23 00:09:42 +05:30
it('does not render the keep button', () => {
expect(findKeepBtn().exists()).toBe(false);
});
it('renders the download button', () => {
expect(findDownloadBtn().exists()).toBe(true);
});
2018-11-20 20:47:30 +05:30
2020-06-23 00:09:42 +05:30
it('renders the browse button', () => {
expect(findBrowseBtn().exists()).toBe(true);
2018-11-20 20:47:30 +05:30
});
});
});