mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 02:40:53 -06:00
DEV: attempts to make d-editor tests more resilient (#7556)
This commit is contained in:
parent
244c03573a
commit
ad4d01233b
@ -675,7 +675,7 @@ export default Ember.Component.extend({
|
||||
}
|
||||
},
|
||||
|
||||
_replaceText(oldVal, newVal, opts) {
|
||||
_replaceText(oldVal, newVal, opts = {}) {
|
||||
const val = this.get("value");
|
||||
const needleStart = val.indexOf(oldVal);
|
||||
|
||||
@ -693,7 +693,7 @@ export default Ember.Component.extend({
|
||||
replacement: { start: needleStart, end: needleStart + newVal.length }
|
||||
});
|
||||
|
||||
if (opts && opts.index && opts.regex) {
|
||||
if (opts.index && opts.regex) {
|
||||
let i = -1;
|
||||
const newValue = val.replace(opts.regex, match => {
|
||||
i++;
|
||||
@ -705,7 +705,7 @@ export default Ember.Component.extend({
|
||||
this.set("value", val.replace(oldVal, newVal));
|
||||
}
|
||||
|
||||
if ($("textarea.d-editor-input").is(":focus")) {
|
||||
if (opts.forceFocus || $("textarea.d-editor-input").is(":focus")) {
|
||||
// Restore cursor.
|
||||
this._selectText(
|
||||
newSelection.start,
|
||||
|
@ -761,13 +761,12 @@ composerTestCase("replace-text event for composer", async function(assert) {
|
||||
before: [BEFORE.length, 0],
|
||||
after: [AFTER.length, 0]
|
||||
},
|
||||
// Flaky test. Marked as pending
|
||||
//{
|
||||
// description:
|
||||
// "selection spanning needle start becomes selection until replacement start",
|
||||
// before: [BEFORE.indexOf(NEEDLE) - 1, 2],
|
||||
// after: [AFTER.indexOf(REPLACE) - 1, 1]
|
||||
//},
|
||||
{
|
||||
description:
|
||||
"selection spanning needle start becomes selection until replacement start",
|
||||
before: [BEFORE.indexOf(NEEDLE) - 1, 2],
|
||||
after: [AFTER.indexOf(REPLACE) - 1, 1]
|
||||
},
|
||||
{
|
||||
description:
|
||||
"selection spanning needle end becomes selection from replacement end",
|
||||
@ -805,16 +804,22 @@ composerTestCase("replace-text event for composer", async function(assert) {
|
||||
assert,
|
||||
textarea
|
||||
) {
|
||||
const focusEvent = $.Event("focus");
|
||||
const $input = $('textarea.d-editor-input');
|
||||
$input.trigger(focusEvent);
|
||||
|
||||
this.set("value", BEFORE);
|
||||
await setSelection(textarea, CASE.before);
|
||||
|
||||
textarea.focus();
|
||||
|
||||
assert.ok(document.activeElement === textarea);
|
||||
assert.ok(textarea.value === BEFORE);
|
||||
|
||||
setSelection(textarea, CASE.before);
|
||||
|
||||
assert.ok(document.activeElement === textarea);
|
||||
|
||||
this.container
|
||||
.lookup("app-events:main")
|
||||
.trigger("composer:replace-text", "green", "yellow");
|
||||
.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
|
||||
|
Loading…
Reference in New Issue
Block a user