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

details_content_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: 575f3bf65e4ccc501ff6b64ee155a996d19f9a9e (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import Details from '~/content_editor/extensions/details';
import DetailsContent from '~/content_editor/extensions/details_content';
import { createTestEditor, createDocBuilder } from '../test_utils';

describe('content_editor/extensions/details_content', () => {
  let tiptapEditor;
  let doc;
  let p;
  let details;
  let detailsContent;

  beforeEach(() => {
    tiptapEditor = createTestEditor({ extensions: [Details, DetailsContent] });

    ({
      builders: { doc, p, details, detailsContent },
    } = createDocBuilder({
      tiptapEditor,
      names: {
        details: { nodeType: Details.name },
        detailsContent: { nodeType: DetailsContent.name },
      },
    }));
  });

  describe('shortcut: Enter', () => {
    it('splits a details content into two items', () => {
      const initialDoc = doc(
        details(
          detailsContent(p('Summary')),
          detailsContent(p('Text content')),
          detailsContent(p('Text content')),
        ),
      );
      const expectedDoc = doc(
        details(
          detailsContent(p('Summary')),
          detailsContent(p('')),
          detailsContent(p('Text content')),
          detailsContent(p('Text content')),
        ),
      );

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

      tiptapEditor.commands.setTextSelection(10);
      tiptapEditor.commands.keyboardShortcut('Enter');

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

  describe('shortcut: Shift-Tab', () => {
    it('lifts a details content and creates two separate details items', () => {
      const initialDoc = doc(
        details(
          detailsContent(p('Summary')),
          detailsContent(p('Text content')),
          detailsContent(p('Text content')),
        ),
      );
      const expectedDoc = doc(
        details(detailsContent(p('Summary'))),
        p('Text content'),
        details(detailsContent(p('Text content'))),
      );

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

      tiptapEditor.commands.setTextSelection(20);
      tiptapEditor.commands.keyboardShortcut('Shift-Tab');

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