DEV: Modulize component tests (#11300)

DEV: Modulize component tests (#11300)

It’s like the new tests, but still old underneath!

diff --git a/app/assets/javascripts/discourse/tests/helpers/component-test.js b/app/assets/javascripts/discourse/tests/helpers/component-test.js
index 5509343..e2edd2e 100644
--- a/app/assets/javascripts/discourse/tests/helpers/component-test.js
+++ b/app/assets/javascripts/discourse/tests/helpers/component-test.js
@@ -7,6 +7,31 @@ import Site from "discourse/models/site";
 import Session from "discourse/models/session";
 import { currentSettings } from "discourse/tests/helpers/site-settings";
 import { test } from "qunit";
+import { TestModuleForComponent } from "@ember/test-helpers";
+
+export function setupRenderingTest(hooks) {
+  let testModule;
+
+  hooks.before(function () {
+    const name = this.moduleName.split("|").pop();
+    testModule = new TestModuleForComponent(name, {
+      integration: true,
+    });
+  });
+
+  hooks.beforeEach(function () {
+    testModule.setContext(this);
+    return testModule.setup(...arguments);
+  });
+
+  hooks.afterEach(function () {
+    return testModule.teardown(...arguments);
+  });
+
+  hooks.after(function () {
+    testModule = null;
+  });
+}
 
 export default function (name, opts) {
   opts = opts || {};
diff --git a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js
index 7776186..09d8afa 100644
--- a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js
+++ b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js
@@ -113,6 +113,8 @@ export function discourseModule(name, options) {
         this.siteSettings = currentSettings();
       });
 
+      this.moduleName = name;
+
       options.call(this, hooks);
     });
 
diff --git a/app/assets/javascripts/discourse/tests/integration/components/ace-editor-test.js b/app/assets/javascripts/discourse/tests/integration/components/ace-editor-test.js
index 0896344..83f94cc 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/ace-editor-test.js
+++ b/app/assets/javascripts/discourse/tests/integration/components/ace-editor-test.js
@@ -1,53 +1,59 @@
-import { queryAll } from "discourse/tests/helpers/qunit-helpers";
-import componentTest from "discourse/tests/helpers/component-test";
-import { moduleForComponent } from "ember-qunit";
+import {
+  discourseModule,
+  queryAll,
+} from "discourse/tests/helpers/qunit-helpers";
+import componentTest, {
+  setupRenderingTest,
+} from "discourse/tests/helpers/component-test";
 
-moduleForComponent("ace-editor", { integration: true });
+discourseModule("Integration | Component | ace-editor", function (hooks) {
+  setupRenderingTest(hooks);
 
-componentTest("css editor", {
-  skip: true,
-  template: '{{ace-editor mode="css"}}',
-  test(assert) {
-    assert.expect(1);
-    assert.ok(queryAll(".ace_editor").length, "it renders the ace editor");
-  },
-});
+  componentTest("css editor", {
+    skip: true,
+    template: '{{ace-editor mode="css"}}',
+    test(assert) {
+      assert.expect(1);
+      assert.ok(queryAll(".ace_editor").length, "it renders the ace editor");
+    },
+  });
 
-componentTest("html editor", {
-  skip: true,
-  template: '{{ace-editor mode="html" content="<b>wat</b>"}}',
-  test(assert) {
-    assert.expect(1);
-    assert.ok(queryAll(".ace_editor").length, "it renders the ace editor");
-  },
-});
+  componentTest("html editor", {
+    skip: true,
+    template: '{{ace-editor mode="html" content="<b>wat</b>"}}',
+    test(assert) {
+      assert.expect(1);
+      assert.ok(queryAll(".ace_editor").length, "it renders the ace editor");
+    },
+  });
 
-componentTest("sql editor", {
-  skip: true,
-  template: '{{ace-editor mode="sql" content="SELECT * FROM users"}}',
-  test(assert) {
-    assert.expect(1);
-    assert.ok(queryAll(".ace_editor").length, "it renders the ace editor");
-  },
-});
+  componentTest("sql editor", {
+    skip: true,
+    template: '{{ace-editor mode="sql" content="SELECT * FROM users"}}',
+    test(assert) {
+      assert.expect(1);
+      assert.ok(queryAll(".ace_editor").length, "it renders the ace editor");
+    },
+  });
 
-componentTest("disabled editor", {
-  skip: true,
-  template:
-    '{{ace-editor mode="sql" content="SELECT * FROM users" disabled=true}}',
-  test(assert) {
-    const $ace = queryAll(".ace_editor");
-    assert.expect(3);
-    assert.ok($ace.length, "it renders the ace editor");
-    assert.equal(
-      $ace.parent().data().editor.getReadOnly(),
-      true,
-      "it sets ACE to read-only mode"
-    );
-    assert.equal(
-      $ace.parent().attr("data-disabled"),
-      "true",
-      "ACE wrapper has `data-disabled` attribute set to true"
-    );
-  },
+  componentTest("disabled editor", {
+    skip: true,
+    template:
+      '{{ace-editor mode="sql" content="SELECT * FROM users" disabled=true}}',
+    test(assert) {
+      const $ace = queryAll(".ace_editor");
+      assert.expect(3);
+      assert.ok($ace.length, "it renders the ace editor");
+      assert.equal(
+        $ace.parent().data().editor.getReadOnly(),
+        true,
+        "it sets ACE to read-only mode"
+      );
+      assert.equal(
+        $ace.parent().attr("data-disabled"),
+        "true",
+        "ACE wrapper has `data-disabled` attribute set to true"
+      );
+    },
+  });
 });
diff --git a/app/assets/javascripts/discourse/tests/integration/components/admin-report-test.js b/app/assets/javascripts/discourse/tests/integration/components/admin-report-test.js
index 7951b66..878c007 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/admin-report-test.js
+++ b/app/assets/javascripts/discourse/tests/integration/components/admin-report-test.js
@@ -1,173 +1,177 @@
-import { queryAll } from "discourse/tests/helpers/qunit-helpers";
-import { exists } from "discourse/tests/helpers/qunit-helpers";
-import { moduleForComponent } from "ember-qunit";
-import componentTest from "discourse/tests/helpers/component-test";
+import {
+  discourseModule,
+  exists,
+  queryAll,
+} from "discourse/tests/helpers/qunit-helpers";
+import componentTest, {
+  setupRenderingTest,
+} from "discourse/tests/helpers/component-test";
 import pretender from "discourse/tests/helpers/create-pretender";
 import { click } from "@ember/test-helpers";
 
-moduleForComponent("admin-report", {
-  integration: true,
-});
-
-componentTest("default", {
-  template: "{{admin-report dataSourceName='signups'}}",
-
-  async test(assert) {
-    assert.ok(exists(".admin-report.signups"));
-
-    assert.ok(exists(".admin-report.signups", "it defaults to table mode"));
-
-    assert.equal(
-      queryAll(".header .item.report").text().trim(),
-      "Signups",
-      "it has a title"
-    );
-
-    assert.equal(
-      queryAll(".header .info").attr("data-tooltip"),
-      "New account registrations for this period",
-      "it has a description"
-    );
-
-    assert.equal(
-      queryAll(".admin-report-table thead tr th:first-child .title")
-        .text()
-        .trim(),
-      "Day",
-      "it has col headers"
-    );
-
-    assert.equal(
-      queryAll(".admin-report-table thead tr th:nth-child(2) .title")
-        .text()
-        .trim(),
-      "Count",
-      "it has col headers"
-    );
-
-    assert.equal(
-      queryAll(".admin-report-table tbody tr:nth-child(1) td:nth-child(1)")
-        .text()
-        .trim(),
-      "June 16, 2018",
-      "it has rows"
-    );
-
-    assert.equal(
-      queryAll(".admin-report-table tbody tr:nth-child(1) td:nth-child(2)")
-        .text()
-        .trim(),
-      "12",
-      "it has rows"
-    );
-
-    assert.ok(exists(".total-row"), "it has totals");
-
-    await click(".admin-report-table-header.y .sort-btn");
-
-    assert.equal(
-      queryAll(".admin-report-table tbody tr:nth-child(1) td:nth-child(2)")
-        .text()
-        .trim(),
-      "7",
-      "it can sort rows"
-    );
-  },
-});
-
-componentTest("options", {

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

GitHub sha: dbcf722a

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