2020-09-15 11:10:08 -04:00
|
|
|
import { GlIcon } from '@gitlab/ui';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-06-23 20:08:43 -04:00
|
|
|
import TimeAgo from '~/pipelines/components/pipelines_list/time_ago.vue';
|
2020-04-30 17:09:47 -04:00
|
|
|
|
|
|
|
describe('Timeago component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const createComponent = (props = {}) => {
|
|
|
|
wrapper = shallowMount(TimeAgo, {
|
|
|
|
propsData: {
|
2021-03-01 13:11:21 -05:00
|
|
|
pipeline: {
|
|
|
|
details: {
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
},
|
2020-04-30 17:09:47 -04:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
iconTimerSvg: `<svg></svg>`,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
2020-09-15 11:10:08 -04:00
|
|
|
const duration = () => wrapper.find('.duration');
|
|
|
|
const finishedAt = () => wrapper.find('.finished-at');
|
2021-03-12 13:09:23 -05:00
|
|
|
const findInProgress = () => wrapper.find('[data-testid="pipeline-in-progress"]');
|
2021-03-17 11:09:03 -04:00
|
|
|
const findSkipped = () => wrapper.find('[data-testid="pipeline-skipped"]');
|
2020-09-15 11:10:08 -04:00
|
|
|
|
2020-04-30 17:09:47 -04:00
|
|
|
describe('with duration', () => {
|
|
|
|
beforeEach(() => {
|
2021-03-01 13:11:21 -05:00
|
|
|
createComponent({ duration: 10, finished_at: '' });
|
2020-04-30 17:09:47 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render duration and timer svg', () => {
|
2020-09-15 11:10:08 -04:00
|
|
|
const icon = duration().find(GlIcon);
|
|
|
|
|
|
|
|
expect(duration().exists()).toBe(true);
|
|
|
|
expect(icon.props('name')).toBe('timer');
|
2020-04-30 17:09:47 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('without duration', () => {
|
|
|
|
beforeEach(() => {
|
2021-03-25 17:09:13 -04:00
|
|
|
createComponent({ duration: 0, finished_at: '' });
|
2020-04-30 17:09:47 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render duration and timer svg', () => {
|
2020-09-15 11:10:08 -04:00
|
|
|
expect(duration().exists()).toBe(false);
|
2020-04-30 17:09:47 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with finishedTime', () => {
|
|
|
|
beforeEach(() => {
|
2021-03-01 13:11:21 -05:00
|
|
|
createComponent({ duration: 0, finished_at: '2017-04-26T12:40:23.277Z' });
|
2020-04-30 17:09:47 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render time and calendar icon', () => {
|
2020-09-15 11:10:08 -04:00
|
|
|
const icon = finishedAt().find(GlIcon);
|
|
|
|
const time = finishedAt().find('time');
|
|
|
|
|
|
|
|
expect(finishedAt().exists()).toBe(true);
|
|
|
|
expect(icon.props('name')).toBe('calendar');
|
|
|
|
expect(time.exists()).toBe(true);
|
2020-04-30 17:09:47 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('without finishedTime', () => {
|
|
|
|
beforeEach(() => {
|
2021-03-25 17:09:13 -04:00
|
|
|
createComponent({ duration: 0, finished_at: '' });
|
2020-04-30 17:09:47 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render time and calendar icon', () => {
|
2020-09-15 11:10:08 -04:00
|
|
|
expect(finishedAt().exists()).toBe(false);
|
2020-04-30 17:09:47 -04:00
|
|
|
});
|
|
|
|
});
|
2021-03-12 13:09:23 -05:00
|
|
|
|
|
|
|
describe('in progress', () => {
|
|
|
|
it.each`
|
|
|
|
durationTime | finishedAtTime | shouldShow
|
|
|
|
${10} | ${'2017-04-26T12:40:23.277Z'} | ${false}
|
|
|
|
${10} | ${''} | ${false}
|
|
|
|
${0} | ${'2017-04-26T12:40:23.277Z'} | ${false}
|
|
|
|
${0} | ${''} | ${true}
|
|
|
|
`(
|
|
|
|
'progress state shown: $shouldShow when pipeline duration is $durationTime and finished_at is $finishedAtTime',
|
|
|
|
({ durationTime, finishedAtTime, shouldShow }) => {
|
2021-03-17 11:09:03 -04:00
|
|
|
createComponent({
|
|
|
|
duration: durationTime,
|
|
|
|
finished_at: finishedAtTime,
|
|
|
|
});
|
2021-03-12 13:09:23 -05:00
|
|
|
|
|
|
|
expect(findInProgress().exists()).toBe(shouldShow);
|
2021-03-17 11:09:03 -04:00
|
|
|
expect(findSkipped().exists()).toBe(false);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('skipped', () => {
|
2021-03-25 17:09:13 -04:00
|
|
|
it('should show skipped if pipeline was skipped', () => {
|
|
|
|
createComponent({
|
|
|
|
status: { label: 'skipped' },
|
|
|
|
});
|
2021-03-17 11:09:03 -04:00
|
|
|
|
2021-03-25 17:09:13 -04:00
|
|
|
expect(findSkipped().exists()).toBe(true);
|
|
|
|
expect(findInProgress().exists()).toBe(false);
|
|
|
|
});
|
2021-03-12 13:09:23 -05:00
|
|
|
});
|
2020-04-30 17:09:47 -04:00
|
|
|
});
|