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