DEV: uses focus helper for d-editor tests (#7610)

This commit is contained in:
Joffrey JAFFEUX 2019-05-27 17:31:11 +02:00 committed by GitHub
parent 669bfaba30
commit 192562745f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 15 deletions

View File

@ -20,6 +20,8 @@
"Blob": true,
"bootbox": true,
"click": true,
"waitUntil": true,
"getSettledState": true,
"collapseSelectKit": true,
"controllerFor": true,
"count": true,
@ -58,6 +60,7 @@
"selectKitSelectRowByName": true,
"selectKitSelectRowByValue": true,
"setTextareaSelection": true,
"getTextareaSelection": true,
"sinon": true,
"test": true,
"triggerEvent": true,

View File

@ -544,7 +544,8 @@ export default Ember.Component.extend({
$textarea.focus();
}
textarea.selectionStart = from;
textarea.selectionEnd = textarea.selectionStart + length;
textarea.selectionEnd = from + length;
$textarea.scrollTop(oldScrollPos);
});
},

View File

@ -777,12 +777,6 @@ composerTestCase("replace-text event for composer", async function(assert) {
}
];
function getSelection(textarea) {
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
return [start, end - start];
}
for (let i = 0; i < CASES.length; i++) {
const CASE = CASES[i];
// prettier-ignore
@ -792,26 +786,21 @@ composerTestCase("replace-text event for composer", async function(assert) {
) {
this.set("value", BEFORE);
await click(textarea);
await focus(textarea);
assert.ok(document.activeElement === textarea);
assert.ok(textarea.value === 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 });
assert.ok(document.activeElement === textarea);
let expect = await formatTextWithSelection(AFTER, CASE.after); // eslint-disable-line no-undef
let actual = await formatTextWithSelection( // eslint-disable-line no-undef
this.value,
getSelection(textarea)
getTextareaSelection(textarea)
);
assert.equal(actual, expect);
});

View File

@ -7,3 +7,9 @@ Ember.Test.registerHelper("setTextareaSelection", function(
textarea.selectionStart = selectionStart;
textarea.selectionEnd = selectionEnd;
});
Ember.Test.registerHelper("getTextareaSelection", function(app, textarea) {
var start = textarea.selectionStart;
var end = textarea.selectionEnd;
return [start, end - start];
});

View File

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