summaryrefslogtreecommitdiff
path: root/spec/frontend/content_editor/extensions/table_of_contents_spec.js
blob: 83818899c177fa96d4ecb93106591a76ab66fbc4 (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
import TableOfContents from '~/content_editor/extensions/table_of_contents';
import { createTestEditor, createDocBuilder } from '../test_utils';

describe('content_editor/extensions/emoji', () => {
  let tiptapEditor;
  let builders;

  beforeEach(() => {
    tiptapEditor = createTestEditor({ extensions: [TableOfContents] });
    ({ builders } = createDocBuilder({
      tiptapEditor,
      names: { tableOfContents: { nodeType: TableOfContents.name } },
    }));
  });

  it.each`
    input          | insertedNode
    ${'[[_TOC_]]'} | ${'tableOfContents'}
    ${'[TOC]'}     | ${'tableOfContents'}
    ${'[toc]'}     | ${'p'}
    ${'TOC'}       | ${'p'}
    ${'[_TOC_]'}   | ${'p'}
    ${'[[TOC]]'}   | ${'p'}
  `('with input=$input, then should insert a $insertedNode', ({ input, insertedNode }) => {
    const { doc } = builders;
    const { view } = tiptapEditor;
    const { selection } = view.state;
    const expectedDoc = doc(builders[insertedNode]());

    // Triggers the event handler that input rules listen to
    view.someProp('handleTextInput', (f) => f(view, selection.from, selection.to, input));

    expect(tiptapEditor.getJSON()).toEqual(expectedDoc.toJSON());
  });
});