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

80 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-12-13 13:39:08 +05:30
import Vue from 'vue';
2020-05-24 23:13:21 +05:30
import mountComponent from 'helpers/vue_mount_component_helper';
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', () => {
const delayedJobFixture = getJSONFixture('jobs/delayed.json');
const dummyComponent = Vue.extend({
mixins: [delayedJobMixin],
props: {
job: {
type: Object,
required: true,
},
},
2020-05-24 23:13:21 +05:30
render(createElement) {
return createElement('div', this.remainingTime);
},
2018-12-13 13:39:08 +05:30
});
let vm;
afterEach(() => {
vm.$destroy();
2020-05-24 23:13:21 +05:30
jest.clearAllTimers();
2018-12-13 13:39:08 +05:30
});
describe('if job is empty object', () => {
beforeEach(() => {
vm = mountComponent(dummyComponent, {
job: {},
});
});
it('sets remaining time to 00:00:00', () => {
expect(vm.$el.innerText).toBe('00:00:00');
});
describe('after mounting', () => {
2020-05-24 23:13:21 +05:30
beforeEach(() => vm.$nextTick());
2018-12-13 13:39:08 +05:30
2020-05-24 23:13:21 +05:30
it('does not update remaining time', () => {
2018-12-13 13:39:08 +05:30
expect(vm.$el.innerText).toBe('00:00:00');
});
});
});
describe('if job is delayed job', () => {
let remainingTimeInMilliseconds = 42000;
beforeEach(() => {
2020-05-24 23:13:21 +05:30
jest
.spyOn(Date, 'now')
.mockImplementation(
() => new Date(delayedJobFixture.scheduled_at).getTime() - remainingTimeInMilliseconds,
);
2018-12-13 13:39:08 +05:30
vm = mountComponent(dummyComponent, {
job: delayedJobFixture,
});
});
describe('after mounting', () => {
2020-05-24 23:13:21 +05:30
beforeEach(() => vm.$nextTick());
2018-12-13 13:39:08 +05:30
it('sets remaining time', () => {
expect(vm.$el.innerText).toBe('00:00:42');
});
2020-05-24 23:13:21 +05:30
it('updates remaining time', () => {
2018-12-13 13:39:08 +05:30
remainingTimeInMilliseconds = 41000;
2020-05-24 23:13:21 +05:30
jest.advanceTimersByTime(1000);
2018-12-13 13:39:08 +05:30
2020-05-24 23:13:21 +05:30
return vm.$nextTick().then(() => {
expect(vm.$el.innerText).toBe('00:00:41');
});
2018-12-13 13:39:08 +05:30
});
});
});
});