summaryrefslogtreecommitdiff
path: root/spec/frontend/pdf/page_spec.js
blob: 4e24b0696ecf6943a073ee42a73a19968d7d01c0 (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
import Vue from 'vue';
import PageComponent from '~/pdf/page/index.vue';
import mountComponent from 'helpers/vue_mount_component_helper';

jest.mock('pdfjs-dist/webpack', () => {
  return { default: jest.requireActual('pdfjs-dist/build/pdf') };
});

describe('Page component', () => {
  const Component = Vue.extend(PageComponent);
  let vm;

  afterEach(() => {
    vm.$destroy();
  });

  it('renders the page when mounting', done => {
    const promise = Promise.resolve();
    const testPage = {
      render: jest.fn().mockReturnValue({ promise: Promise.resolve() }),
      getViewport: jest.fn().mockReturnValue({}),
    };

    vm = mountComponent(Component, {
      page: testPage,
      number: 1,
    });

    expect(vm.rendering).toBe(true);

    promise
      .then(() => {
        expect(testPage.render).toHaveBeenCalledWith(vm.renderContext);
        expect(vm.rendering).toBe(false);
      })
      .then(done)
      .catch(done.fail);
  });
});