2021-03-11 19:13:27 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-01-01 13:55:28 +05:30
|
|
|
import delayedJobMixin from '~/jobs/mixins/delayed_job_mixin';
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
describe('DelayedJobMixin', () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
let wrapper;
|
2018-12-13 13:39:08 +05:30
|
|
|
const delayedJobFixture = getJSONFixture('jobs/delayed.json');
|
2021-03-11 19:13:27 +05:30
|
|
|
const dummyComponent = {
|
2018-12-13 13:39:08 +05:30
|
|
|
props: {
|
|
|
|
job: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
2021-03-11 19:13:27 +05:30
|
|
|
mixins: [delayedJobMixin],
|
|
|
|
template: '<div>{{remainingTime}}</div>',
|
|
|
|
};
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
afterEach(() => {
|
2021-03-11 19:13:27 +05:30
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('if job is empty object', () => {
|
|
|
|
beforeEach(() => {
|
2021-03-11 19:13:27 +05:30
|
|
|
wrapper = shallowMount(dummyComponent, {
|
|
|
|
propsData: {
|
|
|
|
job: {},
|
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets remaining time to 00:00:00', () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(wrapper.text()).toBe('00:00:00');
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it('does not update remaining time after mounting', async () => {
|
|
|
|
await wrapper.vm.$nextTick();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(wrapper.text()).toBe('00:00:00');
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
describe('in REST component', () => {
|
|
|
|
describe('if job is delayed job', () => {
|
|
|
|
let remainingTimeInMilliseconds = 42000;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
beforeEach(async () => {
|
2021-02-22 17:27:13 +05:30
|
|
|
jest
|
|
|
|
.spyOn(Date, 'now')
|
|
|
|
.mockImplementation(
|
|
|
|
() => new Date(delayedJobFixture.scheduled_at).getTime() - remainingTimeInMilliseconds,
|
|
|
|
);
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
wrapper = shallowMount(dummyComponent, {
|
|
|
|
propsData: {
|
|
|
|
job: delayedJobFixture,
|
|
|
|
},
|
2021-02-22 17:27:13 +05:30
|
|
|
});
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
});
|
2021-02-22 17:27:13 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it('sets remaining time', () => {
|
|
|
|
expect(wrapper.text()).toBe('00:00:42');
|
|
|
|
});
|
2021-02-22 17:27:13 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it('updates remaining time', async () => {
|
|
|
|
remainingTimeInMilliseconds = 41000;
|
|
|
|
jest.advanceTimersByTime(1000);
|
2021-02-22 17:27:13 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
expect(wrapper.text()).toBe('00:00:41');
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
});
|
2021-02-22 17:27:13 +05:30
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
describe('in GraphQL component', () => {
|
|
|
|
const mockGraphQlJob = {
|
|
|
|
name: 'build_b',
|
|
|
|
scheduledAt: new Date(delayedJobFixture.scheduled_at),
|
|
|
|
status: {
|
|
|
|
icon: 'status_success',
|
|
|
|
tooltip: 'passed',
|
|
|
|
hasDetails: true,
|
|
|
|
detailsPath: '/root/abcd-dag/-/jobs/1515',
|
|
|
|
group: 'success',
|
|
|
|
action: null,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('if job is delayed job', () => {
|
|
|
|
let remainingTimeInMilliseconds = 42000;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
beforeEach(async () => {
|
2021-02-22 17:27:13 +05:30
|
|
|
jest
|
|
|
|
.spyOn(Date, 'now')
|
|
|
|
.mockImplementation(
|
|
|
|
() => mockGraphQlJob.scheduledAt.getTime() - remainingTimeInMilliseconds,
|
|
|
|
);
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
wrapper = shallowMount(dummyComponent, {
|
|
|
|
propsData: {
|
|
|
|
job: mockGraphQlJob,
|
|
|
|
},
|
2021-02-22 17:27:13 +05:30
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
});
|
2021-02-22 17:27:13 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it('sets remaining time', () => {
|
|
|
|
expect(wrapper.text()).toBe('00:00:42');
|
|
|
|
});
|
2021-02-22 17:27:13 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it('updates remaining time', async () => {
|
|
|
|
remainingTimeInMilliseconds = 41000;
|
|
|
|
jest.advanceTimersByTime(1000);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
expect(wrapper.text()).toBe('00:00:41');
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|