summaryrefslogtreecommitdiff
path: root/spec/frontend/content_editor/components/content_editor_spec.js
blob: 59c4190ad3a3ec4196cb7bd50778e2984690a5cc (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
import { EditorContent } from '@tiptap/vue-2';
import { shallowMount } from '@vue/test-utils';
import ContentEditor from '~/content_editor/components/content_editor.vue';
import TopToolbar from '~/content_editor/components/top_toolbar.vue';
import { createContentEditor } from '~/content_editor/services/create_content_editor';

describe('ContentEditor', () => {
  let wrapper;
  let editor;

  const createWrapper = async (contentEditor) => {
    wrapper = shallowMount(ContentEditor, {
      propsData: {
        contentEditor,
      },
    });
  };

  beforeEach(() => {
    editor = createContentEditor({ renderMarkdown: () => true });
  });

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

  it('renders editor content component and attaches editor instance', () => {
    createWrapper(editor);

    const editorContent = wrapper.findComponent(EditorContent);

    expect(editorContent.props().editor).toBe(editor.tiptapEditor);
    expect(editorContent.classes()).toContain('md');
  });

  it('renders top toolbar component and attaches editor instance', () => {
    createWrapper(editor);

    expect(wrapper.findComponent(TopToolbar).props().contentEditor).toBe(editor);
  });

  it.each`
    isFocused | classes
    ${true}   | ${['md-area', 'is-focused']}
    ${false}  | ${['md-area']}
  `(
    'has $classes class selectors when tiptapEditor.isFocused = $isFocused',
    ({ isFocused, classes }) => {
      editor.tiptapEditor.isFocused = isFocused;
      createWrapper(editor);

      expect(wrapper.classes()).toStrictEqual(classes);
    },
  );

  it('adds isFocused class when tiptapEditor is focused', () => {
    editor.tiptapEditor.isFocused = true;
    createWrapper(editor);

    expect(wrapper.classes()).toContain('is-focused');
  });
});