gitlab-org--gitlab-foss/spec/javascripts/pdf/page_spec.js
Lukas Eipert c2674c2d37
Move to pdf.js distributed with npm
pdf.js is available on npm. Importing the dependency from there instead
of vendoring it has certain benefits, e.g. the discoverability of
updates (especially security fixes).
2019-05-10 15:07:41 -05:00

50 lines
1.2 KiB
JavaScript

import Vue from 'vue';
import pdfjsLib from 'pdfjs-dist/build/pdf';
import workerSrc from 'pdfjs-dist/build/pdf.worker.min';
import PageComponent from '~/pdf/page/index.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { FIXTURES_PATH } from 'spec/test_constants';
const testPDF = `${FIXTURES_PATH}/blob/pdf/test.pdf`;
describe('Page component', () => {
const Component = Vue.extend(PageComponent);
let vm;
let testPage;
beforeEach(done => {
pdfjsLib.GlobalWorkerOptions.workerSrc = workerSrc;
pdfjsLib
.getDocument(testPDF)
.then(pdf => pdf.getPage(1))
.then(page => {
testPage = page;
})
.then(done)
.catch(done.fail);
});
afterEach(() => {
vm.$destroy();
});
it('renders the page when mounting', done => {
const promise = Promise.resolve();
spyOn(testPage, 'render').and.callFake(() => promise);
vm = mountComponent(Component, {
page: testPage,
number: 1,
});
expect(vm.rendering).toBe(true);
promise
.then(() => {
expect(testPage.render).toHaveBeenCalledWith(vm.renderContext);
expect(vm.rendering).toBe(false);
})
.then(done)
.catch(done.fail);
});
});