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/unit/controllers/create-account-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

105 lines
3.0 KiB
JavaScript

import { test } from "qunit";
import I18n from "I18n";
import { controllerModule } from "discourse/tests/helpers/qunit-helpers";
controllerModule("controller:create-account", {
needs: ["controller:modal", "controller:login"],
});
test("basicUsernameValidation", async function (assert) {
const subject = this.subject;
const testInvalidUsername = async (username, expectedReason) => {
const controller = await subject();
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
);
};
testInvalidUsername("", undefined);
testInvalidUsername("x", I18n.t("user.username.too_short"));
testInvalidUsername(
"123456789012345678901",
I18n.t("user.username.too_long")
);
const controller = await subject();
controller.setProperties({
accountUsername: "porkchops",
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"
);
});
test("passwordValidation", async function (assert) {
const controller = await this.subject();
controller.set("authProvider", "");
controller.set("accountEmail", "pork@chops.com");
controller.set("accountUsername", "porkchops");
controller.set("prefilledUsername", "porkchops");
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"
);
const testInvalidPassword = (password, expectedReason) => {
controller.set("accountPassword", password);
assert.equal(
controller.get("passwordValidation.failed"),
true,
"password should be invalid: " + password
);
assert.equal(
controller.get("passwordValidation.reason"),
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();
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"
);
});