diff options
author | Sam Rose <sam@gitlab.com> | 2017-04-03 14:39:50 -0400 |
---|---|---|
committer | Jacob Schatz <jschatz1@gmail.com> | 2017-04-05 11:22:12 -0400 |
commit | dad30d6bbf9816993bf999edcc7b1a7203a3eae5 (patch) | |
tree | a8b75a1fc2bbe22d54da02c0396ba2089ff7360b /spec/javascripts | |
parent | 97667b83420cf42b01836d9b0c46d904f55aae21 (diff) | |
download | gitlab-ce-dad30d6bbf9816993bf999edcc7b1a7203a3eae5.tar.gz |
Use PDFLab to render PDFs in GitLab
Diffstat (limited to 'spec/javascripts')
-rw-r--r-- | spec/javascripts/blob/pdf/index_spec.js | 72 | ||||
-rw-r--r-- | spec/javascripts/blob/pdf/test.pdf | bin | 0 -> 11956 bytes | |||
-rw-r--r-- | spec/javascripts/fixtures/pdf_viewer.html.haml | 1 |
3 files changed, 73 insertions, 0 deletions
diff --git a/spec/javascripts/blob/pdf/index_spec.js b/spec/javascripts/blob/pdf/index_spec.js new file mode 100644 index 00000000000..19a4e55a9db --- /dev/null +++ b/spec/javascripts/blob/pdf/index_spec.js @@ -0,0 +1,72 @@ +import renderPDF from '~/blob/pdf'; +import testPDF from './test.pdf'; + +describe('PDF renderer', () => { + let viewer; + 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) => { + renderPDF(); + + setTimeout(() => { + done(); + }, 500); + }); + + 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) => { + viewer.dataset.endpoint = 'invalid/endpoint'; + renderPDF(); + + setTimeout(() => { + done(); + }, 500); + }); + + 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.'); + }); + }); +}); diff --git a/spec/javascripts/blob/pdf/test.pdf b/spec/javascripts/blob/pdf/test.pdf Binary files differnew file mode 100644 index 00000000000..eb3d147fde3 --- /dev/null +++ b/spec/javascripts/blob/pdf/test.pdf diff --git a/spec/javascripts/fixtures/pdf_viewer.html.haml b/spec/javascripts/fixtures/pdf_viewer.html.haml new file mode 100644 index 00000000000..2e57beae54b --- /dev/null +++ b/spec/javascripts/fixtures/pdf_viewer.html.haml @@ -0,0 +1 @@ +.file-content#js-pdf-viewer{ data: { endpoint: '/test' } } |