Commit b7fc4b31 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'browse-locked-artifact' into 'master'

Update artifacts section to show when an artifact is locked

See merge request gitlab-org/gitlab!32992
parents 3b95696a 7ca92969
...@@ -17,11 +17,14 @@ export default { ...@@ -17,11 +17,14 @@ export default {
}, },
computed: { computed: {
isExpired() { isExpired() {
return this.artifact.expired; return this.artifact?.expired && !this.isLocked;
},
isLocked() {
return this.artifact?.locked;
}, },
// Only when the key is `false` we can render this block // Only when the key is `false` we can render this block
willExpire() { willExpire() {
return this.artifact.expired === false; return this.artifact?.expired === false && !this.isLocked;
}, },
}, },
}; };
...@@ -29,42 +32,45 @@ export default { ...@@ -29,42 +32,45 @@ export default {
<template> <template>
<div class="block"> <div class="block">
<div class="title font-weight-bold">{{ s__('Job|Job artifacts') }}</div> <div class="title font-weight-bold">{{ s__('Job|Job artifacts') }}</div>
<p <p
v-if="isExpired || willExpire" v-if="isExpired || willExpire"
:class="{
'js-artifacts-removed': isExpired,
'js-artifacts-will-be-removed': willExpire,
}"
class="build-detail-row" class="build-detail-row"
data-testid="artifacts-remove-timeline"
> >
<span v-if="isExpired">{{ s__('Job|The artifacts were removed') }}</span> <span v-if="isExpired">{{ s__('Job|The artifacts were removed') }}</span>
<span v-if="willExpire">{{ s__('Job|The artifacts will be removed') }}</span> <span v-if="willExpire">{{ s__('Job|The artifacts will be removed') }}</span>
<timeago-tooltip v-if="artifact.expire_at" :time="artifact.expire_at" /> <timeago-tooltip v-if="artifact.expire_at" :time="artifact.expire_at" />
</p> </p>
<p v-else-if="isLocked" class="build-detail-row">
<span data-testid="job-locked-message">{{
s__(
'Job|These artifacts are the latest. They will not be deleted (even if expired) until newer artifacts are available.',
)
}}</span>
</p>
<div class="btn-group d-flex prepend-top-10" role="group"> <div class="btn-group d-flex prepend-top-10" role="group">
<gl-link <gl-link
v-if="artifact.keep_path" v-if="artifact.keep_path"
:href="artifact.keep_path" :href="artifact.keep_path"
class="js-keep-artifacts btn btn-sm btn-default" class="btn btn-sm btn-default"
data-method="post" data-method="post"
data-testid="keep-artifacts"
>{{ s__('Job|Keep') }}</gl-link >{{ s__('Job|Keep') }}</gl-link
> >
<gl-link <gl-link
v-if="artifact.download_path" v-if="artifact.download_path"
:href="artifact.download_path" :href="artifact.download_path"
class="js-download-artifacts btn btn-sm btn-default" class="btn btn-sm btn-default"
download download
rel="nofollow" rel="nofollow"
data-testid="download-artifacts"
>{{ s__('Job|Download') }}</gl-link >{{ s__('Job|Download') }}</gl-link
> >
<gl-link <gl-link
v-if="artifact.browse_path" v-if="artifact.browse_path"
:href="artifact.browse_path" :href="artifact.browse_path"
class="js-browse-artifacts btn btn-sm btn-default" class="btn btn-sm btn-default"
data-testid="browse-artifacts"
>{{ s__('Job|Browse') }}</gl-link >{{ s__('Job|Browse') }}</gl-link
> >
</div> </div>
......
---
title: Update artifacts section to show when an artifact is locked
merge_request: 32992
author:
type: changed
...@@ -8,6 +8,8 @@ msgid "" ...@@ -8,6 +8,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: gitlab 1.0.0\n" "Project-Id-Version: gitlab 1.0.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-06-01 14:24-0400\n"
"PO-Revision-Date: 2020-06-01 14:24-0400\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n" "Language: \n"
...@@ -12469,6 +12471,9 @@ msgstr "" ...@@ -12469,6 +12471,9 @@ msgstr ""
msgid "Job|The artifacts will be removed" msgid "Job|The artifacts will be removed"
msgstr "" msgstr ""
msgid "Job|These artifacts are the latest. They will not be deleted (even if expired) until newer artifacts are available."
msgstr ""
msgid "Job|This job failed because the necessary resources were not successfully created." msgid "Job|This job failed because the necessary resources were not successfully created."
msgstr "" msgstr ""
......
import Vue from 'vue'; import { mount } from '@vue/test-utils';
import { getTimeago } from '~/lib/utils/datetime_utility'; import { getTimeago } from '~/lib/utils/datetime_utility';
import component from '~/jobs/components/artifacts_block.vue'; import ArtifactsBlock from '~/jobs/components/artifacts_block.vue';
import mountComponent from '../../helpers/vue_mount_component_helper';
import { trimText } from '../../helpers/text_helper'; import { trimText } from '../../helpers/text_helper';
describe('Artifacts block', () => { describe('Artifacts block', () => {
const Component = Vue.extend(component); let wrapper;
let vm;
const createWrapper = propsData =>
mount(ArtifactsBlock, {
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 expireAt = '2018-08-14T09:38:49.157Z';
const timeago = getTimeago(); const timeago = getTimeago();
const formattedDate = timeago.format(expireAt); 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 = { const expiredArtifact = {
expire_at: expireAt, expire_at: expireAt,
expired: true, expired: true,
locked: false,
}; };
const nonExpiredArtifact = { const nonExpiredArtifact = {
...@@ -23,97 +35,127 @@ describe('Artifacts block', () => { ...@@ -23,97 +35,127 @@ describe('Artifacts block', () => {
keep_path: '/gitlab-org/gitlab-foss/-/jobs/98314558/artifacts/keep', keep_path: '/gitlab-org/gitlab-foss/-/jobs/98314558/artifacts/keep',
expire_at: expireAt, expire_at: expireAt,
expired: false, 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(() => { afterEach(() => {
vm.$destroy(); wrapper.destroy();
wrapper = null;
}); });
describe('with expired artifacts', () => { describe('with expired artifacts that are not locked', () => {
it('renders expired artifact date and info', () => { beforeEach(() => {
vm = mountComponent(Component, { wrapper = createWrapper({
artifact: expiredArtifact, artifact: expiredArtifact,
}); });
});
expect(vm.$el.querySelector('.js-artifacts-removed')).not.toBeNull(); it('renders expired artifact date and info', () => {
expect(vm.$el.querySelector('.js-artifacts-will-be-removed')).toBeNull(); expect(trimText(findArtifactRemoveElt().text())).toBe(
expect(trimText(vm.$el.querySelector('.js-artifacts-removed').textContent)).toEqual(
`The artifacts were removed ${formattedDate}`, `The artifacts were removed ${formattedDate}`,
); );
}); });
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', () => { describe('with artifacts that will expire', () => {
it('renders will expire artifact date and info', () => { beforeEach(() => {
vm = mountComponent(Component, { wrapper = createWrapper({
artifact: nonExpiredArtifact, artifact: nonExpiredArtifact,
}); });
});
expect(vm.$el.querySelector('.js-artifacts-removed')).toBeNull(); it('renders will expire artifact date and info', () => {
expect(vm.$el.querySelector('.js-artifacts-will-be-removed')).not.toBeNull(); expect(trimText(findArtifactRemoveElt().text())).toBe(
expect(trimText(vm.$el.querySelector('.js-artifacts-will-be-removed').textContent)).toEqual(
`The artifacts will be removed ${formattedDate}`, `The artifacts will be removed ${formattedDate}`,
); );
}); });
});
describe('with keep path', () => {
it('renders the keep button', () => { it('renders the keep button', () => {
vm = mountComponent(Component, { expect(findKeepBtn().exists()).toBe(true);
artifact: nonExpiredArtifact,
});
expect(vm.$el.querySelector('.js-keep-artifacts')).not.toBeNull();
}); });
});
describe('without keep path', () => { it('renders the download button', () => {
it('does not render the keep button', () => { expect(findDownloadBtn().exists()).toBe(true);
vm = mountComponent(Component, { });
artifact: expiredArtifact,
});
expect(vm.$el.querySelector('.js-keep-artifacts')).toBeNull(); it('renders the browse button', () => {
expect(findBrowseBtn().exists()).toBe(true);
}); });
}); });
describe('with download path', () => { describe('with expired locked artifacts', () => {
it('renders the download button', () => { beforeEach(() => {
vm = mountComponent(Component, { wrapper = createWrapper({
artifact: nonExpiredArtifact, artifact: lockedExpiredArtifact,
}); });
});
expect(vm.$el.querySelector('.js-download-artifacts')).not.toBeNull(); it('renders the information that the artefacts are locked', () => {
expect(findArtifactRemoveElt().exists()).toBe(false);
expect(trimText(findJobLockedElt().text())).toBe(lockedText);
}); });
});
describe('without download path', () => {
it('does not render the keep button', () => { it('does not render the keep button', () => {
vm = mountComponent(Component, { expect(findKeepBtn().exists()).toBe(false);
artifact: expiredArtifact, });
});
expect(vm.$el.querySelector('.js-download-artifacts')).toBeNull(); it('renders the download button', () => {
expect(findDownloadBtn().exists()).toBe(true);
});
it('renders the browse button', () => {
expect(findBrowseBtn().exists()).toBe(true);
}); });
}); });
describe('with browse path', () => { describe('with non expired locked artifacts', () => {
it('does not render the browse button', () => { beforeEach(() => {
vm = mountComponent(Component, { wrapper = createWrapper({
artifact: nonExpiredArtifact, artifact: lockedNonExpiredArtifact,
}); });
});
expect(vm.$el.querySelector('.js-browse-artifacts')).not.toBeNull(); it('renders the information that the artefacts are locked', () => {
expect(findArtifactRemoveElt().exists()).toBe(false);
expect(trimText(findJobLockedElt().text())).toBe(lockedText);
}); });
});
describe('without browse path', () => { it('does not render the keep button', () => {
it('does not render the browse button', () => { expect(findKeepBtn().exists()).toBe(false);
vm = mountComponent(Component, { });
artifact: expiredArtifact,
}); it('renders the download button', () => {
expect(findDownloadBtn().exists()).toBe(true);
});
expect(vm.$el.querySelector('.js-browse-artifacts')).toBeNull(); it('renders the browse button', () => {
expect(findBrowseBtn().exists()).toBe(true);
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment