Merge branch 'winh-fix-pdf-page-spec-timing' into 'master'
Remove waiting from PDF page component test See merge request gitlab-org/gitlab-ce!21365
This commit is contained in:
commit
29df3f1d3f
1 changed files with 27 additions and 35 deletions
|
@ -3,53 +3,45 @@ import pdfjsLib from 'vendor/pdf';
|
||||||
import workerSrc from 'vendor/pdf.worker.min';
|
import workerSrc from 'vendor/pdf.worker.min';
|
||||||
|
|
||||||
import PageComponent from '~/pdf/page/index.vue';
|
import PageComponent from '~/pdf/page/index.vue';
|
||||||
import testPDF from '../fixtures/blob/pdf/test.pdf';
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
||||||
|
import testPDF from 'spec/fixtures/blob/pdf/test.pdf';
|
||||||
const Component = Vue.extend(PageComponent);
|
|
||||||
|
|
||||||
describe('Page component', () => {
|
describe('Page component', () => {
|
||||||
|
const Component = Vue.extend(PageComponent);
|
||||||
let vm;
|
let vm;
|
||||||
let testPage;
|
let testPage;
|
||||||
pdfjsLib.PDFJS.workerSrc = workerSrc;
|
|
||||||
|
|
||||||
const checkRendered = (done) => {
|
beforeEach(done => {
|
||||||
if (vm.rendering) {
|
pdfjsLib.PDFJS.workerSrc = workerSrc;
|
||||||
setTimeout(() => {
|
pdfjsLib
|
||||||
checkRendered(done);
|
.getDocument(testPDF)
|
||||||
}, 100);
|
|
||||||
} else {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach((done) => {
|
|
||||||
pdfjsLib.getDocument(testPDF)
|
|
||||||
.then(pdf => pdf.getPage(1))
|
.then(pdf => pdf.getPage(1))
|
||||||
.then((page) => {
|
.then(page => {
|
||||||
testPage = page;
|
testPage = page;
|
||||||
done();
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.then(done)
|
||||||
done.fail(error);
|
.catch(done.fail);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('render', () => {
|
afterEach(() => {
|
||||||
beforeEach((done) => {
|
vm.$destroy();
|
||||||
vm = new Component({
|
});
|
||||||
propsData: {
|
|
||||||
page: testPage,
|
|
||||||
number: 1,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
vm.$mount();
|
it('renders the page when mounting', done => {
|
||||||
|
const promise = Promise.resolve();
|
||||||
checkRendered(done);
|
spyOn(testPage, 'render').and.callFake(() => promise);
|
||||||
|
vm = mountComponent(Component, {
|
||||||
|
page: testPage,
|
||||||
|
number: 1,
|
||||||
});
|
});
|
||||||
|
expect(vm.rendering).toBe(true);
|
||||||
|
|
||||||
it('renders first page', () => {
|
promise
|
||||||
expect(vm.$el.tagName).toBeDefined();
|
.then(() => {
|
||||||
});
|
expect(testPage.render).toHaveBeenCalledWith(vm.renderContext);
|
||||||
|
expect(vm.rendering).toBe(false);
|
||||||
|
})
|
||||||
|
.then(done)
|
||||||
|
.catch(done.fail);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue