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/forgot-password-test.js
Robin Ward 71d37953d5 REFACTOR: Import QUnit and related helpers rather than globals
We used many global functions to handle tests when they should be
imported like other libraries in our application. This also gets us
closer to the way Ember CLI prefers our tests to be laid out.
2020-10-07 11:50:49 -04:00

83 lines
2.1 KiB
JavaScript

import { test } from "qunit";
import I18n from "I18n";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
let userFound = false;
acceptance("Forgot password", {
pretend(server, helper) {
server.post("/session/forgot_password", () => {
return helper.response({
user_found: userFound,
});
});
},
});
test("requesting password reset", async (assert) => {
await visit("/");
await click("header .login-button");
await click("#forgot-password-link");
assert.equal(
find(".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(
find(".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(
find(".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(find(".alert-error")),
"it should remove the flash error when succeeding"
);
assert.equal(
find(".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(
find(".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"
);
});