diff options
| author | Jan Christophersen <jan@ruken.pw> | 2017-02-22 20:58:24 +0100 |
|---|---|---|
| committer | Jan Christophersen <jan@ruken.pw> | 2017-03-02 19:22:29 +0100 |
| commit | 7abdc24c7e3bd07f2f22bee521750b353402f4e9 (patch) | |
| tree | ee794cf65d2a7fb087f135e9e7026330559c911f /spec/javascripts/lib/utils/text_utility_spec.js.es6 | |
| parent | 3b3f0fab452fb9cbe4fbe7f75112bef3a7f9d039 (diff) | |
| download | gitlab-ce-7abdc24c7e3bd07f2f22bee521750b353402f4e9.tar.gz | |
Only add a newline in Markdown Editor if the current line is not empty
Diffstat (limited to 'spec/javascripts/lib/utils/text_utility_spec.js.es6')
| -rw-r--r-- | spec/javascripts/lib/utils/text_utility_spec.js.es6 | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/javascripts/lib/utils/text_utility_spec.js.es6 b/spec/javascripts/lib/utils/text_utility_spec.js.es6 index 06b69b8ac17..4200e943121 100644 --- a/spec/javascripts/lib/utils/text_utility_spec.js.es6 +++ b/spec/javascripts/lib/utils/text_utility_spec.js.es6 @@ -46,5 +46,65 @@ require('~/lib/utils/text_utility'); expect(gl.text.highCountTrim(45)).toBe(45); }); }); + + describe('gl.text.insertText', () => { + let textArea; + + beforeAll(() => { + textArea = document.createElement('textarea'); + document.querySelector('body').appendChild(textArea); + }); + + afterAll(() => { + textArea.parentNode.removeChild(textArea); + }); + + describe('without selection', () => { + it('inserts the tag on an empty line', () => { + const initialValue = ''; + + textArea.value = initialValue; + textArea.selectionStart = 0; + textArea.selectionEnd = 0; + + gl.text.insertText(textArea, textArea.value, '*', null, '', false); + + expect(textArea.value).toEqual(`${initialValue}* `); + }); + + it('inserts the tag on a new line if the current one is not empty', () => { + const initialValue = 'some text'; + + textArea.value = initialValue; + textArea.setSelectionRange(initialValue.length, initialValue.length); + + gl.text.insertText(textArea, textArea.value, '*', null, '', false); + + expect(textArea.value).toEqual(`${initialValue}\n* `); + }); + + it('inserts the tag on the same line if the current line only contains spaces', () => { + const initialValue = ' '; + + textArea.value = initialValue; + textArea.setSelectionRange(initialValue.length, initialValue.length); + + gl.text.insertText(textArea, textArea.value, '*', null, '', false); + + expect(textArea.value).toEqual(`${initialValue}* `); + }); + + it('inserts the tag on the same line if the current line only contains tabs', () => { + const initialValue = '\t\t\t'; + + textArea.value = initialValue; + textArea.setSelectionRange(initialValue.length, initialValue.length); + + gl.text.insertText(textArea, textArea.value, '*', null, '', false); + + expect(textArea.value).toEqual(`${initialValue}* `); + }); + }); + }); }); })(); |
