BigW Consortium Gitlab

index_spec.js 2.17 KB
Newer Older
1 2 3 4 5 6 7
import Vue from 'vue';
import Notebook from '~/notebook/index.vue';

const Component = Vue.extend(Notebook);

describe('Notebook component', () => {
  let vm;
8 9 10 11 12 13 14
  let json;
  let jsonWithWorksheet;

  beforeEach(() => {
    json = getJSONFixture('blob/notebook/basic.json');
    jsonWithWorksheet = getJSONFixture('blob/notebook/worksheets.json');
  });
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

  describe('without JSON', () => {
    beforeEach((done) => {
      vm = new Component({
        propsData: {
          notebook: {},
        },
      });
      vm.$mount();

      setTimeout(() => {
        done();
      });
    });

    it('does not render', () => {
      expect(vm.$el.tagName).toBeUndefined();
    });
  });

  describe('with JSON', () => {
    beforeEach((done) => {
      vm = new Component({
        propsData: {
          notebook: json,
          codeCssClass: 'js-code-class',
        },
      });
      vm.$mount();

      setTimeout(() => {
        done();
      });
    });

    it('renders cells', () => {
      expect(vm.$el.querySelectorAll('.cell').length).toBe(json.cells.length);
    });

    it('renders markdown cell', () => {
      expect(vm.$el.querySelector('.markdown')).not.toBeNull();
    });

    it('renders code cell', () => {
      expect(vm.$el.querySelector('pre')).not.toBeNull();
    });

    it('add code class to code blocks', () => {
      expect(vm.$el.querySelector('.js-code-class')).not.toBeNull();
    });
  });

  describe('with worksheets', () => {
    beforeEach((done) => {
      vm = new Component({
        propsData: {
          notebook: jsonWithWorksheet,
          codeCssClass: 'js-code-class',
        },
      });
      vm.$mount();

      setTimeout(() => {
        done();
      });
    });

    it('renders cells', () => {
      expect(vm.$el.querySelectorAll('.cell').length).toBe(jsonWithWorksheet.worksheets[0].cells.length);
    });

    it('renders markdown cell', () => {
      expect(vm.$el.querySelector('.markdown')).not.toBeNull();
    });

    it('renders code cell', () => {
      expect(vm.$el.querySelector('pre')).not.toBeNull();
    });

    it('add code class to code blocks', () => {
      expect(vm.$el.querySelector('.js-code-class')).not.toBeNull();
    });
  });
});