BigW Consortium Gitlab

page_spec.js 1.11 KB
Newer Older
Sam Rose committed
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
/* eslint-disable import/no-unresolved */

import Vue from 'vue';
import pdfjsLib from 'pdfjs-dist';
import workerSrc from 'vendor/pdf.worker';

import PageComponent from '~/pdf/page/index.vue';
import testPDF from '../fixtures/blob/pdf/test.pdf';

const Component = Vue.extend(PageComponent);

describe('Page component', () => {
  let vm;
  let testPage;
  pdfjsLib.PDFJS.workerSrc = workerSrc;

  const checkRendered = (done) => {
    if (vm.rendering) {
      setTimeout(() => {
        checkRendered(done);
      }, 100);
    } else {
      done();
    }
  };

  beforeEach((done) => {
    pdfjsLib.getDocument(testPDF)
      .then(pdf => pdf.getPage(1))
      .then((page) => {
        testPage = page;
        done();
      })
      .catch((error) => {
        console.error(error);
      });
  });

  describe('render', () => {
    beforeEach((done) => {
      vm = new Component({
        propsData: {
          page: testPage,
          number: 1,
        },
      });

      vm.$mount();

      checkRendered(done);
    });

    it('renders first page', () => {
      expect(vm.$el.tagName).toBeDefined();
    });
  });
});