summaryrefslogtreecommitdiff
path: root/spec/frontend/code_navigation/components/popover_spec.js
blob: ad05504a224075ba1eb9aae84851087ec4718612 (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
import { shallowMount } from '@vue/test-utils';
import Popover from '~/code_navigation/components/popover.vue';

const MOCK_CODE_DATA = Object.freeze({
  hover: [
    {
      language: 'javascript',
      value: 'console.log',
    },
  ],
  definition_url: 'http://test.com',
});

const MOCK_DOCS_DATA = Object.freeze({
  hover: [
    {
      language: null,
      value: 'console.log',
    },
  ],
  definition_url: 'http://test.com',
});

let wrapper;

function factory(position, data) {
  wrapper = shallowMount(Popover, { propsData: { position, data } });
}

describe('Code navigation popover component', () => {
  afterEach(() => {
    wrapper.destroy();
  });

  it('renders popover', () => {
    factory({ x: 0, y: 0, height: 0 }, MOCK_CODE_DATA);

    expect(wrapper.element).toMatchSnapshot();
  });

  describe('code output', () => {
    it('renders code output', () => {
      factory({ x: 0, y: 0, height: 0 }, MOCK_CODE_DATA);

      expect(wrapper.find({ ref: 'code-output' }).exists()).toBe(true);
      expect(wrapper.find({ ref: 'doc-output' }).exists()).toBe(false);
    });
  });

  describe('documentation output', () => {
    it('renders code output', () => {
      factory({ x: 0, y: 0, height: 0 }, MOCK_DOCS_DATA);

      expect(wrapper.find({ ref: 'code-output' }).exists()).toBe(false);
      expect(wrapper.find({ ref: 'doc-output' }).exists()).toBe(true);
    });
  });
});