This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/acceptance/admin-suspend-user-test.js
Jarek Radosz a17d54d0bf
DEV: De-arrowify tests (#11068)
Using arrow functions changes `this` context, which is undesired in tests, e.g. it makes it impossible to setup things like pretender (`this.server`) in `beforeEach` hooks.

Ember guides always use classic functions in examples (e.g. https://guides.emberjs.com/release/testing/test-types/), and that's what it uses in its own test suite, as do various addons and ember apps.

It was also already used in Discourse where `this` was required. Moving forward, it will be needed in more places as we migrate toward ember-cli.

(I might later add a custom rule to eslint-discourse-ember to enforce this)
2020-10-30 17:37:32 +01:00

105 lines
3.1 KiB
JavaScript

import { queryAll } from "discourse/tests/helpers/qunit-helpers";
import { exists } from "discourse/tests/helpers/qunit-helpers";
import { visit, click, fillIn } from "@ember/test-helpers";
import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Admin - Suspend User", function (needs) {
needs.user();
needs.pretender((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,
},
})
);
});
test("suspend a user - cancel", async function (assert) {
await visit("/admin/users/1234/regular");
await click(".suspend-user");
assert.equal(queryAll(".suspend-user-modal:visible").length, 1);
await click(".d-modal-cancel");
assert.equal(queryAll(".suspend-user-modal:visible").length, 0);
});
test("suspend a user - cancel with input", async function (assert) {
await visit("/admin/users/1234/regular");
await click(".suspend-user");
assert.equal(queryAll(".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(queryAll(".bootbox.modal:visible").length, 1);
await click(".modal-footer .btn-default");
assert.equal(queryAll(".suspend-user-modal:visible").length, 1);
assert.equal(
queryAll(".suspend-message")[0].value,
"this is an email reason why"
);
await click(".d-modal-cancel");
assert.equal(queryAll(".bootbox.modal:visible").length, 1);
assert.equal(queryAll(".suspend-user-modal:visible").length, 0);
await click(".modal-footer .btn-primary");
assert.equal(queryAll(".bootbox.modal:visible").length, 0);
});
test("suspend, then unsuspend a user", async function (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(
queryAll(".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(
queryAll(".perform-suspend[disabled]").length,
0,
"no longer disabled"
);
await click(".perform-suspend");
assert.equal(queryAll(".suspend-user-modal:visible").length, 0);
assert.ok(exists(".suspension-info"));
await click(".unsuspend-user");
assert.ok(!exists(".suspension-info"));
});
});