Welcome to mirror list, hosted at ThFree Co, Russian Federation.

index_spec.js « pdf « blob « javascripts « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6fa3890483c504c0ef8fdef3996724b4e0caaa1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import renderPDF from '~/blob/pdf';
import { FIXTURES_PATH } from 'spec/test_constants';

const testPDF = `${FIXTURES_PATH}/blob/pdf/test.pdf`;

describe('PDF renderer', () => {
  let viewer;
  let app;

  const checkLoaded = done => {
    if (app.loading) {
      setTimeout(() => {
        checkLoaded(done);
      }, 100);
    } else {
      done();
    }
  };

  preloadFixtures('static/pdf_viewer.html');

  beforeEach(() => {
    loadFixtures('static/pdf_viewer.html');
    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();

      checkLoaded(done);
    });

    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/path/to/file.pdf';
      app = renderPDF();

      checkLoaded(done);
    });

    it('does not show loading icon', () => {
      expect(document.querySelector('.loading')).toBeNull();
    });

    it('shows error message', () => {
      expect(document.querySelector('.md').textContent.trim()).toBe(
        'An error occurred whilst loading the file. Please try again later.',
      );
    });
  });
});