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';
|
2021-04-06 02:09:00 -04:00
|
|
|
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
|
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;
|
|
|
|
|
2021-04-06 02:09:00 -04:00
|
|
|
const defaultProps = { duration: 0, finished_at: '' };
|
|
|
|
|
|
|
|
const createComponent = (props = defaultProps, stuck = false) => {
|
|
|
|
wrapper = extendedWrapper(
|
|
|
|
shallowMount(TimeAgo, {
|
|
|
|
propsData: {
|
|
|
|
pipeline: {
|
|
|
|
details: {
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
flags: {
|
|
|
|
stuck,
|
|
|
|
},
|
2021-03-01 13:11:21 -05:00
|
|
|
},
|
|
|
|
},
|
2021-04-06 02:09:00 -04:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
iconTimerSvg: `<svg></svg>`,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
2020-04-30 17:09:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
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-04-06 02:09:00 -04:00
|
|
|
const findInProgress = () => wrapper.findByTestId('pipeline-in-progress');
|
|
|
|
const findSkipped = () => wrapper.findByTestId('pipeline-skipped');
|
|
|
|
const findHourGlassIcon = () => wrapper.findByTestId('hourglass-icon');
|
|
|
|
const findWarningIcon = () => wrapper.findByTestId('warning-icon');
|
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-04-06 02:09:00 -04:00
|
|
|
createComponent();
|
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-04-06 02:09:00 -04:00
|
|
|
createComponent();
|
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);
|
|
|
|
},
|
|
|
|
);
|
2021-04-06 02:09:00 -04:00
|
|
|
|
|
|
|
it('should show warning icon beside in progress if pipeline is stuck', () => {
|
|
|
|
const stuck = true;
|
|
|
|
|
|
|
|
createComponent(defaultProps, stuck);
|
|
|
|
|
|
|
|
expect(findWarningIcon().exists()).toBe(true);
|
|
|
|
expect(findHourGlassIcon().exists()).toBe(false);
|
|
|
|
});
|
2021-03-17 11:09:03 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
});
|