Remove Discourse.SiteSettings from tests (#10193)

* Remove unused Discourse.SiteSettings

* Remove `Discourse.SiteSettings` from many tests

* REFACTOR: `lib:formatter` was using a lot of leaky state

* Remove more `Discourse.SiteSettings` from tests

* More SiteSettings removed from tests
This commit is contained in:
Robin Ward
2020-07-09 15:54:53 -04:00
committed by GitHub
parent b1c6ff9e1c
commit 5b276af921
19 changed files with 252 additions and 218 deletions

View File

@ -24,6 +24,7 @@ import { resetCache as resetOneboxCache } from "pretty-text/oneboxer";
import { resetCustomPostMessageCallbacks } from "discourse/controllers/topic";
import { _clearSnapshots } from "select-kit/components/composer-actions";
import User from "discourse/models/user";
import { mapRoutes } from "discourse/mapping-router";
export function currentUser() {
return User.create(sessionFixtures["/session/current.json"].current_user);
@ -101,6 +102,37 @@ export function applyPretender(name, server, helper) {
if (cb) cb(server, helper);
}
export function controllerModule(name, args = {}) {
moduleFor(name, name, {
setup() {
this.registry.register("router:main", mapRoutes());
let controller = this.subject();
controller.siteSettings = Discourse.SiteSettings;
if (args.setupController) {
args.setupController(controller);
}
},
needs: args.needs
});
}
export function discourseModule(name, hooks) {
QUnit.module(name, {
beforeEach() {
// Give us an API to change site settings without `Discourse.SiteSettings` in tests
this.siteSettings = Discourse.SiteSettings;
if (hooks && hooks.beforeEach) {
hooks.beforeEach.call(this);
}
},
afterEach() {
if (hooks && hooks.afterEach) {
hooks.afterEach.call(this);
}
}
});
}
export function acceptance(name, options) {
options = options || {};
@ -135,6 +167,7 @@ export function acceptance(name, options) {
options.settings
);
}
this.siteSettings = Discourse.SiteSettings;
if (options.site) {
resetSite(Discourse.SiteSettings, options.site);