debian-mirror-gitlab/spec/frontend/pipelines/time_ago_spec.js

134 lines
3.7 KiB
JavaScript
Raw Normal View History

2020-11-24 15:15:51 +05:30
import { GlIcon } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2021-04-29 21:17:54 +05:30
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
2020-07-28 23:09:34 +05:30
import TimeAgo from '~/pipelines/components/pipelines_list/time_ago.vue';
2020-05-24 23:13:21 +05:30
describe('Timeago component', () => {
let wrapper;
2021-04-29 21:17:54 +05:30
const defaultProps = { duration: 0, finished_at: '' };
const createComponent = (props = defaultProps, stuck = false) => {
wrapper = extendedWrapper(
shallowMount(TimeAgo, {
propsData: {
pipeline: {
details: {
...props,
},
flags: {
stuck,
},
2021-04-17 20:07:23 +05:30
},
},
2021-04-29 21:17:54 +05:30
data() {
return {
iconTimerSvg: `<svg></svg>`,
};
},
}),
);
2020-05-24 23:13:21 +05:30
};
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
2020-11-24 15:15:51 +05:30
const duration = () => wrapper.find('.duration');
const finishedAt = () => wrapper.find('.finished-at');
2021-04-29 21:17:54 +05:30
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-11-24 15:15:51 +05:30
2020-05-24 23:13:21 +05:30
describe('with duration', () => {
beforeEach(() => {
2021-04-17 20:07:23 +05:30
createComponent({ duration: 10, finished_at: '' });
2020-05-24 23:13:21 +05:30
});
it('should render duration and timer svg', () => {
2020-11-24 15:15:51 +05:30
const icon = duration().find(GlIcon);
expect(duration().exists()).toBe(true);
expect(icon.props('name')).toBe('timer');
2020-05-24 23:13:21 +05:30
});
});
describe('without duration', () => {
beforeEach(() => {
2021-04-29 21:17:54 +05:30
createComponent();
2020-05-24 23:13:21 +05:30
});
it('should not render duration and timer svg', () => {
2020-11-24 15:15:51 +05:30
expect(duration().exists()).toBe(false);
2020-05-24 23:13:21 +05:30
});
});
describe('with finishedTime', () => {
beforeEach(() => {
2021-04-17 20:07:23 +05:30
createComponent({ duration: 0, finished_at: '2017-04-26T12:40:23.277Z' });
2020-05-24 23:13:21 +05:30
});
it('should render time and calendar icon', () => {
2020-11-24 15:15:51 +05:30
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-05-24 23:13:21 +05:30
});
});
describe('without finishedTime', () => {
beforeEach(() => {
2021-04-29 21:17:54 +05:30
createComponent();
2020-05-24 23:13:21 +05:30
});
it('should not render time and calendar icon', () => {
2020-11-24 15:15:51 +05:30
expect(finishedAt().exists()).toBe(false);
2020-05-24 23:13:21 +05:30
});
});
2021-04-17 20:07:23 +05:30
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-04-29 21:17:54 +05:30
createComponent({
duration: durationTime,
finished_at: finishedAtTime,
});
2021-04-17 20:07:23 +05:30
expect(findInProgress().exists()).toBe(shouldShow);
2021-04-29 21:17:54 +05:30
expect(findSkipped().exists()).toBe(false);
2021-04-17 20:07:23 +05:30
},
);
2021-04-29 21:17:54 +05:30
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);
});
});
describe('skipped', () => {
it('should show skipped if pipeline was skipped', () => {
createComponent({
status: { label: 'skipped' },
});
expect(findSkipped().exists()).toBe(true);
expect(findInProgress().exists()).toBe(false);
});
2021-04-17 20:07:23 +05:30
});
2020-05-24 23:13:21 +05:30
});