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)
86 lines
2.4 KiB
JavaScript
86 lines
2.4 KiB
JavaScript
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
|
|
import { exists } from "discourse/tests/helpers/qunit-helpers";
|
|
import { click, fillIn, visit } from "@ember/test-helpers";
|
|
import { test } from "qunit";
|
|
import I18n from "I18n";
|
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
let userFound = false;
|
|
|
|
acceptance("Forgot password", function (needs) {
|
|
needs.pretender((server, helper) => {
|
|
server.post("/session/forgot_password", () => {
|
|
return helper.response({
|
|
user_found: userFound,
|
|
});
|
|
});
|
|
});
|
|
|
|
test("requesting password reset", async function (assert) {
|
|
await visit("/");
|
|
await click("header .login-button");
|
|
await click("#forgot-password-link");
|
|
|
|
assert.equal(
|
|
queryAll(".forgot-password-reset").attr("disabled"),
|
|
"disabled",
|
|
"it should disable the button until the field is filled"
|
|
);
|
|
|
|
await fillIn("#username-or-email", "someuser");
|
|
await click(".forgot-password-reset");
|
|
|
|
assert.equal(
|
|
queryAll(".alert-error").html().trim(),
|
|
I18n.t("forgot_password.complete_username_not_found", {
|
|
username: "someuser",
|
|
}),
|
|
"it should display an error for an invalid username"
|
|
);
|
|
|
|
await fillIn("#username-or-email", "someuser@gmail.com");
|
|
await click(".forgot-password-reset");
|
|
|
|
assert.equal(
|
|
queryAll(".alert-error").html().trim(),
|
|
I18n.t("forgot_password.complete_email_not_found", {
|
|
email: "someuser@gmail.com",
|
|
}),
|
|
"it should display an error for an invalid email"
|
|
);
|
|
|
|
await fillIn("#username-or-email", "someuser");
|
|
|
|
userFound = true;
|
|
|
|
await click(".forgot-password-reset");
|
|
|
|
assert.notOk(
|
|
exists(queryAll(".alert-error")),
|
|
"it should remove the flash error when succeeding"
|
|
);
|
|
|
|
assert.equal(
|
|
queryAll(".modal-body").html().trim(),
|
|
I18n.t("forgot_password.complete_username_found", {
|
|
username: "someuser",
|
|
}),
|
|
"it should display a success message for a valid username"
|
|
);
|
|
|
|
await visit("/");
|
|
await click("header .login-button");
|
|
await click("#forgot-password-link");
|
|
await fillIn("#username-or-email", "someuser@gmail.com");
|
|
await click(".forgot-password-reset");
|
|
|
|
assert.equal(
|
|
queryAll(".modal-body").html().trim(),
|
|
I18n.t("forgot_password.complete_email_found", {
|
|
email: "someuser@gmail.com",
|
|
}),
|
|
"it should display a success message for a valid email"
|
|
);
|
|
});
|
|
});
|