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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

109 lines
3.2 KiB
JavaScript
Raw Normal View History

import I18n from "I18n";
2016-11-09 03:29:50 +08:00
import { mapRoutes } from "discourse/mapping-router";
2014-07-31 05:53:14 +08:00
moduleFor("controller:create-account", "controller:create-account", {
2017-06-15 01:57:58 +08:00
beforeEach() {
2016-11-09 03:29:50 +08:00
this.registry.register("router:main", mapRoutes());
},
needs: ["controller:modal", "controller:login"]
2014-07-31 05:53:14 +08:00
});
test("basicUsernameValidation", async function(assert) {
const subject = this.subject;
2014-07-31 05:53:14 +08:00
const testInvalidUsername = async (username, expectedReason) => {
const controller = await subject({ siteSettings: Discourse.SiteSettings });
controller.set("accountUsername", username);
2017-06-15 01:57:58 +08:00
assert.equal(
controller.get("basicUsernameValidation.failed"),
true,
"username should be invalid: " + username
);
assert.equal(
controller.get("basicUsernameValidation.reason"),
expectedReason,
"username validation reason: " + username + ", " + expectedReason
);
};
testInvalidUsername("", undefined);
testInvalidUsername("x", I18n.t("user.username.too_short"));
testInvalidUsername(
"123456789012345678901",
I18n.t("user.username.too_long")
);
const controller = await subject({ siteSettings: Discourse.SiteSettings });
controller.setProperties({
accountUsername: "porkchops",
prefilledUsername: "porkchops"
});
2017-06-15 01:57:58 +08:00
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"
);
});
test("passwordValidation", async function(assert) {
const controller = await this.subject({
siteSettings: Discourse.SiteSettings
});
controller.set("passwordRequired", true);
2016-03-04 17:52:23 +08:00
controller.set("accountEmail", "pork@chops.com");
controller.set("accountUsername", "porkchops");
controller.set("prefilledUsername", "porkchops");
2016-03-04 17:52:23 +08:00
controller.set("accountPassword", "b4fcdae11f9167");
2017-06-15 01:57:58 +08:00
assert.equal(controller.get("passwordValidation.ok"), true, "Password is ok");
assert.equal(
controller.get("passwordValidation.reason"),
I18n.t("user.password.ok"),
"Password is valid"
);
const testInvalidPassword = (password, expectedReason) => {
controller.set("accountPassword", password);
2017-06-15 01:57:58 +08:00
assert.equal(
controller.get("passwordValidation.failed"),
2017-06-15 01:57:58 +08:00
true,
"password should be invalid: " + password
);
assert.equal(
controller.get("passwordValidation.reason"),
2017-06-15 01:57:58 +08:00
expectedReason,
"password validation reason: " + password + ", " + expectedReason
);
};
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"));
});
test("authProviderDisplayName", async function(assert) {
const controller = this.subject({ siteSettings: Discourse.SiteSettings });
assert.equal(
controller.authProviderDisplayName("facebook"),
I18n.t("login.facebook.name"),
"provider name is translated correctly"
);
assert.equal(
controller.authProviderDisplayName("idontexist"),
"idontexist",
"provider name falls back if not found"
);
});