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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-09-23 21:12:59 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-09-23 21:12:59 +0300
commit3acaaf7231d0779a6ceb37fca693cd81e698ef90 (patch)
tree22a068ab03faa19008997f5bc10298282ad077ab /spec/frontend/lib
parent2cba761741967eb6baf797af2ee0a702c2ffbdfe (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.js38
1 files changed, 22 insertions, 16 deletions
diff --git a/spec/frontend/lib/utils/text_markdown_spec.js b/spec/frontend/lib/utils/text_markdown_spec.js
index 8d179baa505..ba3c73d662d 100644
--- a/spec/frontend/lib/utils/text_markdown_spec.js
+++ b/spec/frontend/lib/utils/text_markdown_spec.js
@@ -4,15 +4,30 @@ import {
keypressNoteText,
compositionStartNoteText,
compositionEndNoteText,
+ updateTextForToolbarBtn,
} from '~/lib/utils/text_markdown';
import '~/lib/utils/jquery_at_who';
+import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
describe('init markdown', () => {
+ let mdArea;
let textArea;
+ let indentButton;
+ let outdentButton;
beforeAll(() => {
- textArea = document.createElement('textarea');
- document.querySelector('body').appendChild(textArea);
+ setHTMLFixture(
+ `<div class='md-area'>
+ <textarea></textarea>
+ <button data-md-command="indentLines" id="indentButton"></button>
+ <button data-md-command="outdentLines" id="outdentButton"></button>
+ </div>`,
+ );
+ mdArea = document.querySelector('.md-area');
+ textArea = mdArea.querySelector('textarea');
+ indentButton = mdArea.querySelector('#indentButton');
+ outdentButton = mdArea.querySelector('#outdentButton');
+
textArea.focus();
// needed for the underlying insertText to work
@@ -20,7 +35,7 @@ describe('init markdown', () => {
});
afterAll(() => {
- textArea.parentNode.removeChild(textArea);
+ resetHTMLFixture();
});
describe('insertMarkdownText', () => {
@@ -306,15 +321,6 @@ describe('init markdown', () => {
});
describe('shifting selected lines left or right', () => {
- const indentEvent = new KeyboardEvent('keydown', { key: ']', metaKey: true });
- const outdentEvent = new KeyboardEvent('keydown', { key: '[', metaKey: true });
-
- beforeEach(() => {
- textArea.addEventListener('keydown', keypressNoteText);
- textArea.addEventListener('compositionstart', compositionStartNoteText);
- textArea.addEventListener('compositionend', compositionEndNoteText);
- });
-
it.each`
selectionStart | selectionEnd | expected | expectedSelectionStart | expectedSelectionEnd
${0} | ${0} | ${' 012\n456\n89'} | ${2} | ${2}
@@ -338,7 +344,7 @@ describe('init markdown', () => {
textArea.value = text;
textArea.setSelectionRange(selectionStart, selectionEnd);
- textArea.dispatchEvent(indentEvent);
+ updateTextForToolbarBtn($(indentButton));
expect(textArea.value).toEqual(expected);
expect(textArea.selectionStart).toEqual(expectedSelectionStart);
@@ -350,7 +356,7 @@ describe('init markdown', () => {
textArea.value = '012\n\n89';
textArea.setSelectionRange(4, 4);
- textArea.dispatchEvent(indentEvent);
+ updateTextForToolbarBtn($(indentButton));
expect(textArea.value).toEqual('012\n \n89');
expect(textArea.selectionStart).toEqual(6);
@@ -381,7 +387,7 @@ describe('init markdown', () => {
textArea.value = text;
textArea.setSelectionRange(selectionStart, selectionEnd);
- textArea.dispatchEvent(outdentEvent);
+ updateTextForToolbarBtn($(outdentButton));
expect(textArea.value).toEqual(expected);
expect(textArea.selectionStart).toEqual(expectedSelectionStart);
@@ -393,7 +399,7 @@ describe('init markdown', () => {
textArea.value = '012\n\n89';
textArea.setSelectionRange(4, 4);
- textArea.dispatchEvent(outdentEvent);
+ updateTextForToolbarBtn($(outdentButton));
expect(textArea.value).toEqual('012\n\n89');
expect(textArea.selectionStart).toEqual(4);