DEV: d-editor helper should be synchronous (#7706)
Also ensures trigger has happened before assertion and prevents leaking formatTextWithSelection into global context
This commit is contained in:
parent
a77d8bee68
commit
df95457468
|
@ -1,5 +1,6 @@
|
||||||
import componentTest from "helpers/component-test";
|
import componentTest from "helpers/component-test";
|
||||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||||
|
import formatTextWithSelection from "helpers/d-editor-helper";
|
||||||
|
|
||||||
moduleForComponent("d-editor", { integration: true });
|
moduleForComponent("d-editor", { integration: true });
|
||||||
|
|
||||||
|
@ -797,12 +798,14 @@ composerTestCase("replace-text event for composer", async function(assert) {
|
||||||
.lookup("app-events:main")
|
.lookup("app-events:main")
|
||||||
.trigger("composer:replace-text", "green", "yellow", { forceFocus: true });
|
.trigger("composer:replace-text", "green", "yellow", { forceFocus: true });
|
||||||
|
|
||||||
let expect = await formatTextWithSelection(AFTER, CASE.after); // eslint-disable-line no-undef
|
Ember.run.next(() => {
|
||||||
let actual = await formatTextWithSelection( // eslint-disable-line no-undef
|
let expect = formatTextWithSelection(AFTER, CASE.after);
|
||||||
|
let actual = formatTextWithSelection(
|
||||||
this.value,
|
this.value,
|
||||||
getTextareaSelection(textarea)
|
getTextareaSelection(textarea)
|
||||||
);
|
);
|
||||||
assert.equal(actual, expect);
|
assert.equal(actual, expect);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
Ember.Test.registerAsyncHelper("formatTextWithSelection", function(
|
export default function formatTextWithSelection(text, [start, len]) {
|
||||||
app,
|
|
||||||
text,
|
|
||||||
[start, len]
|
|
||||||
) {
|
|
||||||
return [
|
return [
|
||||||
'"',
|
'"',
|
||||||
text.substr(0, start),
|
text.substr(0, start),
|
||||||
|
@ -12,4 +8,4 @@ Ember.Test.registerAsyncHelper("formatTextWithSelection", function(
|
||||||
text.substr(start + len),
|
text.substr(start + len),
|
||||||
'"'
|
'"'
|
||||||
].join("");
|
].join("");
|
||||||
});
|
}
|
|
@ -32,7 +32,6 @@
|
||||||
//= require helpers/assertions
|
//= require helpers/assertions
|
||||||
//= require helpers/textarea-selection
|
//= require helpers/textarea-selection
|
||||||
//= require helpers/select-kit-helper
|
//= require helpers/select-kit-helper
|
||||||
//= require helpers/d-editor-helper
|
|
||||||
|
|
||||||
//= require helpers/qunit-helpers
|
//= require helpers/qunit-helpers
|
||||||
//= require_tree ./fixtures
|
//= require_tree ./fixtures
|
||||||
|
|
Loading…
Reference in New Issue