discourse/test/javascripts/controllers/create-account-test.js.es6

87 lines
2.8 KiB
Plaintext
Raw Normal View History

2018-06-15 23:03:24 +08:00
import { mapRoutes } from "discourse/mapping-router";
2016-11-09 03:29:50 +08:00
2014-07-31 05:53:14 +08:00
moduleFor("controller:create-account", "controller:create-account", {
2017-06-15 01:57:58 +08:00
beforeEach() {
2018-06-15 23:03:24 +08:00
this.registry.register("router:main", mapRoutes());
2016-11-09 03:29:50 +08:00
},
2018-06-15 23:03:24 +08:00
needs: ["controller:modal", "controller:login"]
2014-07-31 05:53:14 +08:00
});
2018-06-15 23:03:24 +08:00
QUnit.test("basicUsernameValidation", function(assert) {
2014-07-31 05:53:14 +08:00
var subject = this.subject;
var testInvalidUsername = function(username, expectedReason) {
var controller = subject({ siteSettings: Discourse.SiteSettings });
2018-06-15 23:03:24 +08:00
controller.set("accountUsername", username);
assert.equal(
controller.get("basicUsernameValidation.failed"),
true,
"username should be invalid: " + username
);
assert.equal(
controller.get("basicUsernameValidation.reason"),
expectedReason,
"username validation reason: " + username + ", " + expectedReason
);
};
2018-06-15 23:03:24 +08:00
testInvalidUsername("", undefined);
testInvalidUsername("x", I18n.t("user.username.too_short"));
testInvalidUsername(
"123456789012345678901",
I18n.t("user.username.too_long")
);
var controller = subject({ siteSettings: Discourse.SiteSettings });
2018-06-15 23:03:24 +08:00
controller.set("accountUsername", "porkchops");
controller.set("prefilledUsername", "porkchops");
assert.equal(
controller.get("basicUsernameValidation.ok"),
true,
"Prefilled username is valid"
);
assert.equal(
controller.get("basicUsernameValidation.reason"),
I18n.t("user.username.prefilled"),
"Prefilled username is valid"
);
});
2018-06-15 23:03:24 +08:00
QUnit.test("passwordValidation", function(assert) {
var subject = this.subject;
var controller = subject({ siteSettings: Discourse.SiteSettings });
2018-06-15 23:03:24 +08:00
controller.set("passwordRequired", true);
controller.set("accountEmail", "pork@chops.com");
controller.set("accountUsername", "porkchops");
controller.set("prefilledUsername", "porkchops");
2018-06-15 23:03:24 +08:00
controller.set("accountPassword", "b4fcdae11f9167");
assert.equal(controller.get("passwordValidation.ok"), true, "Password is ok");
assert.equal(
controller.get("passwordValidation.reason"),
I18n.t("user.password.ok"),
"Password is valid"
);
var testInvalidPassword = function(password, expectedReason) {
var c = subject({ siteSettings: Discourse.SiteSettings });
2018-06-15 23:03:24 +08:00
c.set("accountPassword", password);
assert.equal(
c.get("passwordValidation.failed"),
true,
"password should be invalid: " + password
);
assert.equal(
c.get("passwordValidation.reason"),
expectedReason,
"password validation reason: " + password + ", " + expectedReason
);
};
2018-06-15 23:03:24 +08:00
testInvalidPassword("", undefined);
testInvalidPassword("x", I18n.t("user.password.too_short"));
testInvalidPassword("porkchops", I18n.t("user.password.same_as_username"));
testInvalidPassword("pork@chops.com", I18n.t("user.password.same_as_email"));
});