2017-04-20 23:17:24 +08:00
|
|
|
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];
|
2017-04-20 23:17:24 +08:00
|
|
|
};
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
server.post("/session/forgot_password", () => {
|
|
|
|
// eslint-disable-line no-undef
|
|
|
|
return response({ user_found: userFound });
|
2017-04-20 23:17:24 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-02-20 20:29:43 +08:00
|
|
|
QUnit.test("requesting password reset", assert => {
|
2017-04-20 23:17:24 +08:00
|
|
|
visit("/");
|
|
|
|
click("header .login-button");
|
2018-06-15 23:03:24 +08:00
|
|
|
click("#forgot-password-link");
|
2017-04-20 23:17:24 +08:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-02-20 20:29:43 +08:00
|
|
|
assert.equal(
|
2018-06-15 23:03:24 +08:00
|
|
|
find(".forgot-password-reset").attr("disabled"),
|
2018-02-20 20:29:43 +08:00
|
|
|
"disabled",
|
2018-06-15 23:03:24 +08:00
|
|
|
"it should disable the button until the field is filled"
|
2018-02-20 20:29:43 +08:00
|
|
|
);
|
2017-04-20 23:17:24 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
fillIn("#username-or-email", "someuser");
|
|
|
|
click(".forgot-password-reset");
|
2017-04-20 23:17:24 +08:00
|
|
|
|
|
|
|
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"
|
2017-04-20 23:17:24 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
fillIn("#username-or-email", "someuser@gmail.com");
|
|
|
|
click(".forgot-password-reset");
|
2017-04-20 23:17:24 +08:00
|
|
|
|
|
|
|
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"
|
2017-04-20 23:17:24 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
fillIn("#username-or-email", "someuser");
|
2017-04-20 23:17:24 +08:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
userFound = true;
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
click(".forgot-password-reset");
|
2017-04-20 23:17:24 +08:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.notOk(
|
|
|
|
exists(find(".alert-error")),
|
|
|
|
"it should remove the flash error when succeeding"
|
|
|
|
);
|
2018-02-20 20:29:43 +08:00
|
|
|
|
2017-04-20 23:17:24 +08:00
|
|
|
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"
|
2017-04-20 23:17:24 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
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");
|
2017-04-20 23:17:24 +08:00
|
|
|
|
|
|
|
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"
|
2017-04-20 23:17:24 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|