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

99 lines
2.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';
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;
const createComponent = (props = {}) => {
wrapper = shallowMount(TimeAgo, {
propsData: {
2021-04-17 20:07:23 +05:30
pipeline: {
details: {
...props,
},
},
2020-05-24 23:13:21 +05:30
},
data() {
return {
iconTimerSvg: `<svg></svg>`,
};
},
});
};
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-17 20:07:23 +05:30
const findInProgress = () => wrapper.find('[data-testid="pipeline-in-progress"]');
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-17 20:07:23 +05:30
createComponent({ duration: 0, finished_at: '' });
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-17 20:07:23 +05:30
createComponent({ duration: 0, finished_at: '' });
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 }) => {
createComponent({ duration: durationTime, finished_at: finishedAtTime });
expect(findInProgress().exists()).toBe(shouldShow);
},
);
});
2020-05-24 23:13:21 +05:30
});