discourse/test/javascripts/acceptance/admin-suspend-user-test.js.es6
Jeff Wong 111fa7e277 FEATURE: prevent accidental canceling when drafting penalties (#9129)
Pop up a confirmation box when there is input. This prevents accidental closing
of the dialog boxes due to clicking outside.

This adds a development hook on modals in the form of a `beforeClose`
function. Modal windows can abort the close if the funtion returns false.

Additionally fixing a few issues with loop and state on the modal popups:

Escape key with bootbox is keyup.
Updating modal to close on keyup as well so escape key is working.
Fixes an issue where pressing esc will loop immediately back to the modal by:
keydown -> bootbox -> keyup -> acts as "cancel", restores modal

Needs a next call to reopenModal otherwise, keyup is handled again by the modal.
Fixes an issue where pressing esc will loop immediately back to the confirm:
esc keyup will be handled and bubble immediately back to the modal.

Additionally, only handle key events when the #discourse-modal is visible.
This resolves issues where escape or enter events were being handled by
a hidden modal window.
2020-03-23 16:01:39 -07:00

102 lines
2.6 KiB
JavaScript

import selectKit from "helpers/select-kit-helper";
import { acceptance } from "helpers/qunit-helpers";
acceptance("Admin - Suspend User", {
loggedIn: true,
pretend(server, helper) {
server.put("/admin/users/:user_id/suspend", () =>
helper.response(200, {
suspension: {
suspended_till: "2099-01-01T12:00:00.000Z"
}
})
);
server.put("/admin/users/:user_id/unsuspend", () =>
helper.response(200, {
suspension: {
suspended_till: null
}
})
);
}
});
QUnit.test("suspend a user - cancel", async assert => {
await visit("/admin/users/1234/regular");
await click(".suspend-user");
assert.equal(find(".suspend-user-modal:visible").length, 1);
await click(".d-modal-cancel");
assert.equal(find(".suspend-user-modal:visible").length, 0);
});
QUnit.test("suspend a user - cancel with input", async assert => {
await visit("/admin/users/1234/regular");
await click(".suspend-user");
assert.equal(find(".suspend-user-modal:visible").length, 1);
await fillIn(".suspend-reason", "for breaking the rules");
await fillIn(".suspend-message", "this is an email reason why");
await click(".d-modal-cancel");
assert.equal(find(".bootbox.modal:visible").length, 1);
await click(".modal-footer .btn-default");
assert.equal(find(".suspend-user-modal:visible").length, 1);
assert.equal(
find(".suspend-message")[0].value,
"this is an email reason why"
);
await click(".d-modal-cancel");
assert.equal(find(".bootbox.modal:visible").length, 1);
assert.equal(find(".suspend-user-modal:visible").length, 0);
await click(".modal-footer .btn-primary");
assert.equal(find(".bootbox.modal:visible").length, 0);
});
QUnit.test("suspend, then unsuspend a user", async assert => {
const suspendUntilCombobox = selectKit(".suspend-until .combobox");
await visit("/admin/flags/active");
await visit("/admin/users/1234/regular");
assert.ok(!exists(".suspension-info"));
await click(".suspend-user");
assert.equal(
find(".perform-suspend[disabled]").length,
1,
"disabled by default"
);
await suspendUntilCombobox.expand();
await suspendUntilCombobox.selectRowByValue("tomorrow");
await fillIn(".suspend-reason", "for breaking the rules");
await fillIn(".suspend-message", "this is an email reason why");
assert.equal(
find(".perform-suspend[disabled]").length,
0,
"no longer disabled"
);
await click(".perform-suspend");
assert.equal(find(".suspend-user-modal:visible").length, 0);
assert.ok(exists(".suspension-info"));
await click(".unsuspend-user");
assert.ok(!exists(".suspension-info"));
});