gitlab-org--gitlab-foss/spec/javascripts/blob/pdf/index_spec.js

83 lines
1.7 KiB
JavaScript
Raw Normal View History

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;
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) => {
app = renderPDF();
2017-04-03 14:39:50 -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';
app = renderPDF();
2017-04-03 14:39:50 -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(),
2017-09-25 16:02:08 -04:00
).toBe('An error occurred whilst loading the file. Please try again later.');
2017-04-03 14:39:50 -04:00
});
});
});