diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-24 00:10:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-24 00:10:28 +0300 |
commit | 4e7abe540dbd1d170bfb2b3594e645cbfb48cac3 (patch) | |
tree | f3de940e069b4d927acfdf54247c9900113a4c79 /spec/frontend/lib | |
parent | f6b95a66bc12adeb4fac7277d1eb345d9e7819fd (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/lib')
-rw-r--r-- | spec/frontend/lib/utils/text_markdown_spec.js | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/spec/frontend/lib/utils/text_markdown_spec.js b/spec/frontend/lib/utils/text_markdown_spec.js index 2180ea7e6c2..7ca9715430d 100644 --- a/spec/frontend/lib/utils/text_markdown_spec.js +++ b/spec/frontend/lib/utils/text_markdown_spec.js @@ -10,6 +10,7 @@ import { } from '~/lib/utils/text_markdown'; import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; import '~/lib/utils/jquery_at_who'; +import { ENTER_KEY } from '~/lib/utils/keys'; import axios from '~/lib/utils/axios_utils'; import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; @@ -208,7 +209,7 @@ describe('init markdown', () => { let enterEvent; beforeEach(() => { - enterEvent = new KeyboardEvent('keydown', { key: 'Enter', cancelable: true }); + enterEvent = new KeyboardEvent('keydown', { key: ENTER_KEY, cancelable: true }); textArea.addEventListener('keydown', keypressNoteText); textArea.addEventListener('compositionstart', compositionStartNoteText); textArea.addEventListener('compositionend', compositionEndNoteText); @@ -492,6 +493,53 @@ describe('init markdown', () => { }); }); + describe('adding a hard break using Shift+Enter', () => { + let enterEvent; + + beforeEach(() => { + enterEvent = new KeyboardEvent('keydown', { key: ENTER_KEY, shiftKey: true }); + textArea.addEventListener('keydown', keypressNoteText); + textArea.addEventListener('compositionstart', compositionStartNoteText); + textArea.addEventListener('compositionend', compositionEndNoteText); + }); + + it.each` + selectionStart | selectionEnd | expected | expectedSelectionStart + ${0} | ${0} | ${'\\\n0123456789'} | ${2} + ${3} | ${3} | ${'012\\\n3456789'} | ${5} + ${3} | ${6} | ${'012\\\n6789'} | ${5} + `( + 'adds a hard break', + ({ selectionStart, selectionEnd, expected, expectedSelectionStart }) => { + const text = '0123456789'; + textArea.value = text; + textArea.setSelectionRange(selectionStart, selectionEnd); + + textArea.dispatchEvent(enterEvent); + + expect(textArea.value).toEqual(expected); + expect(textArea.selectionStart).toEqual(expectedSelectionStart); + expect(textArea.selectionEnd).toEqual(expectedSelectionStart); + }, + ); + + it.each` + keyEvent + ${new KeyboardEvent('keydown', { key: ENTER_KEY, shiftKey: false })} + ${new KeyboardEvent('keydown', { key: ENTER_KEY, shiftKey: true, metaKey: true })} + ${new KeyboardEvent('keydown', { key: ENTER_KEY, shiftKey: true, altKey: true })} + ${new KeyboardEvent('keydown', { key: ENTER_KEY, shiftKey: true, ctrlKey: true })} + `('does not add when shift is pressed with other keys', ({ keyEvent }) => { + const text = '0123456789'; + textArea.value = text; + textArea.setSelectionRange(0, 0); + + textArea.dispatchEvent(keyEvent); + + expect(textArea.value).toEqual(text); + }); + }); + describe('with selection', () => { let text = 'initial selected value'; let selected = 'selected'; |