Wait for the PDF to be loaded before doing anything

Closes #30531
This commit is contained in:
Phil Hughes 2017-04-06 10:08:33 +01:00
parent 49bdd8d63b
commit 5e67b2fdb0
2 changed files with 17 additions and 9 deletions

View file

@ -10,7 +10,7 @@ Vue.use(PDFLab, {
export default () => { export default () => {
const el = document.getElementById('js-pdf-viewer'); const el = document.getElementById('js-pdf-viewer');
new Vue({ return new Vue({
el, el,
data() { data() {
return { return {

View file

@ -3,6 +3,18 @@ import testPDF from './test.pdf';
describe('PDF renderer', () => { describe('PDF renderer', () => {
let viewer; let viewer;
let app;
const checkLoaded = (done) => {
if (app.loading) {
setTimeout(() => {
checkLoaded(done);
}, 100);
} else {
done();
}
};
preloadFixtures('static/pdf_viewer.html.raw'); preloadFixtures('static/pdf_viewer.html.raw');
beforeEach(() => { beforeEach(() => {
@ -21,11 +33,9 @@ describe('PDF renderer', () => {
describe('successful response', () => { describe('successful response', () => {
beforeEach((done) => { beforeEach((done) => {
renderPDF(); app = renderPDF();
setTimeout(() => { checkLoaded(done);
done();
}, 500);
}); });
it('does not show loading icon', () => { it('does not show loading icon', () => {
@ -50,11 +60,9 @@ describe('PDF renderer', () => {
describe('error getting file', () => { describe('error getting file', () => {
beforeEach((done) => { beforeEach((done) => {
viewer.dataset.endpoint = 'invalid/endpoint'; viewer.dataset.endpoint = 'invalid/endpoint';
renderPDF(); app = renderPDF();
setTimeout(() => { checkLoaded(done);
done();
}, 500);
}); });
it('does not show loading icon', () => { it('does not show loading icon', () => {