2017-04-11 22:44:22 -04:00
|
|
|
import Vue from 'vue';
|
2017-08-07 03:47:29 -04:00
|
|
|
import pdfjsLib from 'vendor/pdf';
|
|
|
|
import workerSrc from 'vendor/pdf.worker.min';
|
2017-04-11 22:44:22 -04:00
|
|
|
|
|
|
|
import PageComponent from '~/pdf/page/index.vue';
|
2018-08-23 15:05:20 -04:00
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
|
|
|
import testPDF from 'spec/fixtures/blob/pdf/test.pdf';
|
2017-04-11 22:44:22 -04:00
|
|
|
|
|
|
|
describe('Page component', () => {
|
2018-08-23 15:05:20 -04:00
|
|
|
const Component = Vue.extend(PageComponent);
|
2017-04-11 22:44:22 -04:00
|
|
|
let vm;
|
|
|
|
let testPage;
|
|
|
|
|
2018-08-23 15:05:20 -04:00
|
|
|
beforeEach(done => {
|
2019-03-13 08:59:15 -04:00
|
|
|
pdfjsLib.GlobalWorkerOptions.workerSrc = workerSrc;
|
2018-08-23 15:05:20 -04:00
|
|
|
pdfjsLib
|
|
|
|
.getDocument(testPDF)
|
2017-04-11 22:44:22 -04:00
|
|
|
.then(pdf => pdf.getPage(1))
|
2018-08-23 15:05:20 -04:00
|
|
|
.then(page => {
|
2017-04-11 22:44:22 -04:00
|
|
|
testPage = page;
|
|
|
|
})
|
2018-08-23 15:05:20 -04:00
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-04-11 22:44:22 -04:00
|
|
|
});
|
|
|
|
|
2018-08-23 15:05:20 -04:00
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
2017-04-11 22:44:22 -04:00
|
|
|
|
2018-08-23 15:05:20 -04:00
|
|
|
it('renders the page when mounting', done => {
|
|
|
|
const promise = Promise.resolve();
|
|
|
|
spyOn(testPage, 'render').and.callFake(() => promise);
|
|
|
|
vm = mountComponent(Component, {
|
|
|
|
page: testPage,
|
|
|
|
number: 1,
|
2017-04-11 22:44:22 -04:00
|
|
|
});
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-08-23 15:05:20 -04:00
|
|
|
expect(vm.rendering).toBe(true);
|
2017-04-11 22:44:22 -04:00
|
|
|
|
2018-08-23 15:05:20 -04:00
|
|
|
promise
|
|
|
|
.then(() => {
|
|
|
|
expect(testPage.render).toHaveBeenCalledWith(vm.renderContext);
|
|
|
|
expect(vm.rendering).toBe(false);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-04-11 22:44:22 -04:00
|
|
|
});
|
|
|
|
});
|