Remove `Discourse.SiteSettings` from tests (#10193)

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

diff --git a/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6 b/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6
index f582a3f..a499ba5 100644
--- a/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6
+++ b/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6
@@ -1,9 +1,8 @@
-import { mapRoutes } from "discourse/mapping-router";
+import { controllerModule } from "helpers/qunit-helpers";
 
-moduleFor("controller:poll-ui-builder", "controller:poll-ui-builder", {
-  setup() {
-    this.registry.register("router:main", mapRoutes());
-    this.subject().set("toolbarEvent", {
+controllerModule("controller:poll-ui-builder", {
+  setupController(controller) {
+    controller.set("toolbarEvent", {
       getText: () => ""
     });
   },
@@ -31,7 +30,6 @@ test("isMultiple", function(assert) {
 
 test("isNumber", function(assert) {
   const controller = this.subject();
-  controller.siteSettings = Discourse.SiteSettings;
 
   controller.set("pollType", controller.regularPollType);
 
@@ -44,7 +42,6 @@ test("isNumber", function(assert) {
 
 test("showMinMax", function(assert) {
   const controller = this.subject();
-  controller.siteSettings = Discourse.SiteSettings;
 
   controller.set("pollType", controller.numberPollType);
   assert.equal(controller.showMinMax, true, "it should be true");
@@ -58,7 +55,6 @@ test("showMinMax", function(assert) {
 
 test("pollOptionsCount", function(assert) {
   const controller = this.subject();
-  controller.siteSettings = Discourse.SiteSettings;
 
   controller.set("pollOptions", "1\n2\n");
 
@@ -71,7 +67,6 @@ test("pollOptionsCount", function(assert) {
 
 test("pollMinOptions", function(assert) {
   const controller = this.subject();
-  controller.siteSettings = Discourse.SiteSettings;
 
   controller.setProperties({
     pollType: controller.multiplePollType,
@@ -110,7 +105,6 @@ test("pollMinOptions", function(assert) {
 
 test("pollMaxOptions", function(assert) {
   const controller = this.subject();
-  controller.siteSettings = Discourse.SiteSettings;
 
   controller.setProperties({
     pollType: controller.multiplePollType,
@@ -154,7 +148,6 @@ test("pollMaxOptions", function(assert) {
 
 test("pollStepOptions", function(assert) {
   const controller = this.subject();
-  controller.siteSettings = Discourse.SiteSettings;
   controller.siteSettings.poll_maximum_options = 3;
 
   assert.equal(controller.pollStepOptions, null, "is should return null");
@@ -174,7 +167,6 @@ test("pollStepOptions", function(assert) {
 
 test("disableInsert", function(assert) {
   const controller = this.subject();
-  controller.siteSettings = Discourse.SiteSettings;
 
   assert.equal(controller.disableInsert, true, "it should be true");
 
@@ -210,7 +202,6 @@ test("disableInsert", function(assert) {
 
 test("number pollOutput", function(assert) {
   const controller = this.subject();
-  controller.siteSettings = Discourse.SiteSettings;
   controller.siteSettings.poll_maximum_options = 20;
 
   controller.setProperties({
@@ -251,7 +242,6 @@ test("number pollOutput", function(assert) {
 
 test("regular pollOutput", function(assert) {
   const controller = this.subject();
-  controller.siteSettings = Discourse.SiteSettings;
   controller.siteSettings.poll_maximum_options = 20;
 
   controller.set("pollOptions", "1\n2");
@@ -285,7 +275,6 @@ test("regular pollOutput", function(assert) {
 
 test("multiple pollOutput", function(assert) {
   const controller = this.subject();
-  controller.siteSettings = Discourse.SiteSettings;
   controller.siteSettings.poll_maximum_options = 20;
 
   controller.setProperties({
diff --git a/test/javascripts/acceptance/auth-complete-test.js b/test/javascripts/acceptance/auth-complete-test.js
index 58a717b..864953f 100644
--- a/test/javascripts/acceptance/auth-complete-test.js
+++ b/test/javascripts/acceptance/auth-complete-test.js
@@ -27,8 +27,8 @@ QUnit.test("when login not required", async assert => {
   );
 });
 
-QUnit.test("when login required", async assert => {
-  Discourse.SiteSettings.login_required = true;
+QUnit.test("when login required", async function(assert) {
+  this.siteSettings.login_required = true;
   await visit("/");
 
   assert.equal(currentPath(), "login", "it redirects to the login page");
diff --git a/test/javascripts/acceptance/composer-test.js b/test/javascripts/acceptance/composer-test.js
index 74f87d5..5a30d17 100644
--- a/test/javascripts/acceptance/composer-test.js
+++ b/test/javascripts/acceptance/composer-test.js
@@ -720,8 +720,6 @@ QUnit.test("Loading draft also replaces the recipients", async assert => {
 QUnit.test(
   "Deleting the text content of the first post in a private message",
   async assert => {
-    Discourse.SiteSettings.allow_uncategorized_topics = false;
-
     await visit("/t/34");
 
     await click("#post_1 .d-icon-ellipsis-h");
diff --git a/test/javascripts/acceptance/create-account-external-test.js b/test/javascripts/acceptance/create-account-external-test.js
index cd64fe1..5feef45 100644
--- a/test/javascripts/acceptance/create-account-external-test.js
+++ b/test/javascripts/acceptance/create-account-external-test.js
@@ -30,8 +30,8 @@ QUnit.test("when skip is disabled (default)", async assert => {
   assert.ok(exists("#new-account-username"), "it shows the fields");
 });
 
-QUnit.test("when skip is enabled", async assert => {
-  Discourse.SiteSettings.external_auth_skip_create_confirm = true;
+QUnit.test("when skip is enabled", async function(assert) {
+  this.siteSettings.external_auth_skip_create_confirm = true;
   await visit("/");
 
   assert.ok(
diff --git a/test/javascripts/acceptance/email-notice-test.js b/test/javascripts/acceptance/email-notice-test.js
index 824b93c..2027bb7 100644
--- a/test/javascripts/acceptance/email-notice-test.js
+++ b/test/javascripts/acceptance/email-notice-test.js
@@ -4,22 +4,26 @@ acceptance("Email Disabled Banner", {
   loggedIn: true
 });
 
-QUnit.test("shows banner when required", async assert => {
-  Discourse.set("SiteSettings.disable_emails", "no");
+QUnit.test("when disabled", async function(assert) {
+  this.siteSettings.disable_emails = "no";
   await visit("/");
   assert.notOk(
     exists(".alert-emails-disabled"),
     "alert is not displayed when email enabled"
   );
+});
 
-  Discourse.set("SiteSettings.disable_emails", "yes");
+QUnit.test("when enabled", async function(assert) {
+  this.siteSettings.disable_emails = "yes";
   await visit("/latest");
   assert.ok(
     exists(".alert-emails-disabled"),
     "alert is displayed when email disabled"
   );
+});
 
-  Discourse.set("SiteSettings.disable_emails", "non-staff");
+QUnit.test("when non-staff", async function(assert) {
+  this.siteSettings.disable_emails = "non-staff";
   await visit("/");
   assert.ok(
     exists(".alert-emails-disabled"),
diff --git a/test/javascripts/acceptance/enforce-second-factor-test.js b/test/javascripts/acceptance/enforce-second-factor-test.js
index cd4570f..3a327be 100644
--- a/test/javascripts/acceptance/enforce-second-factor-test.js
+++ b/test/javascripts/acceptance/enforce-second-factor-test.js
@@ -12,9 +12,9 @@ acceptance("Enforce Second Factor", {
   }
 });
 
-QUnit.test("as an admin", async assert => {
+QUnit.test("as an admin", async function(assert) {
   await visit("/u/eviltrout/preferences/second-factor");
-  Discourse.SiteSettings.enforce_second_factor = "staff";
+  this.siteSettings.enforce_second_factor = "staff";
 
   await visit("/u/eviltrout/summary");
 
@@ -34,11 +34,11 @@ QUnit.test("as an admin", async assert => {
   );
 });
 
-QUnit.test("as a user", async assert => {
+QUnit.test("as a user", async function(assert) {
   updateCurrentUser({ moderator: false, admin: false });
 
   await visit("/u/eviltrout/preferences/second-factor");
-  Discourse.SiteSettings.enforce_second_factor = "all";
+  this.siteSettings.enforce_second_factor = "all";
 
   await visit("/u/eviltrout/summary");
 

[... diff too long, it was truncated ...]

GitHub sha: 5b276af9

1 Like

This commit appears in #10193 which was approved by jjaffeux. It was merged by eviltrout.