debian-mirror-gitlab/spec/frontend/jobs/mixins/delayed_job_mixin_spec.js

125 lines
2.9 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2021-11-18 22:05:49 +05:30
import delayedJobFixture from 'test_fixtures/jobs/delayed.json';
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;
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 () => {
2022-04-04 11:22:00 +05:30
await 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
});
2022-04-04 11:22:00 +05:30
await nextTick();
2021-03-11 19:13:27 +05:30
});
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
2022-04-04 11:22:00 +05:30
await nextTick();
2021-03-11 19:13:27 +05:30
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
2022-04-04 11:22:00 +05:30
await nextTick();
2021-03-11 19:13:27 +05:30
});
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
2022-04-04 11:22:00 +05:30
await nextTick();
2021-03-11 19:13:27 +05:30
expect(wrapper.text()).toBe('00:00:41');
2018-12-13 13:39:08 +05:30
});
});
});
});