mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 15:55:08 +08:00
f57fdee2f6
This happened because the modal controller was not clearing the `name` attribute, which is used for looking up the controller to call `onClose` on. Every page navigation would call the method over and over, breaking state in odd ways.
55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
import { acceptance, controllerFor } from "helpers/qunit-helpers";
|
|
import showModal from "discourse/lib/show-modal";
|
|
|
|
acceptance("Modal");
|
|
|
|
QUnit.test("modal", async function(assert) {
|
|
await visit("/");
|
|
|
|
assert.ok(
|
|
find(".d-modal:visible").length === 0,
|
|
"there is no modal at first"
|
|
);
|
|
|
|
await click(".login-button");
|
|
assert.ok(find(".d-modal:visible").length === 1, "modal should appear");
|
|
|
|
let controller = controllerFor("modal");
|
|
assert.equal(controller.name, "login");
|
|
|
|
await click(".modal-outer-container");
|
|
assert.ok(
|
|
find(".d-modal:visible").length === 0,
|
|
"modal should disappear when you click outside"
|
|
);
|
|
assert.equal(controller.name, null);
|
|
|
|
await click(".login-button");
|
|
assert.ok(find(".d-modal:visible").length === 1, "modal should reappear");
|
|
|
|
await keyEvent("#main-outlet", "keydown", 27);
|
|
assert.ok(
|
|
find(".d-modal:visible").length === 0,
|
|
"ESC should close the modal"
|
|
);
|
|
|
|
Ember.TEMPLATES["modal/not-dismissable"] = Ember.HTMLBars.compile(
|
|
'{{#d-modal-body title="" class="" dismissable=false}}test{{/d-modal-body}}'
|
|
);
|
|
|
|
Ember.run(() => showModal("not-dismissable", {}));
|
|
|
|
assert.ok(find(".d-modal:visible").length === 1, "modal should appear");
|
|
|
|
await click(".modal-outer-container");
|
|
assert.ok(
|
|
find(".d-modal:visible").length === 1,
|
|
"modal should not disappear when you click outside"
|
|
);
|
|
await keyEvent("#main-outlet", "keydown", 27);
|
|
assert.ok(
|
|
find(".d-modal:visible").length === 1,
|
|
"ESC should not close the modal"
|
|
);
|
|
});
|