diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-06 18:08:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-06 18:08:14 +0300 |
commit | b72b14cb4d1567c555d9e5cb336111afd479ee9e (patch) | |
tree | 7cc3087bae34b9dd9ce2339658d299cb4dae0ed9 /spec/frontend/content_editor | |
parent | d5e68dfae835516bcc94d208cd7be461e75831ff (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/content_editor')
-rw-r--r-- | spec/frontend/content_editor/extensions/hard_break_spec.js | 46 | ||||
-rw-r--r-- | spec/frontend/content_editor/test_utils.js | 10 |
2 files changed, 56 insertions, 0 deletions
diff --git a/spec/frontend/content_editor/extensions/hard_break_spec.js b/spec/frontend/content_editor/extensions/hard_break_spec.js new file mode 100644 index 00000000000..ebd58e60b0c --- /dev/null +++ b/spec/frontend/content_editor/extensions/hard_break_spec.js @@ -0,0 +1,46 @@ +import { tiptapExtension as HardBreak } from '~/content_editor/extensions/hard_break'; +import { createTestEditor, createDocBuilder } from '../test_utils'; + +describe('content_editor/extensions/hard_break', () => { + let tiptapEditor; + let eq; + let doc; + let p; + let hardBreak; + + beforeEach(() => { + tiptapEditor = createTestEditor({ extensions: [HardBreak] }); + + ({ + builders: { doc, p, hardBreak }, + eq, + } = createDocBuilder({ + tiptapEditor, + names: { hardBreak: { nodeType: HardBreak.name } }, + })); + }); + + describe('Shift-Enter shortcut', () => { + it('inserts a hard break when shortcut is executed', () => { + const initialDoc = doc(p('')); + const expectedDoc = doc(p(hardBreak())); + + tiptapEditor.commands.setContent(initialDoc.toJSON()); + tiptapEditor.commands.keyboardShortcut('Shift-Enter'); + + expect(eq(tiptapEditor.state.doc, expectedDoc)).toBe(true); + }); + }); + + describe('Mod-Enter shortcut', () => { + it('does not insert a hard break when shortcut is executed', () => { + const initialDoc = doc(p('')); + const expectedDoc = initialDoc; + + tiptapEditor.commands.setContent(initialDoc.toJSON()); + tiptapEditor.commands.keyboardShortcut('Mod-Enter'); + + expect(eq(tiptapEditor.state.doc, expectedDoc)).toBe(true); + }); + }); +}); diff --git a/spec/frontend/content_editor/test_utils.js b/spec/frontend/content_editor/test_utils.js index e4f2754f4c0..090e1d92218 100644 --- a/spec/frontend/content_editor/test_utils.js +++ b/spec/frontend/content_editor/test_utils.js @@ -3,6 +3,16 @@ import { Document } from '@tiptap/extension-document'; import { Paragraph } from '@tiptap/extension-paragraph'; import { Text } from '@tiptap/extension-text'; import { Editor } from '@tiptap/vue-2'; +import { builders, eq } from 'prosemirror-test-builder'; + +export const createDocBuilder = ({ tiptapEditor, names = {} }) => { + const docBuilders = builders(tiptapEditor.schema, { + p: { nodeType: 'paragraph' }, + ...names, + }); + + return { eq, builders: docBuilders }; +}; /** * Creates an instance of the Tiptap Editor class |