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