summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/code_block_spec.js
blob: 9a4dbcc47ff77d87b421aaaedb83ec7960c176a3 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { shallowMount } from '@vue/test-utils';
import CodeBlock from '~/vue_shared/components/code_block.vue';

describe('Code Block', () => {
  let wrapper;

  const code = 'test-code';

  const createComponent = (propsData, slots = {}) => {
    wrapper = shallowMount(CodeBlock, {
      slots,
      propsData,
    });
  };

  afterEach(() => {
    wrapper.destroy();
  });

  it('overwrites the default slot', () => {
    createComponent({}, { default: 'DEFAULT SLOT' });

    expect(wrapper.element).toMatchInlineSnapshot(`
        <pre
          class="code-block rounded code"
        >
          DEFAULT SLOT
        </pre>
      `);
  });

  it('renders with empty code prop', () => {
    createComponent({});

    expect(wrapper.element).toMatchInlineSnapshot(`
      <pre
        class="code-block rounded code"
      >
        <code
          class="d-block"
        >
          
        </code>
      </pre>
    `);
  });

  it('renders code prop when provided', () => {
    createComponent({ code });

    expect(wrapper.element).toMatchInlineSnapshot(`
        <pre
          class="code-block rounded code"
        >
          <code
            class="d-block"
          >
            test-code
          </code>
        </pre>
      `);
  });

  it('sets maxHeight properly when provided', () => {
    createComponent({ code, maxHeight: '200px' });

    expect(wrapper.element).toMatchInlineSnapshot(`
        <pre
          class="code-block rounded code"
          style="max-height: 200px; overflow-y: auto;"
        >
          <code
            class="d-block"
          >
            test-code
          </code>
        </pre>
      `);
  });
});