debian-mirror-gitlab/spec/frontend/vue_shared/components/gl_countdown_spec.js

84 lines
2 KiB
JavaScript
Raw Normal View History

2020-05-24 23:13:21 +05:30
import mountComponent from 'helpers/vue_mount_component_helper';
2018-12-13 13:39:08 +05:30
import Vue from 'vue';
import GlCountdown from '~/vue_shared/components/gl_countdown.vue';
describe('GlCountdown', () => {
const Component = Vue.extend(GlCountdown);
let vm;
let now = '2000-01-01T00:00:00Z';
beforeEach(() => {
2020-05-24 23:13:21 +05:30
jest.spyOn(Date, 'now').mockImplementation(() => new Date(now).getTime());
2018-12-13 13:39:08 +05:30
});
afterEach(() => {
vm.$destroy();
2020-05-24 23:13:21 +05:30
jest.clearAllTimers();
2018-12-13 13:39:08 +05:30
});
describe('when there is time remaining', () => {
beforeEach(done => {
vm = mountComponent(Component, {
endDateString: '2000-01-01T01:02:03Z',
});
Vue.nextTick()
.then(done)
.catch(done.fail);
});
it('displays remaining time', () => {
2020-05-24 23:13:21 +05:30
expect(vm.$el.textContent).toContain('01:02:03');
2018-12-13 13:39:08 +05:30
});
it('updates remaining time', done => {
now = '2000-01-01T00:00:01Z';
2020-05-24 23:13:21 +05:30
jest.advanceTimersByTime(1000);
2018-12-13 13:39:08 +05:30
Vue.nextTick()
.then(() => {
2020-05-24 23:13:21 +05:30
expect(vm.$el.textContent).toContain('01:02:02');
2018-12-13 13:39:08 +05:30
done();
})
.catch(done.fail);
});
});
describe('when there is no time remaining', () => {
beforeEach(done => {
vm = mountComponent(Component, {
endDateString: '1900-01-01T00:00:00Z',
});
Vue.nextTick()
.then(done)
.catch(done.fail);
});
it('displays 00:00:00', () => {
2020-05-24 23:13:21 +05:30
expect(vm.$el.textContent).toContain('00:00:00');
2018-12-13 13:39:08 +05:30
});
});
describe('when an invalid date is passed', () => {
2020-05-24 23:13:21 +05:30
beforeEach(() => {
Vue.config.warnHandler = jest.fn();
});
afterEach(() => {
Vue.config.warnHandler = null;
});
2018-12-13 13:39:08 +05:30
it('throws a validation error', () => {
vm = mountComponent(Component, {
endDateString: 'this is invalid',
});
expect(Vue.config.warnHandler).toHaveBeenCalledTimes(1);
2020-05-24 23:13:21 +05:30
const [errorMessage] = Vue.config.warnHandler.mock.calls[0];
2018-12-13 13:39:08 +05:30
expect(errorMessage).toMatch(/^Invalid prop: .* "endDateString"/);
});
});
});