DEV: Clean up QUnit tests (#13328)

DEV: Clean up QUnit tests (#13328)

  • DEV: Use query helper instead of queryAll()[0]
  • DEV: Replace queryAll().length w/ exists()/count()
  • DEV: Use exists() instead of count() > 0, count() === 0
  • DEV: Use count()/exists() instead of find().length
diff --git a/app/assets/javascripts/discourse/tests/acceptance/account-created-test.js b/app/assets/javascripts/discourse/tests/acceptance/account-created-test.js
index fab4de4..0eac23b 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/account-created-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/account-created-test.js
@@ -60,7 +60,7 @@ acceptance("Account Created", function () {
     await click(".activation-controls .edit-email");
 
     assert.equal(currentRouteName(), "account-created.edit-email");
-    assert.ok(queryAll(".activation-controls .btn-primary:disabled").length);
+    assert.ok(exists(".activation-controls .btn-primary:disabled"));
 
     await click(".activation-controls .edit-cancel");
 
@@ -79,11 +79,11 @@ acceptance("Account Created", function () {
 
     await click(".activation-controls .edit-email");
 
-    assert.ok(queryAll(".activation-controls .btn-primary:disabled").length);
+    assert.ok(exists(".activation-controls .btn-primary:disabled"));
 
     await fillIn(".activate-new-email", "newemail@example.com");
 
-    assert.notOk(queryAll(".activation-controls .btn-primary:disabled").length);
+    assert.notOk(exists(".activation-controls .btn-primary:disabled"));
 
     await click(".activation-controls .btn-primary");
 
diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-search-log-term-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-search-log-term-test.js
index b4a9df1..6b4d080 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/admin-search-log-term-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/admin-search-log-term-test.js
@@ -8,7 +8,7 @@ acceptance("Admin - Search Log Term", function (needs) {
   test("show search log term details", async function (assert) {
     await visit("/admin/logs/search_logs/term?term=ruby");
 
-    assert.ok($("div.search-logs-filter").length, "has the search type filter");
+    assert.ok(exists("div.search-logs-filter"), "has the search type filter");
     assert.ok(exists("canvas.chartjs-render-monitor"), "has graph canvas");
     assert.ok(exists("div.header-search-results"), "has header search results");
   });
diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-search-logs-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-search-logs-test.js
index 9b19b29..8d63354 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/admin-search-logs-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/admin-search-logs-test.js
@@ -8,7 +8,7 @@ acceptance("Admin - Search Logs", function (needs) {
   test("show search logs", async function (assert) {
     await visit("/admin/logs/search_logs");
 
-    assert.ok($("table.search-logs-list.grid").length, "has the div class");
+    assert.ok(exists("table.search-logs-list.grid"), "has the div class");
 
     assert.ok(
       exists(".search-logs-list .admin-list-item .col"),
@@ -18,7 +18,7 @@ acceptance("Admin - Search Logs", function (needs) {
     await click(".term a");
 
     assert.ok(
-      $("div.search-logs-filter").length,
+      exists("div.search-logs-filter"),
       "it should show the search log term page"
     );
   });
diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-suspend-user-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-suspend-user-test.js
index 05a8a86..f9821d9 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/admin-suspend-user-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/admin-suspend-user-test.js
@@ -1,7 +1,8 @@
 import {
   acceptance,
+  count,
   exists,
-  queryAll,
+  query,
 } from "discourse/tests/helpers/qunit-helpers";
 import { click, fillIn, visit } from "@ember/test-helpers";
 import selectKit from "discourse/tests/helpers/select-kit-helper";
@@ -31,38 +32,39 @@ acceptance("Admin - Suspend User", function (needs) {
     await visit("/admin/users/1234/regular");
     await click(".suspend-user");
 
-    assert.equal(queryAll(".suspend-user-modal:visible").length, 1);
+    assert.equal(count(".suspend-user-modal:visible"), 1);
 
     await click(".d-modal-cancel");
 
-    assert.equal(queryAll(".suspend-user-modal:visible").length, 0);
+    assert.ok(!exists(".suspend-user-modal:visible"));
   });
 
   test("suspend a user - cancel with input", async function (assert) {
     await visit("/admin/users/1234/regular");
     await click(".suspend-user");
 
-    assert.equal(queryAll(".suspend-user-modal:visible").length, 1);
+    assert.equal(count(".suspend-user-modal:visible"), 1);
 
     await fillIn("input.suspend-reason", "for breaking the rules");
     await fillIn(".suspend-message", "this is an email reason why");
 
     await click(".d-modal-cancel");
 
-    assert.equal(queryAll(".bootbox.modal:visible").length, 1);
+    assert.equal(count(".bootbox.modal:visible"), 1);
 
     await click(".modal-footer .btn-default");
-    assert.equal(queryAll(".suspend-user-modal:visible").length, 1);
+    assert.equal(count(".suspend-user-modal:visible"), 1);
     assert.equal(
-      queryAll(".suspend-message")[0].value,
+      query(".suspend-message").value,
       "this is an email reason why"
     );
 
     await click(".d-modal-cancel");
-    assert.equal(queryAll(".bootbox.modal:visible").length, 1);
-    assert.equal(queryAll(".suspend-user-modal:visible").length, 0);
+    assert.equal(count(".bootbox.modal:visible"), 1);
+    assert.ok(!exists(".suspend-user-modal:visible"));
+
     await click(".modal-footer .btn-primary");
-    assert.equal(queryAll(".bootbox.modal:visible").length, 0);
+    assert.ok(!exists(".bootbox.modal:visible"));
   });
 
   test("suspend, then unsuspend a user", async function (assert) {
@@ -76,11 +78,7 @@ acceptance("Admin - Suspend User", function (needs) {
 
     await click(".suspend-user");
 
-    assert.equal(
-      queryAll(".perform-suspend[disabled]").length,
-      1,
-      "disabled by default"
-    );
+    assert.equal(count(".perform-suspend[disabled]"), 1, "disabled by default");
 
     await suspendUntilCombobox.expand();
     await suspendUntilCombobox.selectRowByValue("tomorrow");
@@ -88,15 +86,11 @@ acceptance("Admin - Suspend User", function (needs) {
     await fillIn("input.suspend-reason", "for breaking the rules");
     await fillIn(".suspend-message", "this is an email reason why");
 
-    assert.equal(
-      queryAll(".perform-suspend[disabled]").length,
-      0,
-      "no longer disabled"
-    );
+    assert.ok(!exists(".perform-suspend[disabled]"), "no longer disabled");
 
     await click(".perform-suspend");
 
-    assert.equal(queryAll(".suspend-user-modal:visible").length, 0);
+    assert.ok(!exists(".suspend-user-modal:visible"));
     assert.ok(exists(".suspension-info"));
 
     await click(".unsuspend-user");
diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-user-index-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-user-index-test.js
index 731c77c..296b876 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/admin-user-index-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/admin-user-index-test.js
@@ -1,4 +1,8 @@
-import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers";
+import {
+  acceptance,
+  exists,
+  queryAll,
+} from "discourse/tests/helpers/qunit-helpers";
 import { click, fillIn, visit } from "@ember/test-helpers";
 import selectKit from "discourse/tests/helpers/select-kit-helper";
 import { test } from "qunit";
@@ -81,9 +85,8 @@ acceptance("Admin - User Index", function (needs) {
       "the name should be correct"
     );
 
-    assert.equal(
-      queryAll('.group-chooser span[title="Macdonald"]').length,
-      0,
+    assert.ok(
+      !exists('.group-chooser span[title="Macdonald"]'),
       "group should not be set"
     );
   });

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

GitHub sha: 21e8a33177047e69f25c7103480c06ba8e23d01c

This commit appears in #13328 which was approved by eviltrout. It was merged by CvX.