Our method of loading a subset of client settings into tests via
tests/helpers/site-settings.js can be improved upon. Currently we have a
hardcoded subset of the client settings, which may get out of date and not have
the correct defaults. As well as this plugins do not get their settings into the
tests, so whenever you need a setting from a plugin, even if it has a default,
you have to do needs.setting({ ... }) which is inconvenient.
This commit introduces an ember CLI build step to take the site_settings.yml and
all the plugin settings.yml files, pull out the client settings, and dump them
into a variable in a single JS file we can load in our tests, so we have the
correct selection of settings and default values in our JS tests. It also fixes
many, many tests that were operating under incorrect assumptions or old
settings.
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
111 lines
3.3 KiB
JavaScript
111 lines
3.3 KiB
JavaScript
import { module, test } from "qunit";
|
|
import { setupTest } from "ember-qunit";
|
|
import { settled } from "@ember/test-helpers";
|
|
import I18n from "I18n";
|
|
|
|
module("Unit | Controller | create-account", function (hooks) {
|
|
setupTest(hooks);
|
|
|
|
test("basicUsernameValidation", function (assert) {
|
|
const testInvalidUsername = (username, expectedReason) => {
|
|
const controller = this.owner.lookup("controller:create-account");
|
|
controller.set("accountUsername", username);
|
|
|
|
let validation = controller.basicUsernameValidation(username);
|
|
assert.ok(validation.failed, "username should be invalid: " + username);
|
|
assert.strictEqual(
|
|
validation.reason,
|
|
expectedReason,
|
|
"username validation reason: " + username + ", " + expectedReason
|
|
);
|
|
};
|
|
|
|
testInvalidUsername("", null);
|
|
testInvalidUsername("x", I18n.t("user.username.too_short"));
|
|
testInvalidUsername(
|
|
"123456789012345678901",
|
|
I18n.t("user.username.too_long")
|
|
);
|
|
|
|
const controller = this.owner.lookup("controller:create-account");
|
|
controller.setProperties({
|
|
accountUsername: "porkchops",
|
|
prefilledUsername: "porkchops",
|
|
});
|
|
|
|
let validation = controller.basicUsernameValidation("porkchops");
|
|
assert.ok(validation.ok, "Prefilled username is valid");
|
|
assert.strictEqual(
|
|
validation.reason,
|
|
I18n.t("user.username.prefilled"),
|
|
"Prefilled username is valid"
|
|
);
|
|
});
|
|
|
|
test("passwordValidation", async function (assert) {
|
|
const controller = this.owner.lookup("controller:create-account");
|
|
|
|
controller.set("authProvider", "");
|
|
controller.set("accountEmail", "pork@chops.com");
|
|
controller.set("accountUsername", "porkchops123");
|
|
controller.set("prefilledUsername", "porkchops123");
|
|
controller.set("accountPassword", "b4fcdae11f9167");
|
|
|
|
assert.strictEqual(
|
|
controller.passwordValidation.ok,
|
|
true,
|
|
"Password is ok"
|
|
);
|
|
assert.strictEqual(
|
|
controller.passwordValidation.reason,
|
|
I18n.t("user.password.ok"),
|
|
"Password is valid"
|
|
);
|
|
|
|
const testInvalidPassword = (password, expectedReason) => {
|
|
controller.set("accountPassword", password);
|
|
|
|
assert.strictEqual(
|
|
controller.passwordValidation.failed,
|
|
true,
|
|
`password should be invalid: ${password}`
|
|
);
|
|
assert.strictEqual(
|
|
controller.passwordValidation.reason,
|
|
expectedReason,
|
|
`password validation reason: ${password}, ${expectedReason}`
|
|
);
|
|
};
|
|
|
|
testInvalidPassword("", null);
|
|
testInvalidPassword("x", I18n.t("user.password.too_short"));
|
|
testInvalidPassword(
|
|
"porkchops123",
|
|
I18n.t("user.password.same_as_username")
|
|
);
|
|
testInvalidPassword(
|
|
"pork@chops.com",
|
|
I18n.t("user.password.same_as_email")
|
|
);
|
|
|
|
// Wait for username check request to finish
|
|
await settled();
|
|
});
|
|
|
|
test("authProviderDisplayName", function (assert) {
|
|
const controller = this.owner.lookup("controller:create-account");
|
|
|
|
assert.strictEqual(
|
|
controller.authProviderDisplayName("facebook"),
|
|
I18n.t("login.facebook.name"),
|
|
"provider name is translated correctly"
|
|
);
|
|
|
|
assert.strictEqual(
|
|
controller.authProviderDisplayName("idontexist"),
|
|
"idontexist",
|
|
"provider name falls back if not found"
|
|
);
|
|
});
|
|
});
|