DEV: setTextareaSelection helper (#7609)

This commit is contained in:
Joffrey JAFFEUX 2019-05-27 16:33:27 +02:00 committed by GitHub
parent 42c82d544e
commit 669bfaba30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 9 deletions

View File

@ -5,7 +5,7 @@
"es6": true,
"jasmine": true,
"mocha": true,
"node": true,
"node": true
},
"parserOptions": {
"ecmaVersion": 7,
@ -57,6 +57,7 @@
"selectKitSelectRowByIndex": true,
"selectKitSelectRowByName": true,
"selectKitSelectRowByValue": true,
"setTextareaSelection": true,
"sinon": true,
"test": true,
"triggerEvent": true,
@ -99,7 +100,7 @@
"semi": 2,
"strict": 0,
"valid-typeof": 2,
"wrap-iife": [2, "inside"],
"wrap-iife": [2, "inside"]
},
"parser": "babel-eslint"
}

View File

@ -777,11 +777,6 @@ composerTestCase("replace-text event for composer", async function(assert) {
}
];
function setSelection(textarea, [start, len]) {
textarea.selectionStart = start;
textarea.selectionEnd = start + len;
}
function getSelection(textarea) {
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
@ -802,13 +797,14 @@ composerTestCase("replace-text event for composer", async function(assert) {
assert.ok(document.activeElement === textarea);
assert.ok(textarea.value === BEFORE);
setSelection(textarea, CASE.before);
const [start, len] = CASE.before;
setTextareaSelection(textarea, start, start + len);
assert.ok(document.activeElement === textarea);
this.container
.lookup("app-events:main")
.trigger("composer:replace-text", "green", "yellow", {forceFocus: true});
.trigger("composer:replace-text", "green", "yellow", { forceFocus: true });
assert.ok(document.activeElement === textarea);

View File

@ -0,0 +1,9 @@
Ember.Test.registerHelper("setTextareaSelection", function(
app,
textarea,
selectionStart,
selectionEnd
) {
textarea.selectionStart = selectionStart;
textarea.selectionEnd = selectionEnd;
});

View File

@ -30,6 +30,7 @@
//= require sinon/pkg/sinon
//= require helpers/assertions
//= require helpers/set-textarea-selection
//= require helpers/select-kit-helper
//= require helpers/d-editor-helper