diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/frontend/lib/utils/text_markdown_spec.js | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/frontend/lib/utils/text_markdown_spec.js')
-rw-r--r-- | spec/frontend/lib/utils/text_markdown_spec.js | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/spec/frontend/lib/utils/text_markdown_spec.js b/spec/frontend/lib/utils/text_markdown_spec.js index 103305f0797..d1bca3c73b6 100644 --- a/spec/frontend/lib/utils/text_markdown_spec.js +++ b/spec/frontend/lib/utils/text_markdown_spec.js @@ -1,5 +1,10 @@ import $ from 'jquery'; -import { insertMarkdownText, keypressNoteText } from '~/lib/utils/text_markdown'; +import { + insertMarkdownText, + keypressNoteText, + compositionStartNoteText, + compositionEndNoteText, +} from '~/lib/utils/text_markdown'; import '~/lib/utils/jquery_at_who'; describe('init markdown', () => { @@ -9,6 +14,9 @@ describe('init markdown', () => { textArea = document.createElement('textarea'); document.querySelector('body').appendChild(textArea); textArea.focus(); + + // needed for the underlying insertText to work + document.execCommand = jest.fn(() => false); }); afterAll(() => { @@ -172,7 +180,9 @@ describe('init markdown', () => { const enterEvent = new KeyboardEvent('keydown', { key: 'Enter' }); beforeEach(() => { - gon.features = { markdownContinueLists: true }; + textArea.addEventListener('keydown', keypressNoteText); + textArea.addEventListener('compositionstart', compositionStartNoteText); + textArea.addEventListener('compositionend', compositionEndNoteText); }); it.each` @@ -203,7 +213,6 @@ describe('init markdown', () => { textArea.value = text; textArea.setSelectionRange(text.length, text.length); - textArea.addEventListener('keydown', keypressNoteText); textArea.dispatchEvent(enterEvent); expect(textArea.value).toEqual(expected); @@ -231,7 +240,6 @@ describe('init markdown', () => { textArea.value = text; textArea.setSelectionRange(text.length, text.length); - textArea.addEventListener('keydown', keypressNoteText); textArea.dispatchEvent(enterEvent); expect(textArea.value.substr(0, textArea.selectionStart)).toEqual(expected); @@ -251,7 +259,6 @@ describe('init markdown', () => { textArea.value = text; textArea.setSelectionRange(text.length, text.length); - textArea.addEventListener('keydown', keypressNoteText); textArea.dispatchEvent(enterEvent); expect(textArea.value).toEqual(expected); @@ -267,23 +274,25 @@ describe('init markdown', () => { textArea.value = text; textArea.setSelectionRange(add_at, add_at); - textArea.addEventListener('keydown', keypressNoteText); textArea.dispatchEvent(enterEvent); expect(textArea.value).toEqual(expected); }, ); - it('does nothing if feature flag disabled', () => { - gon.features = { markdownContinueLists: false }; - - const text = '- item'; - const expected = '- item'; + it('does not duplicate a line item for IME characters', () => { + const text = '- 日本語'; + const expected = '- 日本語\n- '; + textArea.dispatchEvent(new CompositionEvent('compositionstart')); textArea.value = text; + + // Press enter to end composition + textArea.dispatchEvent(enterEvent); + textArea.dispatchEvent(new CompositionEvent('compositionend')); textArea.setSelectionRange(text.length, text.length); - textArea.addEventListener('keydown', keypressNoteText); + // Press enter to make new line textArea.dispatchEvent(enterEvent); expect(textArea.value).toEqual(expected); |