2019-10-30 09:48:24 -04:00
|
|
|
import { run } from "@ember/runloop";
|
2019-08-01 15:40:51 -04:00
|
|
|
import { acceptance, controllerFor } from "helpers/qunit-helpers";
|
2018-06-15 11:03:24 -04:00
|
|
|
import showModal from "discourse/lib/show-modal";
|
2018-06-04 21:34:41 -04:00
|
|
|
|
2015-04-06 14:14:00 -04:00
|
|
|
acceptance("Modal");
|
2014-09-08 16:52:49 -04:00
|
|
|
|
2020-05-27 11:36:50 -04:00
|
|
|
QUnit.skip("modal", async function(assert) {
|
2018-07-19 06:12:00 -04:00
|
|
|
await visit("/");
|
2014-09-08 16:52:49 -04:00
|
|
|
|
2018-07-19 06:12:00 -04:00
|
|
|
assert.ok(
|
|
|
|
find(".d-modal:visible").length === 0,
|
|
|
|
"there is no modal at first"
|
|
|
|
);
|
2014-09-08 16:52:49 -04:00
|
|
|
|
2018-07-19 06:12:00 -04:00
|
|
|
await click(".login-button");
|
|
|
|
assert.ok(find(".d-modal:visible").length === 1, "modal should appear");
|
2014-09-08 16:52:49 -04:00
|
|
|
|
2019-08-01 15:40:51 -04:00
|
|
|
let controller = controllerFor("modal");
|
|
|
|
assert.equal(controller.name, "login");
|
|
|
|
|
2018-07-19 06:12:00 -04:00
|
|
|
await click(".modal-outer-container");
|
|
|
|
assert.ok(
|
|
|
|
find(".d-modal:visible").length === 0,
|
|
|
|
"modal should disappear when you click outside"
|
|
|
|
);
|
2019-08-01 15:40:51 -04:00
|
|
|
assert.equal(controller.name, null);
|
2014-09-08 16:52:49 -04:00
|
|
|
|
2018-07-19 06:12:00 -04:00
|
|
|
await click(".login-button");
|
|
|
|
assert.ok(find(".d-modal:visible").length === 1, "modal should reappear");
|
2014-09-08 16:52:49 -04:00
|
|
|
|
2020-03-06 12:36:56 -05:00
|
|
|
await keyEvent("#main-outlet", "keyup", 27);
|
2018-07-19 06:12:00 -04: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 09:48:24 -04:00
|
|
|
run(() => showModal("not-dismissable", {}));
|
2018-07-19 06:12:00 -04: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 12:36:56 -05:00
|
|
|
await keyEvent("#main-outlet", "keyup", 27);
|
2018-07-19 06:12:00 -04:00
|
|
|
assert.ok(
|
|
|
|
find(".d-modal:visible").length === 1,
|
|
|
|
"ESC should not close the modal"
|
|
|
|
);
|
2017-08-30 15:29:51 -04:00
|
|
|
});
|
2019-10-09 13:28:07 -04: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 12:36:56 -05:00
|
|
|
await keyEvent(".d-modal", "keyup", 13);
|
2019-10-09 13:28:07 -04: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 12:36:56 -05:00
|
|
|
await keyEvent("#main-outlet", "keyup", 27);
|
2019-10-09 13:28:07 -04: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 12:36:56 -05:00
|
|
|
await keyEvent(".d-modal", "keyup", 13);
|
2019-10-09 13:28:07 -04:00
|
|
|
assert.ok(
|
|
|
|
find(".d-modal:visible").length === 0,
|
|
|
|
"modal should disappear on hitting Enter"
|
|
|
|
);
|
|
|
|
});
|