discourse/test/javascripts/acceptance/forgot-password-test.js.es6

104 lines
2.3 KiB
Plaintext
Raw Normal View History

import { acceptance } from "helpers/qunit-helpers";
let userFound = false;
acceptance("Forgot password", {
beforeEach() {
const response = object => {
2018-06-15 23:03:24 +08:00
return [200, { "Content-Type": "application/json" }, object];
};
2018-06-15 23:03:24 +08:00
server.post("/session/forgot_password", () => {
// eslint-disable-line no-undef
return response({ user_found: userFound });
});
}
});
QUnit.test("requesting password reset", assert => {
visit("/");
click("header .login-button");
2018-06-15 23:03:24 +08:00
click("#forgot-password-link");
andThen(() => {
assert.equal(
2018-06-15 23:03:24 +08:00
find(".forgot-password-reset").attr("disabled"),
"disabled",
2018-06-15 23:03:24 +08:00
"it should disable the button until the field is filled"
);
});
2018-06-15 23:03:24 +08:00
fillIn("#username-or-email", "someuser");
click(".forgot-password-reset");
andThen(() => {
assert.equal(
2018-06-15 23:03:24 +08:00
find(".alert-error")
.html()
.trim(),
I18n.t("forgot_password.complete_username_not_found", {
username: "someuser"
}),
"it should display an error for an invalid username"
);
});
2018-06-15 23:03:24 +08:00
fillIn("#username-or-email", "someuser@gmail.com");
click(".forgot-password-reset");
andThen(() => {
assert.equal(
2018-06-15 23:03:24 +08:00
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"
);
});
2018-06-15 23:03:24 +08:00
fillIn("#username-or-email", "someuser");
andThen(() => {
userFound = true;
});
2018-06-15 23:03:24 +08:00
click(".forgot-password-reset");
andThen(() => {
2018-06-15 23:03:24 +08:00
assert.notOk(
exists(find(".alert-error")),
"it should remove the flash error when succeeding"
);
assert.equal(
2018-06-15 23:03:24 +08:00
find(".modal-body")
.html()
.trim(),
I18n.t("forgot_password.complete_username_found", {
username: "someuser"
}),
"it should display a success message for a valid username"
);
});
visit("/");
click("header .login-button");
2018-06-15 23:03:24 +08:00
click("#forgot-password-link");
fillIn("#username-or-email", "someuser@gmail.com");
click(".forgot-password-reset");
andThen(() => {
assert.equal(
2018-06-15 23:03:24 +08:00
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"
);
});
});