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>
61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
const CLIENT_SETTING_TEST_OVERRIDES = {
|
|
title: "QUnit Discourse Tests",
|
|
site_logo_url: "/assets/logo.png",
|
|
site_logo_url: "/assets/logo.png",
|
|
site_logo_small_url: "/assets/logo-single.png",
|
|
site_mobile_logo_url: "",
|
|
site_favicon_url: "/images/discourse-logo-sketch-small.png",
|
|
enable_twitter_logins: true,
|
|
enable_facebook_logins: true,
|
|
enable_github_logins: true,
|
|
authorized_extensions: "jpg|jpeg|png|gif|heic|heif|webp|svg|txt|ico|yml",
|
|
anon_polling_interval: 30000,
|
|
flush_timings_secs: 5,
|
|
};
|
|
|
|
// Note, CLIENT_SITE_SETTINGS_WITH_DEFAULTS is generated by the site-settings-plugin,
|
|
// writing to test-site-settings.js via the ember-cli-build pipeline.
|
|
const ORIGINAL_CLIENT_SITE_SETTINGS = Object.assign(
|
|
{},
|
|
// eslint-disable-next-line no-undef
|
|
CLIENT_SITE_SETTINGS_WITH_DEFAULTS,
|
|
CLIENT_SETTING_TEST_OVERRIDES
|
|
);
|
|
let siteSettings = Object.assign({}, ORIGINAL_CLIENT_SITE_SETTINGS);
|
|
|
|
export function currentSettings() {
|
|
return siteSettings;
|
|
}
|
|
|
|
// In debug mode, Ember will decorate objects with setters that remind you to use
|
|
// this.set() because they are bound (even if you use `unbound` or `readonly` in templates!).
|
|
// Site settings are only ever changed in tests and these warnings are not wanted, so we'll
|
|
// strip them when resetting our settings between tests.
|
|
function setValue(k, v) {
|
|
let desc = Object.getOwnPropertyDescriptor(siteSettings, k);
|
|
if (desc && !desc.writable) {
|
|
Object.defineProperty(siteSettings, k, { writable: true });
|
|
}
|
|
siteSettings[k] = v;
|
|
}
|
|
|
|
export function mergeSettings(other) {
|
|
for (let p in other) {
|
|
if (other.hasOwnProperty(p)) {
|
|
setValue(p, other[p]);
|
|
}
|
|
}
|
|
return siteSettings;
|
|
}
|
|
|
|
export function resetSettings() {
|
|
for (let p in siteSettings) {
|
|
if (siteSettings.hasOwnProperty(p)) {
|
|
// eslint-disable-next-line no-undef
|
|
let v = ORIGINAL_CLIENT_SITE_SETTINGS[p];
|
|
typeof v !== "undefined" ? setValue(p, v) : delete siteSettings[p];
|
|
}
|
|
}
|
|
return siteSettings;
|
|
}
|