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 | |
parent | d5e68dfae835516bcc94d208cd7be461e75831ff (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/commit/pipelines/pipelines_table_spec.js | 4 | ||||
-rw-r--r-- | spec/frontend/content_editor/extensions/hard_break_spec.js | 46 | ||||
-rw-r--r-- | spec/frontend/content_editor/test_utils.js | 10 | ||||
-rw-r--r-- | spec/frontend/editor/source_editor_spec.js | 2 | ||||
-rw-r--r-- | spec/frontend/environment.js | 18 |
5 files changed, 77 insertions, 3 deletions
diff --git a/spec/frontend/commit/pipelines/pipelines_table_spec.js b/spec/frontend/commit/pipelines/pipelines_table_spec.js index 4bf6727af3b..1defb3d586c 100644 --- a/spec/frontend/commit/pipelines/pipelines_table_spec.js +++ b/spec/frontend/commit/pipelines/pipelines_table_spec.js @@ -66,7 +66,7 @@ describe('Pipelines table in Commits and Merge requests', () => { describe('with pipelines', () => { beforeEach(async () => { - mock.onGet('endpoint.json').reply(200, [pipeline]); + mock.onGet('endpoint.json').reply(200, [pipeline], { 'x-total': 10 }); createComponent(); @@ -110,7 +110,7 @@ describe('Pipelines table in Commits and Merge requests', () => { document.body.appendChild(element); element.addEventListener('update-pipelines-count', (event) => { - expect(event.detail.pipelines).toEqual([pipeline]); + expect(event.detail.pipelineCount).toEqual(10); done(); }); 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 diff --git a/spec/frontend/editor/source_editor_spec.js b/spec/frontend/editor/source_editor_spec.js index cf3e2c025e4..d87d373c952 100644 --- a/spec/frontend/editor/source_editor_spec.js +++ b/spec/frontend/editor/source_editor_spec.js @@ -246,7 +246,7 @@ describe('Base editor', () => { let editorEl2; let inst1; let inst2; - const readOnlyIndex = '68'; // readOnly option has the internal index of 68 in the editor's options + const readOnlyIndex = '78'; // readOnly option has the internal index of 78 in the editor's options beforeEach(() => { setFixtures('<div id="editor1"></div><div id="editor2"></div>'); diff --git a/spec/frontend/environment.js b/spec/frontend/environment.js index d1bc11538a3..9cebe2d1e01 100644 --- a/spec/frontend/environment.js +++ b/spec/frontend/environment.js @@ -67,6 +67,24 @@ class CustomEnvironment extends JSDOMEnvironment { getEntriesByName: () => [], }); + // + // Monaco-related environment variables + // + this.global.MonacoEnvironment = { globalAPI: true }; + Object.defineProperty(this.global, 'matchMedia', { + writable: true, + value: (query) => ({ + matches: false, + media: query, + onchange: null, + addListener: () => null, // deprecated + removeListener: () => null, // deprecated + addEventListener: () => null, + removeEventListener: () => null, + dispatchEvent: () => null, + }), + }); + this.global.PerformanceObserver = class { /* eslint-disable no-useless-constructor, no-unused-vars, no-empty-function, class-methods-use-this */ constructor(callback) {} |