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

77 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-05-24 23:13:21 +05:30
import { shallowMount } from '@vue/test-utils';
2020-11-24 15:15:51 +05:30
import { GlIcon } from '@gitlab/ui';
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: {
...props,
},
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');
2020-05-24 23:13:21 +05:30
describe('with duration', () => {
beforeEach(() => {
createComponent({ duration: 10, finishedTime: '' });
});
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(() => {
createComponent({ duration: 0, finishedTime: '' });
});
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(() => {
createComponent({ duration: 0, finishedTime: '2017-04-26T12:40:23.277Z' });
});
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(() => {
createComponent({ duration: 0, finishedTime: '' });
});
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
});
});
});