debian-mirror-gitlab/spec/frontend/pdf/page_spec.js

40 lines
964 B
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
import Vue from 'vue';
2020-06-23 00:09:42 +05:30
import mountComponent from 'helpers/vue_mount_component_helper';
2020-10-24 23:57:45 +05:30
import PageComponent from '~/pdf/page/index.vue';
2019-07-31 22:56:46 +05:30
2020-06-23 00:09:42 +05:30
jest.mock('pdfjs-dist/webpack', () => {
return { default: jest.requireActual('pdfjs-dist/build/pdf') };
});
2017-08-17 22:00:37 +05:30
describe('Page component', () => {
2018-11-20 20:47:30 +05:30
const Component = Vue.extend(PageComponent);
2017-08-17 22:00:37 +05:30
let vm;
2018-11-20 20:47:30 +05:30
afterEach(() => {
vm.$destroy();
});
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
it('renders the page when mounting', (done) => {
2018-11-20 20:47:30 +05:30
const promise = Promise.resolve();
2020-06-23 00:09:42 +05:30
const testPage = {
render: jest.fn().mockReturnValue({ promise: Promise.resolve() }),
getViewport: jest.fn().mockReturnValue({}),
};
2019-10-12 21:52:04 +05:30
2018-11-20 20:47:30 +05:30
vm = mountComponent(Component, {
page: testPage,
number: 1,
2017-08-17 22:00:37 +05:30
});
2018-12-13 13:39:08 +05:30
2018-11-20 20:47:30 +05:30
expect(vm.rendering).toBe(true);
2017-08-17 22:00:37 +05:30
2018-11-20 20:47:30 +05:30
promise
.then(() => {
expect(testPage.render).toHaveBeenCalledWith(vm.renderContext);
expect(vm.rendering).toBe(false);
})
.then(done)
.catch(done.fail);
2017-08-17 22:00:37 +05:30
});
});