2017-04-12 02:44:22 +00:00
|
|
|
import Vue from 'vue';
|
2020-03-13 21:09:38 +00:00
|
|
|
import pdfjsLib from 'pdfjs-dist/webpack';
|
2017-04-12 02:44:22 +00:00
|
|
|
|
2018-08-23 19:05:20 +00:00
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
2019-04-25 12:22:00 +00:00
|
|
|
import { FIXTURES_PATH } from 'spec/test_constants';
|
2019-12-11 09:08:12 +00:00
|
|
|
import PageComponent from '~/pdf/page/index.vue';
|
2019-04-25 12:22:00 +00:00
|
|
|
|
|
|
|
const testPDF = `${FIXTURES_PATH}/blob/pdf/test.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;
|
|
|
|
let testPage;
|
|
|
|
|
2018-08-23 19:05:20 +00:00
|
|
|
beforeEach(done => {
|
|
|
|
pdfjsLib
|
|
|
|
.getDocument(testPDF)
|
2019-07-29 19:47:40 +00:00
|
|
|
.promise.then(pdf => pdf.getPage(1))
|
2018-08-23 19:05:20 +00:00
|
|
|
.then(page => {
|
2017-04-12 02:44:22 +00:00
|
|
|
testPage = page;
|
|
|
|
})
|
2018-08-23 19:05:20 +00:00
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-04-12 02:44:22 +00:00
|
|
|
});
|
|
|
|
|
2018-08-23 19:05:20 +00:00
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
2017-04-12 02:44:22 +00:00
|
|
|
|
2018-08-23 19:05:20 +00:00
|
|
|
it('renders the page when mounting', done => {
|
|
|
|
const promise = Promise.resolve();
|
2019-07-29 19:47:40 +00:00
|
|
|
spyOn(testPage, 'render').and.returnValue({ promise });
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|