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
5 changed files with 14 additions and 15 deletions

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);
});