mirror of
https://github.com/discourse/discourse.git
synced 2025-03-06 03:09:43 +00:00
DEV: Make settled()
work in the legacy env (#16122)
(and await for `focusComposer`)
This commit is contained in:
parent
af20d435ea
commit
c528de3288
@ -412,7 +412,7 @@ export default Controller.extend({
|
||||
// true or topic is provided
|
||||
@action
|
||||
focusComposer(opts = {}) {
|
||||
this._openComposerForFocus(opts).then(() => {
|
||||
return this._openComposerForFocus(opts).then(() => {
|
||||
this._focusAndInsertText(opts.insertText);
|
||||
});
|
||||
},
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { run } from "@ember/runloop";
|
||||
import { click, currentURL, fillIn, settled, visit } from "@ember/test-helpers";
|
||||
import { toggleCheckDraftPopup } from "discourse/controllers/composer";
|
||||
import LinkLookup from "discourse/lib/link-lookup";
|
||||
@ -20,7 +19,7 @@ import {
|
||||
} from "discourse/tests/helpers/qunit-helpers";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
import I18n from "I18n";
|
||||
import { skip, test } from "qunit";
|
||||
import { test } from "qunit";
|
||||
import { Promise } from "rsvp";
|
||||
import sinon from "sinon";
|
||||
|
||||
@ -46,7 +45,7 @@ acceptance("Composer", function (needs) {
|
||||
});
|
||||
});
|
||||
|
||||
test("Tests the Composer controls", async function (assert) {
|
||||
test("composer controls", async function (assert) {
|
||||
await visit("/");
|
||||
assert.ok(exists("#create-topic"), "the create button is visible");
|
||||
|
||||
@ -109,7 +108,8 @@ acceptance("Composer", function (needs) {
|
||||
event.key = "B";
|
||||
event.keyCode = 66;
|
||||
|
||||
run(() => textarea.dispatchEvent(event));
|
||||
textarea.dispatchEvent(event);
|
||||
await settled();
|
||||
|
||||
const example = I18n.t(`composer.bold_text`);
|
||||
assert.strictEqual(
|
||||
@ -922,16 +922,14 @@ acceptance("Composer - Customizations", function (needs) {
|
||||
});
|
||||
});
|
||||
|
||||
// all of these are broken on legacy ember qunit for...some reason. commenting
|
||||
// until we are fully on ember cli.
|
||||
acceptance("Composer - Focus Open and Closed", function (needs) {
|
||||
needs.user();
|
||||
|
||||
skip("Focusing a composer which is not open with create topic", async function (assert) {
|
||||
test("Focusing a composer which is not open with create topic", async function (assert) {
|
||||
await visit("/t/internationalization-localization/280");
|
||||
|
||||
const composer = this.container.lookup("controller:composer");
|
||||
composer.focusComposer({ fallbackToNewTopic: true });
|
||||
await composer.focusComposer({ fallbackToNewTopic: true });
|
||||
|
||||
await settled();
|
||||
assert.strictEqual(
|
||||
@ -942,11 +940,11 @@ acceptance("Composer - Focus Open and Closed", function (needs) {
|
||||
assert.strictEqual(composer.model.action, Composer.CREATE_TOPIC);
|
||||
});
|
||||
|
||||
skip("Focusing a composer which is not open with create topic and append text", async function (assert) {
|
||||
test("Focusing a composer which is not open with create topic and append text", async function (assert) {
|
||||
await visit("/t/internationalization-localization/280");
|
||||
|
||||
const composer = this.container.lookup("controller:composer");
|
||||
composer.focusComposer({
|
||||
await composer.focusComposer({
|
||||
fallbackToNewTopic: true,
|
||||
insertText: "this is appended",
|
||||
});
|
||||
@ -963,12 +961,12 @@ acceptance("Composer - Focus Open and Closed", function (needs) {
|
||||
);
|
||||
});
|
||||
|
||||
skip("Focusing a composer which is already open", async function (assert) {
|
||||
test("Focusing a composer which is already open", async function (assert) {
|
||||
await visit("/");
|
||||
await click("#create-topic");
|
||||
|
||||
const composer = this.container.lookup("controller:composer");
|
||||
composer.focusComposer();
|
||||
await composer.focusComposer();
|
||||
|
||||
await settled();
|
||||
assert.strictEqual(
|
||||
@ -978,12 +976,12 @@ acceptance("Composer - Focus Open and Closed", function (needs) {
|
||||
);
|
||||
});
|
||||
|
||||
skip("Focusing a composer which is already open and append text", async function (assert) {
|
||||
test("Focusing a composer which is already open and append text", async function (assert) {
|
||||
await visit("/");
|
||||
await click("#create-topic");
|
||||
|
||||
const composer = this.container.lookup("controller:composer");
|
||||
composer.focusComposer({ insertText: "this is some appended text" });
|
||||
await composer.focusComposer({ insertText: "this is some appended text" });
|
||||
|
||||
await settled();
|
||||
assert.strictEqual(
|
||||
@ -997,7 +995,7 @@ acceptance("Composer - Focus Open and Closed", function (needs) {
|
||||
);
|
||||
});
|
||||
|
||||
skip("Focusing a composer which is not open that has a draft", async function (assert) {
|
||||
test("Focusing a composer which is not open that has a draft", async function (assert) {
|
||||
await visit("/t/this-is-a-test-topic/9");
|
||||
|
||||
await click(".topic-post:nth-of-type(1) button.edit");
|
||||
@ -1005,7 +1003,7 @@ acceptance("Composer - Focus Open and Closed", function (needs) {
|
||||
await click(".toggle-minimize");
|
||||
|
||||
const composer = this.container.lookup("controller:composer");
|
||||
composer.focusComposer({ insertText: "this is some appended text" });
|
||||
await composer.focusComposer({ insertText: "this is some appended text" });
|
||||
|
||||
await settled();
|
||||
assert.strictEqual(
|
||||
|
@ -4,11 +4,10 @@ import {
|
||||
exists,
|
||||
query,
|
||||
} from "discourse/tests/helpers/qunit-helpers";
|
||||
import { click, fillIn, visit } from "@ember/test-helpers";
|
||||
import { click, fillIn, settled, visit } from "@ember/test-helpers";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
import { test } from "qunit";
|
||||
import userFixtures from "discourse/tests/fixtures/user-fixtures";
|
||||
import { run } from "@ember/runloop";
|
||||
|
||||
async function openFlagModal() {
|
||||
if (exists(".topic-post:first-child button.show-more-actions")) {
|
||||
@ -17,13 +16,14 @@ async function openFlagModal() {
|
||||
await click(".topic-post:first-child button.create-flag");
|
||||
}
|
||||
|
||||
function pressEnter(element, modifier) {
|
||||
async function pressEnter(element, modifier) {
|
||||
const event = document.createEvent("Event");
|
||||
event.initEvent("keydown", true, true);
|
||||
event.key = "Enter";
|
||||
event.keyCode = 13;
|
||||
event[modifier] = true;
|
||||
run(() => element.dispatchEvent(event));
|
||||
element.dispatchEvent(event);
|
||||
await settled();
|
||||
}
|
||||
|
||||
acceptance("flagging", function (needs) {
|
||||
@ -158,14 +158,14 @@ acceptance("flagging", function (needs) {
|
||||
await openFlagModal();
|
||||
|
||||
const modal = query("#discourse-modal");
|
||||
pressEnter(modal, "ctrlKey");
|
||||
await pressEnter(modal, "ctrlKey");
|
||||
assert.ok(
|
||||
exists("#discourse-modal:visible"),
|
||||
"The modal wasn't closed because the accept button was disabled"
|
||||
);
|
||||
|
||||
await click("#radio_inappropriate"); // this enables the accept button
|
||||
pressEnter(modal, "ctrlKey");
|
||||
await pressEnter(modal, "ctrlKey");
|
||||
assert.ok(!exists("#discourse-modal:visible"), "The modal was closed");
|
||||
});
|
||||
|
||||
@ -174,14 +174,14 @@ acceptance("flagging", function (needs) {
|
||||
await openFlagModal();
|
||||
|
||||
const modal = query("#discourse-modal");
|
||||
pressEnter(modal, "metaKey");
|
||||
await pressEnter(modal, "metaKey");
|
||||
assert.ok(
|
||||
exists("#discourse-modal:visible"),
|
||||
"The modal wasn't closed because the accept button was disabled"
|
||||
);
|
||||
|
||||
await click("#radio_inappropriate"); // this enables the accept button
|
||||
pressEnter(modal, "ctrlKey");
|
||||
await pressEnter(modal, "ctrlKey");
|
||||
assert.ok(!exists("#discourse-modal:visible"), "The modal was closed");
|
||||
});
|
||||
});
|
||||
|
@ -5,11 +5,10 @@ import {
|
||||
exists,
|
||||
queryAll,
|
||||
} from "discourse/tests/helpers/qunit-helpers";
|
||||
import { click, triggerKeyEvent, visit } from "@ember/test-helpers";
|
||||
import { click, settled, triggerKeyEvent, visit } from "@ember/test-helpers";
|
||||
import { test } from "qunit";
|
||||
import I18n from "I18n";
|
||||
import hbs from "htmlbars-inline-precompile";
|
||||
import { run } from "@ember/runloop";
|
||||
import showModal from "discourse/lib/show-modal";
|
||||
|
||||
acceptance("Modal", function (needs) {
|
||||
@ -58,7 +57,8 @@ acceptance("Modal", function (needs) {
|
||||
"modal/not-dismissable"
|
||||
] = hbs`{{#d-modal-body title="" class="" dismissable=false}}test{{/d-modal-body}}`;
|
||||
|
||||
run(() => showModal("not-dismissable", {}));
|
||||
showModal("not-dismissable", {});
|
||||
await settled();
|
||||
|
||||
assert.strictEqual(count(".d-modal:visible"), 1, "modal should appear");
|
||||
|
||||
@ -84,7 +84,8 @@ acceptance("Modal", function (needs) {
|
||||
];
|
||||
|
||||
await visit("/");
|
||||
run(() => showModal("test-raw-title-panels", { panels }));
|
||||
showModal("test-raw-title-panels", { panels });
|
||||
await settled();
|
||||
|
||||
assert.strictEqual(
|
||||
queryAll(".d-modal .modal-tab:first-child").text().trim(),
|
||||
@ -101,7 +102,8 @@ acceptance("Modal", function (needs) {
|
||||
|
||||
await visit("/");
|
||||
|
||||
run(() => showModal("test-title", { title: "test_title" }));
|
||||
showModal("test-title", { title: "test_title" });
|
||||
await settled();
|
||||
assert.strictEqual(
|
||||
queryAll(".d-modal .title").text().trim(),
|
||||
"Test title",
|
||||
@ -110,7 +112,8 @@ acceptance("Modal", function (needs) {
|
||||
|
||||
await click(".d-modal .close");
|
||||
|
||||
run(() => showModal("test-title-with-body", { title: "test_title" }));
|
||||
showModal("test-title-with-body", { title: "test_title" });
|
||||
await settled();
|
||||
assert.strictEqual(
|
||||
queryAll(".d-modal .title").text().trim(),
|
||||
"Test title",
|
||||
@ -119,7 +122,8 @@ acceptance("Modal", function (needs) {
|
||||
|
||||
await click(".d-modal .close");
|
||||
|
||||
run(() => showModal("test-title"));
|
||||
showModal("test-title");
|
||||
await settled();
|
||||
assert.ok(
|
||||
!exists(".d-modal .title"),
|
||||
"it should not re-use the previous title"
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { module, test } from "qunit";
|
||||
import PendingPost from "discourse/models/pending-post";
|
||||
import createStore from "discourse/tests/helpers/create-store";
|
||||
import { run } from "@ember/runloop";
|
||||
import { settled } from "@ember/test-helpers";
|
||||
|
||||
module("Unit | Model | pending-post", function () {
|
||||
test("Properties", function (assert) {
|
||||
test("Properties", async function (assert) {
|
||||
const store = createStore();
|
||||
const category = store.createRecord("category", { id: 2 });
|
||||
const post = PendingPost.create({
|
||||
@ -13,6 +13,8 @@ module("Unit | Model | pending-post", function () {
|
||||
username: "USERNAME",
|
||||
category_id: 2,
|
||||
});
|
||||
await settled();
|
||||
|
||||
assert.equal(post.postUrl, "topic-url", "topic_url is aliased to postUrl");
|
||||
assert.equal(post.truncated, false, "truncated is always false");
|
||||
assert.equal(
|
||||
@ -26,8 +28,11 @@ module("Unit | Model | pending-post", function () {
|
||||
"it returns the proper category object based on category_id"
|
||||
);
|
||||
});
|
||||
test("it cooks raw_text", function (assert) {
|
||||
const post = run(() => PendingPost.create({ raw_text: "**bold text**" }));
|
||||
|
||||
test("it cooks raw_text", async function (assert) {
|
||||
const post = PendingPost.create({ raw_text: "**bold text**" });
|
||||
await settled();
|
||||
|
||||
assert.equal(
|
||||
post.expandedExcerpt.string,
|
||||
"<p><strong>bold text</strong></p>"
|
||||
|
@ -35,7 +35,8 @@ define("@ember/test-helpers", () => {
|
||||
return _app;
|
||||
},
|
||||
async settled() {
|
||||
// No-op in pre ember-cli environment
|
||||
// eslint-disable-next-line no-undef, discourse-ember/global-ember
|
||||
Ember.run(() => {});
|
||||
},
|
||||
TestModuleForComponent: window.TestModuleForComponent,
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user