summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/markdown/editor_mode_switcher_spec.js
blob: 693353ed604261050841e56add426cd7a6b6223d (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
import { GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import EditorModeSwitcher from '~/vue_shared/components/markdown/editor_mode_switcher.vue';

describe('vue_shared/component/markdown/editor_mode_switcher', () => {
  let wrapper;

  const createComponent = ({ value } = {}) => {
    wrapper = shallowMount(EditorModeSwitcher, {
      propsData: {
        value,
      },
    });
  };

  const findSwitcherButton = () => wrapper.findComponent(GlButton);

  describe.each`
    modeText       | value         | buttonText
    ${'Rich text'} | ${'richText'} | ${'Switch to Markdown'}
    ${'Markdown'}  | ${'markdown'} | ${'Switch to rich text'}
  `('when $modeText', ({ modeText, value, buttonText }) => {
    beforeEach(() => {
      createComponent({ value });
    });

    it('shows correct button label', () => {
      expect(findSwitcherButton().text()).toEqual(buttonText);
    });

    it('emits event on click', () => {
      findSwitcherButton(modeText).vm.$emit('click');

      expect(wrapper.emitted().input).toEqual([[]]);
    });
  });
});