2019-10-30 21:48:24 +08:00
|
|
|
import { run } from "@ember/runloop";
|
2019-08-02 03:40:51 +08:00
|
|
|
import { acceptance, controllerFor } from "helpers/qunit-helpers";
|
2018-06-05 09:34:41 +08:00
|
|
|
import showModal from "discourse/lib/show-modal";
|
|
|
|
|
2015-04-07 02:14:00 +08:00
|
|
|
acceptance("Modal");
|
2014-09-09 04:52:49 +08:00
|
|
|
|
2019-08-02 03:40:51 +08:00
|
|
|
QUnit.test("modal", async function(assert) {
|
2018-07-19 18:12:00 +08:00
|
|
|
await visit("/");
|
2014-09-09 04:52:49 +08:00
|
|
|
|
2018-07-19 18:12:00 +08:00
|
|
|
assert.ok(
|
|
|
|
find(".d-modal:visible").length === 0,
|
|
|
|
"there is no modal at first"
|
|
|
|
);
|
2014-09-09 04:52:49 +08:00
|
|
|
|
2018-07-19 18:12:00 +08:00
|
|
|
await click(".login-button");
|
|
|
|
assert.ok(find(".d-modal:visible").length === 1, "modal should appear");
|
2014-09-09 04:52:49 +08:00
|
|
|
|
2019-08-02 03:40:51 +08:00
|
|
|
let controller = controllerFor("modal");
|
|
|
|
assert.equal(controller.name, "login");
|
|
|
|
|
2018-07-19 18:12:00 +08:00
|
|
|
await click(".modal-outer-container");
|
|
|
|
assert.ok(
|
|
|
|
find(".d-modal:visible").length === 0,
|
|
|
|
"modal should disappear when you click outside"
|
|
|
|
);
|
2019-08-02 03:40:51 +08:00
|
|
|
assert.equal(controller.name, null);
|
2014-09-09 04:52:49 +08:00
|
|
|
|
2018-07-19 18:12:00 +08:00
|
|
|
await click(".login-button");
|
|
|
|
assert.ok(find(".d-modal:visible").length === 1, "modal should reappear");
|
2014-09-09 04:52:49 +08:00
|
|
|
|
2020-03-06 09:29:51 +08:00
|
|
|
await keyEvent("#main-outlet", "keydown", 27);
|
2018-07-19 18:12:00 +08:00
|
|
|
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}}'
|
|
|
|
);
|
|
|
|
|
2019-10-30 21:48:24 +08:00
|
|
|
run(() => showModal("not-dismissable", {}));
|
2018-07-19 18:12:00 +08:00
|
|
|
|
|
|
|
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"
|
|
|
|
);
|
2020-03-06 09:29:51 +08:00
|
|
|
await keyEvent("#main-outlet", "keydown", 27);
|
2018-07-19 18:12:00 +08:00
|
|
|
assert.ok(
|
|
|
|
find(".d-modal:visible").length === 1,
|
|
|
|
"ESC should not close the modal"
|
|
|
|
);
|
2017-08-31 03:29:51 +08:00
|
|
|
});
|
2019-10-10 01:28:07 +08:00
|
|
|
|
|
|
|
acceptance("Modal Keyboard Events", { loggedIn: true });
|
|
|
|
|
|
|
|
QUnit.test("modal-keyboard-events", async function(assert) {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
|
|
|
|
await click(".toggle-admin-menu");
|
|
|
|
await click(".topic-admin-status-update button");
|
2020-03-06 09:29:51 +08:00
|
|
|
await keyEvent(".d-modal", "keydown", 13);
|
2019-10-10 01:28:07 +08:00
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
find("#modal-alert:visible").length === 1,
|
|
|
|
"hitting Enter triggers modal action"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
find(".d-modal:visible").length === 1,
|
|
|
|
"hitting Enter does not dismiss modal due to alert error"
|
|
|
|
);
|
|
|
|
|
2020-03-06 09:29:51 +08:00
|
|
|
await keyEvent("#main-outlet", "keydown", 27);
|
2019-10-10 01:28:07 +08:00
|
|
|
assert.ok(
|
|
|
|
find(".d-modal:visible").length === 0,
|
|
|
|
"ESC should close the modal"
|
|
|
|
);
|
|
|
|
|
|
|
|
await click(".topic-body button.reply");
|
|
|
|
|
|
|
|
await click(".d-editor-button-bar .btn.link");
|
|
|
|
|
2020-03-06 09:29:51 +08:00
|
|
|
await keyEvent(".d-modal", "keydown", 13);
|
2019-10-10 01:28:07 +08:00
|
|
|
assert.ok(
|
|
|
|
find(".d-modal:visible").length === 0,
|
|
|
|
"modal should disappear on hitting Enter"
|
|
|
|
);
|
|
|
|
});
|