debian-mirror-gitlab/spec/javascripts/pdf/page_spec.js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
import Vue from 'vue';
2017-09-10 17:25:29 +05:30
import pdfjsLib from 'vendor/pdf';
import workerSrc from 'vendor/pdf.worker.min';
2017-08-17 22:00:37 +05:30
import PageComponent from '~/pdf/page/index.vue';
2018-11-20 20:47:30 +05:30
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import testPDF from 'spec/fixtures/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 => {
pdfjsLib.PDFJS.workerSrc = workerSrc;
pdfjsLib
.getDocument(testPDF)
2017-08-17 22:00:37 +05:30
.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();
spyOn(testPage, 'render').and.callFake(() => promise);
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
});
});