2017-04-11 22:44:22 -04:00
|
|
|
/* eslint-disable import/no-unresolved */
|
|
|
|
|
2017-04-03 14:39:50 -04:00
|
|
|
import renderPDF from '~/blob/pdf';
|
2017-04-11 22:44:22 -04:00
|
|
|
import testPDF from '../../fixtures/blob/pdf/test.pdf';
|
2017-04-03 14:39:50 -04:00
|
|
|
|
|
|
|
describe('PDF renderer', () => {
|
|
|
|
let viewer;
|
2017-04-06 05:08:33 -04:00
|
|
|
let app;
|
|
|
|
|
|
|
|
const checkLoaded = (done) => {
|
|
|
|
if (app.loading) {
|
|
|
|
setTimeout(() => {
|
|
|
|
checkLoaded(done);
|
|
|
|
}, 100);
|
|
|
|
} else {
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-03 14:39:50 -04:00
|
|
|
preloadFixtures('static/pdf_viewer.html.raw');
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
loadFixtures('static/pdf_viewer.html.raw');
|
|
|
|
viewer = document.getElementById('js-pdf-viewer');
|
|
|
|
viewer.dataset.endpoint = testPDF;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows loading icon', () => {
|
|
|
|
renderPDF();
|
|
|
|
|
|
|
|
expect(
|
|
|
|
document.querySelector('.loading'),
|
|
|
|
).not.toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('successful response', () => {
|
|
|
|
beforeEach((done) => {
|
2017-04-06 05:08:33 -04:00
|
|
|
app = renderPDF();
|
2017-04-03 14:39:50 -04:00
|
|
|
|
2017-04-06 05:08:33 -04:00
|
|
|
checkLoaded(done);
|
2017-04-03 14:39:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show loading icon', () => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.loading'),
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the PDF', () => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.pdf-viewer'),
|
|
|
|
).not.toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the PDF page', () => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.pdf-page'),
|
|
|
|
).not.toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('error getting file', () => {
|
|
|
|
beforeEach((done) => {
|
2017-04-11 22:44:22 -04:00
|
|
|
viewer.dataset.endpoint = 'invalid/path/to/file.pdf';
|
2017-04-06 05:08:33 -04:00
|
|
|
app = renderPDF();
|
2017-04-03 14:39:50 -04:00
|
|
|
|
2017-04-06 05:08:33 -04:00
|
|
|
checkLoaded(done);
|
2017-04-03 14:39:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show loading icon', () => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.loading'),
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows error message', () => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.md').textContent.trim(),
|
|
|
|
).toBe('An error occured whilst loading the file. Please try again later.');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|