2017-08-17 22:00:37 +05:30
|
|
|
import Vue from 'vue';
|
2019-09-04 21:01:54 +05:30
|
|
|
import pdfjsLib from 'pdfjs-dist/build/pdf';
|
|
|
|
import workerSrc from 'pdfjs-dist/build/pdf.worker.min';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
2019-07-31 22:56:46 +05:30
|
|
|
import { FIXTURES_PATH } from 'spec/test_constants';
|
2020-01-01 13:55:28 +05:30
|
|
|
import PageComponent from '~/pdf/page/index.vue';
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
const testPDF = `${FIXTURES_PATH}/blob/pdf/test.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;
|
|
|
|
let testPage;
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
beforeEach(done => {
|
2019-04-03 18:18:56 +05:30
|
|
|
pdfjsLib.GlobalWorkerOptions.workerSrc = workerSrc;
|
2018-11-20 20:47:30 +05:30
|
|
|
pdfjsLib
|
|
|
|
.getDocument(testPDF)
|
2019-10-12 21:52:04 +05:30
|
|
|
.promise.then(pdf => pdf.getPage(1))
|
2018-11-20 20:47:30 +05:30
|
|
|
.then(page => {
|
2017-08-17 22:00:37 +05:30
|
|
|
testPage = page;
|
|
|
|
})
|
2018-11-20 20:47:30 +05:30
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
it('renders the page when mounting', done => {
|
|
|
|
const promise = Promise.resolve();
|
2019-10-12 21:52:04 +05:30
|
|
|
spyOn(testPage, 'render').and.returnValue({ promise });
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|