summaryrefslogtreecommitdiff
path: root/spec/frontend/notebook/cells/output/dataframe_spec.js
blob: bf90497a36ba78c27414cf99bed379afafb44e94 (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
import { shallowMount } from '@vue/test-utils';
import DataframeOutput from '~/notebook/cells/output/dataframe.vue';
import JSONTable from '~/behaviors/components/json_table.vue';
import { outputWithDataframe } from '../../mock_data';

describe('~/notebook/cells/output/DataframeOutput', () => {
  let wrapper;

  function createComponent(rawCode) {
    wrapper = shallowMount(DataframeOutput, {
      propsData: {
        rawCode,
        count: 0,
        index: 0,
      },
    });
  }

  const findTable = () => wrapper.findComponent(JSONTable);

  describe('with valid dataframe', () => {
    beforeEach(() => createComponent(outputWithDataframe.data['text/html'].join('')));

    it('mounts the table', () => {
      expect(findTable().exists()).toBe(true);
    });

    it('table caption is empty', () => {
      expect(findTable().props().caption).toEqual('');
    });

    it('allows filtering', () => {
      expect(findTable().props().hasFilter).toBe(true);
    });

    it('sets the correct fields', () => {
      expect(findTable().props().fields).toEqual([
        { key: 'index0', label: '', sortable: true, class: 'gl-font-weight-bold' },
        { key: 'column0', label: 'column_1', sortable: true, class: '' },
        { key: 'column1', label: 'column_2', sortable: true, class: '' },
      ]);
    });

    it('sets the correct items', () => {
      expect(findTable().props().items).toEqual([
        { index0: '0', column0: 'abc de f', column1: 'a' },
        { index0: '1', column0: 'True', column1: '0.1' },
      ]);
    });
  });

  describe('invalid dataframe', () => {
    it('still displays the table', () => {
      createComponent('dataframe');

      expect(findTable().exists()).toBe(true);
    });
  });
});