2017-08-17 22:00:37 +05:30
|
|
|
import renderPDF from '~/blob/pdf';
|
|
|
|
import testPDF from '../../fixtures/blob/pdf/test.pdf';
|
|
|
|
|
|
|
|
describe('PDF renderer', () => {
|
|
|
|
let viewer;
|
|
|
|
let app;
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
const checkLoaded = done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
if (app.loading) {
|
|
|
|
setTimeout(() => {
|
|
|
|
checkLoaded(done);
|
|
|
|
}, 100);
|
|
|
|
} else {
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(document.querySelector('.loading')).not.toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('successful response', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
app = renderPDF();
|
|
|
|
|
|
|
|
checkLoaded(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show loading icon', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(document.querySelector('.loading')).toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the PDF', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(document.querySelector('.pdf-viewer')).not.toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the PDF page', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(document.querySelector('.pdf-page')).not.toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('error getting file', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
viewer.dataset.endpoint = 'invalid/path/to/file.pdf';
|
|
|
|
app = renderPDF();
|
|
|
|
|
|
|
|
checkLoaded(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show loading icon', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(document.querySelector('.loading')).toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('shows error message', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(document.querySelector('.md').textContent.trim()).toBe(
|
|
|
|
'An error occurred whilst loading the file. Please try again later.',
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|