debian-mirror-gitlab/spec/javascripts/blob/pdf/index_spec.js

73 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
import renderPDF from '~/blob/pdf';
2019-07-31 22:56:46 +05:30
import { FIXTURES_PATH } from 'spec/test_constants';
const testPDF = `${FIXTURES_PATH}/blob/pdf/test.pdf`;
2017-08-17 22:00:37 +05:30
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();
}
};
2019-07-07 11:18:12 +05:30
preloadFixtures('static/pdf_viewer.html');
2017-08-17 22:00:37 +05:30
beforeEach(() => {
2019-07-07 11:18:12 +05:30
loadFixtures('static/pdf_viewer.html');
2017-08-17 22:00:37 +05:30
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
});
});
});