summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/rich_content_editor/toolbar_item_spec.js
blob: 0e6f951bd53c2e1810a5691a731066d5b5288d04 (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
import { shallowMount } from '@vue/test-utils';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import { GlIcon } from '@gitlab/ui';
import ToolbarItem from '~/vue_shared/components/rich_content_editor/toolbar_item.vue';

describe('Toolbar Item', () => {
  let wrapper;

  const findIcon = () => wrapper.find(GlIcon);
  const findButton = () => wrapper.find('button');

  const buildWrapper = (propsData) => {
    wrapper = shallowMount(ToolbarItem, {
      propsData,
      directives: {
        GlTooltip: createMockDirective(),
      },
    });
  };

  describe.each`
    icon               | tooltip
    ${'heading'}       | ${'Headings'}
    ${'bold'}          | ${'Add bold text'}
    ${'italic'}        | ${'Add italic text'}
    ${'strikethrough'} | ${'Add strikethrough text'}
    ${'quote'}         | ${'Insert a quote'}
    ${'link'}          | ${'Add a link'}
    ${'doc-code'}      | ${'Insert a code block'}
    ${'list-bulleted'} | ${'Add a bullet list'}
    ${'list-numbered'} | ${'Add a numbered list'}
    ${'list-task'}     | ${'Add a task list'}
    ${'list-indent'}   | ${'Indent'}
    ${'list-outdent'}  | ${'Outdent'}
    ${'dash'}          | ${'Add a line'}
    ${'table'}         | ${'Add a table'}
    ${'code'}          | ${'Insert an image'}
    ${'code'}          | ${'Insert inline code'}
  `('toolbar item component', ({ icon, tooltip }) => {
    beforeEach(() => buildWrapper({ icon, tooltip }));

    it('renders a toolbar button', () => {
      expect(findButton().exists()).toBe(true);
    });

    it('renders the correct tooltip', () => {
      const buttonTooltip = getBinding(wrapper.element, 'gl-tooltip');
      expect(buttonTooltip).toBeDefined();
      expect(buttonTooltip.value.title).toBe(tooltip);
    });

    it(`renders the ${icon} icon`, () => {
      expect(findIcon().exists()).toBe(true);
      expect(findIcon().props().name).toBe(icon);
    });
  });
});