Welcome to mirror list, hosted at ThFree Co, Russian Federation.

code_spec.js « extensions « content_editor « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4d8629a35c08fe68083afafa2162a1632b952790 (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
import Bold from '~/content_editor/extensions/bold';
import Code from '~/content_editor/extensions/code';
import { createTestEditor, createDocBuilder } from '../test_utils';

describe('content_editor/extensions/code', () => {
  let tiptapEditor;
  let doc;
  let p;
  let bold;
  let code;

  beforeEach(() => {
    tiptapEditor = createTestEditor({ extensions: [Bold, Code] });

    ({
      builders: { doc, p, bold, code },
    } = createDocBuilder({
      tiptapEditor,
      names: {
        bold: { markType: Bold.name },
        code: { markType: Code.name },
      },
    }));
  });

  it.each`
    markOrder           | description
    ${['bold', 'code']} | ${'bold is toggled before code'}
    ${['code', 'bold']} | ${'code is toggled before bold'}
  `('has a lower loading priority, when $description', ({ markOrder }) => {
    const initialDoc = doc(p('code block'));
    const expectedDoc = doc(p(bold(code('code block'))));

    tiptapEditor.commands.setContent(initialDoc.toJSON());
    tiptapEditor.commands.selectAll();
    markOrder.forEach((mark) => tiptapEditor.commands.toggleMark(mark));

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

  describe('shortcut: RightArrow', () => {
    it('exits the code block', () => {
      const initialDoc = doc(p('You can write ', code('java')));
      const expectedDoc = doc(p('You can write ', code('javascript'), ' here'));
      const pos = 25;

      tiptapEditor.commands.setContent(initialDoc.toJSON());
      tiptapEditor.commands.setTextSelection(pos);

      // insert 'script' after 'java' within the code block
      tiptapEditor.commands.insertContent({ type: 'text', text: 'script' });

      // insert ' here' after the code block
      tiptapEditor.commands.keyboardShortcut('ArrowRight');
      tiptapEditor.commands.insertContent({ type: 'text', text: 'here' });

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