From 263cd02a2769ce63e77a1ae3a77a592f01f187fd Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Thu, 22 Dec 2022 13:13:28 +0100 Subject: [PATCH] DEV: Get rid of all discourseModule uses (#19576) QUnit's `module` and `setupTest` is the way --- .../discourse/tests/unit/lib/computed-test.js | 49 +- .../tests/unit/lib/dom-from-string-test.js | 8 +- .../bookmark-reminder-test.js | 8 +- .../notification-types/granted-badge-test.js | 8 +- .../group-mentioned-test.js | 8 +- .../group-message-summary-test.js | 71 +- .../liked-consolidated-test.js | 8 +- .../unit/lib/notification-types/liked-test.js | 8 +- .../tests/unit/lib/plugin-api-test.js | 21 +- .../lib/reviewable-types/flagged-post-test.js | 8 +- .../lib/reviewable-types/queued-post-test.js | 8 +- .../tests/unit/lib/time-utils-test.js | 13 +- .../discourse/tests/unit/lib/uploads-test.js | 13 +- .../tests/unit/lib/utilities-test.js | 142 ++-- .../unit/models/topic-tracking-state-test.js | 755 +++++++++--------- .../tests/unit/utils/dom-utils-test.js | 48 +- 16 files changed, 599 insertions(+), 577 deletions(-) diff --git a/app/assets/javascripts/discourse/tests/unit/lib/computed-test.js b/app/assets/javascripts/discourse/tests/unit/lib/computed-test.js index 6bb55daa138..8c035ccadfb 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/computed-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/computed-test.js @@ -9,12 +9,15 @@ import { } from "discourse/lib/computed"; import EmberObject from "@ember/object"; import I18n from "I18n"; -import { discourseModule } from "discourse/tests/helpers/qunit-helpers"; import { setPrefix } from "discourse-common/lib/get-url"; import sinon from "sinon"; -import { test } from "qunit"; +import { module, test } from "qunit"; +import { setupTest } from "ember-qunit"; +import { getOwner } from "discourse-common/lib/get-owner"; + +module("Unit | Utility | computed", function (hooks) { + setupTest(hooks); -discourseModule("Unit | Utility | computed", function (hooks) { hooks.beforeEach(function () { sinon.stub(I18n, "t").callsFake(function (scope) { return "%@ translated: " + scope; @@ -26,20 +29,22 @@ discourseModule("Unit | Utility | computed", function (hooks) { }); test("setting", function (assert) { + const siteSettings = getOwner(this).lookup("service:site-settings"); + let t = EmberObject.extend({ - siteSettings: this.siteSettings, + siteSettings, vehicle: setting("vehicle"), missingProp: setting("madeUpThing"), }).create(); - this.siteSettings.vehicle = "airplane"; + siteSettings.vehicle = "airplane"; assert.strictEqual( - t.get("vehicle"), + t.vehicle, "airplane", "it has the value of the site setting" ); assert.ok( - !t.get("missingProp"), + !t.missingProp, "it is falsy when the site setting is not defined" ); }); @@ -52,9 +57,9 @@ discourseModule("Unit | Utility | computed", function (hooks) { biscuits: 10, }); - assert.ok(t.get("same"), "it is true when the properties are the same"); + assert.ok(t.same, "it is true when the properties are the same"); t.set("biscuits", 9); - assert.ok(!t.get("same"), "it isn't true when one property is different"); + assert.ok(!t.same, "it isn't true when one property is different"); }); test("propertyNotEqual", function (assert) { @@ -65,9 +70,9 @@ discourseModule("Unit | Utility | computed", function (hooks) { biscuits: 10, }); - assert.ok(!t.get("diff"), "it isn't true when the properties are the same"); + assert.ok(!t.diff, "it isn't true when the properties are the same"); t.set("biscuits", 9); - assert.ok(t.get("diff"), "it is true when one property is different"); + assert.ok(t.diff, "it is true when one property is different"); }); test("fmt", function (assert) { @@ -80,25 +85,25 @@ discourseModule("Unit | Utility | computed", function (hooks) { }); assert.strictEqual( - t.get("exclaimyUsername"), + t.exclaimyUsername, "!!! eviltrout !!!", "it inserts the string" ); assert.strictEqual( - t.get("multiple"), + t.multiple, "eviltrout is happy", "it inserts multiple strings" ); t.set("username", "codinghorror"); assert.strictEqual( - t.get("multiple"), + t.multiple, "codinghorror is happy", "it supports changing properties" ); t.set("mood", "ecstatic"); assert.strictEqual( - t.get("multiple"), + t.multiple, "codinghorror is ecstatic", "it supports changing another property" ); @@ -114,25 +119,25 @@ discourseModule("Unit | Utility | computed", function (hooks) { }); assert.strictEqual( - t.get("exclaimyUsername"), + t.exclaimyUsername, "%@ translated: !!! eviltrout !!!", "it inserts the string and then translates" ); assert.strictEqual( - t.get("multiple"), + t.multiple, "%@ translated: eviltrout is happy", "it inserts multiple strings and then translates" ); t.set("username", "codinghorror"); assert.strictEqual( - t.get("multiple"), + t.multiple, "%@ translated: codinghorror is happy", "it supports changing properties" ); t.set("mood", "ecstatic"); assert.strictEqual( - t.get("multiple"), + t.multiple, "%@ translated: codinghorror is ecstatic", "it supports changing another property" ); @@ -147,7 +152,7 @@ discourseModule("Unit | Utility | computed", function (hooks) { t = testClass.create({ username: "eviltrout" }); assert.strictEqual( - t.get("userUrl"), + t.userUrl, "/u/eviltrout", "it supports urls without a prefix" ); @@ -155,7 +160,7 @@ discourseModule("Unit | Utility | computed", function (hooks) { setPrefix("/prefixed"); t = testClass.create({ username: "eviltrout" }); assert.strictEqual( - t.get("userUrl"), + t.userUrl, "/prefixed/u/eviltrout", "it supports urls with a prefix" ); @@ -167,6 +172,6 @@ discourseModule("Unit | Utility | computed", function (hooks) { desc: htmlSafe("cookies"), }).create({ cookies }); - assert.strictEqual(t.get("desc").string, cookies); + assert.strictEqual(t.desc.string, cookies); }); }); diff --git a/app/assets/javascripts/discourse/tests/unit/lib/dom-from-string-test.js b/app/assets/javascripts/discourse/tests/unit/lib/dom-from-string-test.js index 0f64e388f3a..943dc812fae 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/dom-from-string-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/dom-from-string-test.js @@ -1,8 +1,10 @@ -import { discourseModule } from "discourse/tests/helpers/qunit-helpers"; -import { test } from "qunit"; +import { module, test } from "qunit"; import domFromString from "discourse-common/lib/dom-from-string"; +import { setupTest } from "ember-qunit"; + +module("Unit | Utility | domFromString", function (hooks) { + setupTest(hooks); -discourseModule("Unit | Utility | domFromString", function () { test("constructing DOM node from a string", function (assert) { const node = domFromString( '
foo
boo
' diff --git a/app/assets/javascripts/discourse/tests/unit/lib/notification-types/bookmark-reminder-test.js b/app/assets/javascripts/discourse/tests/unit/lib/notification-types/bookmark-reminder-test.js index 6bb309c15d3..938d8d937fd 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/notification-types/bookmark-reminder-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/notification-types/bookmark-reminder-test.js @@ -1,11 +1,11 @@ -import { discourseModule } from "discourse/tests/helpers/qunit-helpers"; -import { test } from "qunit"; +import { module, test } from "qunit"; import { NOTIFICATION_TYPES } from "discourse/tests/fixtures/concerns/notification-types"; import { deepMerge } from "discourse-common/lib/object"; import { createRenderDirector } from "discourse/tests/helpers/notification-types-helper"; import { htmlSafe } from "@ember/template"; import Notification from "discourse/models/notification"; import I18n from "I18n"; +import { setupTest } from "ember-qunit"; function getNotification(overrides = {}) { return Notification.create( @@ -33,7 +33,9 @@ function getNotification(overrides = {}) { ); } -discourseModule("Unit | Notification Types | bookmark-reminder", function () { +module("Unit | Notification Types | bookmark-reminder", function (hooks) { + setupTest(hooks); + test("linkTitle", function (assert) { const notification = getNotification({ data: { bookmark_name: "My awesome bookmark" }, diff --git a/app/assets/javascripts/discourse/tests/unit/lib/notification-types/granted-badge-test.js b/app/assets/javascripts/discourse/tests/unit/lib/notification-types/granted-badge-test.js index 187fbe52ed6..ec9675b00ee 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/notification-types/granted-badge-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/notification-types/granted-badge-test.js @@ -1,10 +1,10 @@ -import { discourseModule } from "discourse/tests/helpers/qunit-helpers"; -import { test } from "qunit"; +import { module, test } from "qunit"; import { NOTIFICATION_TYPES } from "discourse/tests/fixtures/concerns/notification-types"; import { deepMerge } from "discourse-common/lib/object"; import { createRenderDirector } from "discourse/tests/helpers/notification-types-helper"; import Notification from "discourse/models/notification"; import I18n from "I18n"; +import { setupTest } from "ember-qunit"; function getNotification(overrides = {}) { return Notification.create( @@ -28,7 +28,9 @@ function getNotification(overrides = {}) { ); } -discourseModule("Unit | Notification Types | granted-badge", function () { +module("Unit | Notification Types | granted-badge", function (hooks) { + setupTest(hooks); + test("linkHref", function (assert) { const notification = getNotification(); const director = createRenderDirector( diff --git a/app/assets/javascripts/discourse/tests/unit/lib/notification-types/group-mentioned-test.js b/app/assets/javascripts/discourse/tests/unit/lib/notification-types/group-mentioned-test.js index 15069ea717e..f29412c719f 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/notification-types/group-mentioned-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/notification-types/group-mentioned-test.js @@ -1,9 +1,9 @@ -import { discourseModule } from "discourse/tests/helpers/qunit-helpers"; -import { test } from "qunit"; +import { module, test } from "qunit"; import { NOTIFICATION_TYPES } from "discourse/tests/fixtures/concerns/notification-types"; import { deepMerge } from "discourse-common/lib/object"; import { createRenderDirector } from "discourse/tests/helpers/notification-types-helper"; import Notification from "discourse/models/notification"; +import { setupTest } from "ember-qunit"; function getNotification(overrides = {}) { return Notification.create( @@ -34,7 +34,9 @@ function getNotification(overrides = {}) { ); } -discourseModule("Unit | Notification Types | group-mentioned", function () { +module("Unit | Notification Types | group-mentioned", function (hooks) { + setupTest(hooks); + test("label", function (assert) { const notification = getNotification(); const director = createRenderDirector( diff --git a/app/assets/javascripts/discourse/tests/unit/lib/notification-types/group-message-summary-test.js b/app/assets/javascripts/discourse/tests/unit/lib/notification-types/group-message-summary-test.js index f55531423f0..e39012d78c2 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/notification-types/group-message-summary-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/notification-types/group-message-summary-test.js @@ -1,10 +1,10 @@ -import { discourseModule } from "discourse/tests/helpers/qunit-helpers"; -import { test } from "qunit"; +import { module, test } from "qunit"; import { NOTIFICATION_TYPES } from "discourse/tests/fixtures/concerns/notification-types"; import { deepMerge } from "discourse-common/lib/object"; import { createRenderDirector } from "discourse/tests/helpers/notification-types-helper"; import Notification from "discourse/models/notification"; import I18n from "I18n"; +import { setupTest } from "ember-qunit"; function getNotification(overrides = {}) { return Notification.create( @@ -28,38 +28,37 @@ function getNotification(overrides = {}) { ); } -discourseModule( - "Unit | Notification Types | group-message-summary", - function () { - test("description", function (assert) { - const notification = getNotification(); - const director = createRenderDirector( - notification, - "group_message_summary", - this.siteSettings - ); - assert.strictEqual( - director.description, - I18n.t("notifications.group_message_summary", { - group_name: "drummers", - count: 13, - }), - "displays the right content" - ); - }); +module("Unit | Notification Types | group-message-summary", function (hooks) { + setupTest(hooks); - test("linkHref", function (assert) { - const notification = getNotification(); - const director = createRenderDirector( - notification, - "group_message_summary", - this.siteSettings - ); - assert.strictEqual( - director.linkHref, - "/u/drummers.boss/messages/group/drummers", - "links to the group inbox in the user profile" - ); - }); - } -); + test("description", function (assert) { + const notification = getNotification(); + const director = createRenderDirector( + notification, + "group_message_summary", + this.siteSettings + ); + assert.strictEqual( + director.description, + I18n.t("notifications.group_message_summary", { + group_name: "drummers", + count: 13, + }), + "displays the right content" + ); + }); + + test("linkHref", function (assert) { + const notification = getNotification(); + const director = createRenderDirector( + notification, + "group_message_summary", + this.siteSettings + ); + assert.strictEqual( + director.linkHref, + "/u/drummers.boss/messages/group/drummers", + "links to the group inbox in the user profile" + ); + }); +}); diff --git a/app/assets/javascripts/discourse/tests/unit/lib/notification-types/liked-consolidated-test.js b/app/assets/javascripts/discourse/tests/unit/lib/notification-types/liked-consolidated-test.js index c42c279f7ee..1e0bb9e1975 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/notification-types/liked-consolidated-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/notification-types/liked-consolidated-test.js @@ -1,10 +1,10 @@ -import { discourseModule } from "discourse/tests/helpers/qunit-helpers"; -import { test } from "qunit"; +import { module, test } from "qunit"; import { NOTIFICATION_TYPES } from "discourse/tests/fixtures/concerns/notification-types"; import { deepMerge } from "discourse-common/lib/object"; import { createRenderDirector } from "discourse/tests/helpers/notification-types-helper"; import Notification from "discourse/models/notification"; import I18n from "I18n"; +import { setupTest } from "ember-qunit"; function getNotification(overrides = {}) { return Notification.create( @@ -31,7 +31,9 @@ function getNotification(overrides = {}) { ); } -discourseModule("Unit | Notification Types | liked-consolidated", function () { +module("Unit | Notification Types | liked-consolidated", function (hooks) { + setupTest(hooks); + test("linkHref", function (assert) { const notification = getNotification(); const director = createRenderDirector( diff --git a/app/assets/javascripts/discourse/tests/unit/lib/notification-types/liked-test.js b/app/assets/javascripts/discourse/tests/unit/lib/notification-types/liked-test.js index 7eac2647854..441e147ac4b 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/notification-types/liked-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/notification-types/liked-test.js @@ -1,10 +1,10 @@ -import { discourseModule } from "discourse/tests/helpers/qunit-helpers"; -import { test } from "qunit"; +import { module, test } from "qunit"; import { NOTIFICATION_TYPES } from "discourse/tests/fixtures/concerns/notification-types"; import { deepMerge } from "discourse-common/lib/object"; import { createRenderDirector } from "discourse/tests/helpers/notification-types-helper"; import Notification from "discourse/models/notification"; import I18n from "I18n"; +import { setupTest } from "ember-qunit"; function getNotification(overrides = {}) { return Notification.create( @@ -33,7 +33,9 @@ function getNotification(overrides = {}) { ); } -discourseModule("Unit | Notification Types | liked", function () { +module("Unit | Notification Types | liked", function (hooks) { + setupTest(hooks); + test("label", function (assert) { const notification = getNotification(); const director = createRenderDirector( diff --git a/app/assets/javascripts/discourse/tests/unit/lib/plugin-api-test.js b/app/assets/javascripts/discourse/tests/unit/lib/plugin-api-test.js index a8b6b8f5d52..7465a51bb22 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/plugin-api-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/plugin-api-test.js @@ -1,10 +1,13 @@ -import { discourseModule } from "discourse/tests/helpers/qunit-helpers"; -import { test } from "qunit"; +import { module, test } from "qunit"; import EmberObject from "@ember/object"; import discourseComputed from "discourse-common/utils/decorators"; import { withPluginApi } from "discourse/lib/plugin-api"; +import { setupTest } from "ember-qunit"; +import { getOwner } from "discourse-common/lib/get-owner"; + +module("Unit | Utility | plugin-api", function (hooks) { + setupTest(hooks); -discourseModule("Unit | Utility | plugin-api", function () { test("modifyClass works with classic Ember objects", function (assert) { const TestThingy = EmberObject.extend({ @discourseComputed @@ -13,7 +16,7 @@ discourseModule("Unit | Utility | plugin-api", function () { }, }); - this.registry.register("test-thingy:main", TestThingy); + getOwner(this).register("test-thingy:main", TestThingy); withPluginApi("1.1.0", (api) => { api.modifyClass("test-thingy:main", { @@ -26,7 +29,7 @@ discourseModule("Unit | Utility | plugin-api", function () { }); }); - const thingy = this.container.lookup("test-thingy:main"); + const thingy = getOwner(this).lookup("test-thingy:main"); assert.strictEqual(thingy.prop, "hello there"); }); @@ -38,7 +41,7 @@ discourseModule("Unit | Utility | plugin-api", function () { } } - this.registry.register("native-test-thingy:main", NativeTestThingy); + getOwner(this).register("native-test-thingy:main", NativeTestThingy); withPluginApi("1.1.0", (api) => { api.modifyClass("native-test-thingy:main", { @@ -51,7 +54,7 @@ discourseModule("Unit | Utility | plugin-api", function () { }); }); - const thingy = this.container.lookup("native-test-thingy:main"); + const thingy = getOwner(this).lookup("native-test-thingy:main"); assert.strictEqual(thingy.prop, "howdy partner"); }); @@ -66,7 +69,7 @@ discourseModule("Unit | Utility | plugin-api", function () { } } - this.registry.register("class-test-thingy:main", new ClassTestThingy(), { + getOwner(this).register("class-test-thingy:main", new ClassTestThingy(), { instantiate: false, }); @@ -80,7 +83,7 @@ discourseModule("Unit | Utility | plugin-api", function () { }); }); - const thingy = this.container.lookup("class-test-thingy:main"); + const thingy = getOwner(this).lookup("class-test-thingy:main"); assert.strictEqual(thingy.keep, "hey!"); assert.strictEqual(thingy.prop, "g'day"); }); diff --git a/app/assets/javascripts/discourse/tests/unit/lib/reviewable-types/flagged-post-test.js b/app/assets/javascripts/discourse/tests/unit/lib/reviewable-types/flagged-post-test.js index 7a075ca768f..8f93ebec9a3 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/reviewable-types/flagged-post-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/reviewable-types/flagged-post-test.js @@ -1,10 +1,10 @@ -import { discourseModule } from "discourse/tests/helpers/qunit-helpers"; -import { test } from "qunit"; +import { module, test } from "qunit"; import { createRenderDirector } from "discourse/tests/helpers/reviewable-types-helper"; import { htmlSafe } from "@ember/template"; import { emojiUnescape } from "discourse/lib/text"; import UserMenuReviewable from "discourse/models/user-menu-reviewable"; import I18n from "I18n"; +import { setupTest } from "ember-qunit"; function getReviewable(overrides = {}) { return UserMenuReviewable.create( @@ -22,7 +22,9 @@ function getReviewable(overrides = {}) { ); } -discourseModule("Unit | Reviewable Items | flagged-post", function () { +module("Unit | Reviewable Items | flagged-post", function (hooks) { + setupTest(hooks); + test("description", function (assert) { const reviewable = getReviewable({ topic_fancy_title: "This is safe title <a> :heart:", diff --git a/app/assets/javascripts/discourse/tests/unit/lib/reviewable-types/queued-post-test.js b/app/assets/javascripts/discourse/tests/unit/lib/reviewable-types/queued-post-test.js index 955969fd466..5c6ecc29fc1 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/reviewable-types/queued-post-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/reviewable-types/queued-post-test.js @@ -1,10 +1,10 @@ -import { discourseModule } from "discourse/tests/helpers/qunit-helpers"; -import { test } from "qunit"; +import { module, test } from "qunit"; import { createRenderDirector } from "discourse/tests/helpers/reviewable-types-helper"; import { htmlSafe } from "@ember/template"; import { emojiUnescape } from "discourse/lib/text"; import UserMenuReviewable from "discourse/models/user-menu-reviewable"; import I18n from "I18n"; +import { setupTest } from "ember-qunit"; function getReviewable(overrides = {}) { return UserMenuReviewable.create( @@ -21,7 +21,9 @@ function getReviewable(overrides = {}) { ); } -discourseModule("Unit | Reviewable Items | queued-post", function () { +module("Unit | Reviewable Items | queued-post", function (hooks) { + setupTest(hooks); + test("description", function (assert) { const reviewable = getReviewable({ topic_fancy_title: "This is safe title <a> :heart:", diff --git a/app/assets/javascripts/discourse/tests/unit/lib/time-utils-test.js b/app/assets/javascripts/discourse/tests/unit/lib/time-utils-test.js index c2a7bbc4e49..8e078392e5d 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/time-utils-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/time-utils-test.js @@ -1,8 +1,4 @@ -import { - discourseModule, - withFrozenTime, -} from "discourse/tests/helpers/qunit-helpers"; - +import { withFrozenTime } from "discourse/tests/helpers/qunit-helpers"; import { laterThisWeek, laterToday, @@ -10,11 +6,14 @@ import { startOfDay, tomorrow, } from "discourse/lib/time-utils"; -import { test } from "qunit"; +import { module, test } from "qunit"; +import { setupTest } from "ember-qunit"; const timezone = "Australia/Brisbane"; -discourseModule("Unit | lib | timeUtils", function () { +module("Unit | lib | timeUtils", function (hooks) { + setupTest(hooks); + test("nextMonth gets next month correctly", function (assert) { withFrozenTime("2019-12-11T08:00:00", timezone, () => { assert.strictEqual( diff --git a/app/assets/javascripts/discourse/tests/unit/lib/uploads-test.js b/app/assets/javascripts/discourse/tests/unit/lib/uploads-test.js index c6d632748a3..bede514d279 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/uploads-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/uploads-test.js @@ -11,11 +11,18 @@ import { } from "discourse/lib/uploads"; import I18n from "I18n"; import User from "discourse/models/user"; -import { discourseModule } from "discourse/tests/helpers/qunit-helpers"; import sinon from "sinon"; -import { test } from "qunit"; +import { module, test } from "qunit"; +import { setupTest } from "ember-qunit"; +import { getOwner } from "discourse-common/lib/get-owner"; + +module("Unit | Utility | uploads", function (hooks) { + setupTest(hooks); + + hooks.beforeEach(function () { + this.siteSettings = getOwner(this).lookup("service:site-settings"); + }); -discourseModule("Unit | Utility | uploads", function () { test("validateUploadedFiles", function (assert) { assert.notOk( validateUploadedFiles(null, { siteSettings: this.siteSettings }), diff --git a/app/assets/javascripts/discourse/tests/unit/lib/utilities-test.js b/app/assets/javascripts/discourse/tests/unit/lib/utilities-test.js index 6473b7e4425..281ae9b189f 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/utilities-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/utilities-test.js @@ -1,4 +1,3 @@ -import { Promise } from "rsvp"; import { avatarImg, avatarUrl, @@ -20,18 +19,19 @@ import { toAsciiPrintable, } from "discourse/lib/utilities"; import sinon from "sinon"; -import { test } from "qunit"; +import { module, test } from "qunit"; import Handlebars from "handlebars"; -import { - chromeTest, - discourseModule, -} from "discourse/tests/helpers/qunit-helpers"; +import { chromeTest } from "discourse/tests/helpers/qunit-helpers"; import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { click, render } from "@ember/test-helpers"; import { hbs } from "ember-cli-htmlbars"; import { setupURL } from "discourse-common/lib/get-url"; +import { setupTest } from "ember-qunit"; +import { getOwner } from "discourse-common/lib/get-owner"; + +module("Unit | Utilities", function (hooks) { + setupTest(hooks); -discourseModule("Unit | Utilities", function () { test("escapeExpression", function (assert) { assert.strictEqual( escapeExpression(">"), @@ -161,7 +161,10 @@ discourseModule("Unit | Utilities", function () { meta.name = "discourse_current_homepage"; meta.content = "hot"; document.body.appendChild(meta); - initializeDefaultHomepage(this.siteSettings); + + const siteSettings = getOwner(this).lookup("service:site-settings"); + initializeDefaultHomepage(siteSettings); + assert.strictEqual( defaultHomepage(), "hot", @@ -171,8 +174,10 @@ discourseModule("Unit | Utilities", function () { }); test("defaultHomepage via site settings", function (assert) { - this.siteSettings.top_menu = "top|latest|hot"; - initializeDefaultHomepage(this.siteSettings); + const siteSettings = getOwner(this).lookup("service:site-settings"); + siteSettings.top_menu = "top|latest|hot"; + initializeDefaultHomepage(siteSettings); + assert.strictEqual( defaultHomepage(), "top", @@ -181,8 +186,11 @@ discourseModule("Unit | Utilities", function () { }); test("setDefaultHomepage", function (assert) { - initializeDefaultHomepage(this.siteSettings); + const siteSettings = getOwner(this).lookup("service:site-settings"); + initializeDefaultHomepage(siteSettings); + assert.strictEqual(defaultHomepage(), "latest"); + setDefaultHomepage("top"); assert.strictEqual(defaultHomepage(), "top"); }); @@ -346,75 +354,71 @@ discourseModule("Unit | Utilities", function () { "it correctly merges lists that share common items" ); }); +}); - discourseModule("modKeysPressed", function (hooks) { - setupRenderingTest(hooks); +module("Unit | Utilities | modKeysPressed", function (hooks) { + setupRenderingTest(hooks); - test("returns an array of modifier keys pressed during keyboard or mouse event", async function (assert) { - let i = 0; + test("returns an array of modifier keys pressed during keyboard or mouse event", async function (assert) { + let i = 0; - this.handleClick = (event) => { - if (i === 0) { - assert.deepEqual(modKeysPressed(event), []); - } else if (i === 1) { - assert.deepEqual(modKeysPressed(event), ["alt"]); - } else if (i === 2) { - assert.deepEqual(modKeysPressed(event), ["shift"]); - } else if (i === 3) { - assert.deepEqual(modKeysPressed(event), ["meta"]); - } else if (i === 4) { - assert.deepEqual(modKeysPressed(event), ["ctrl"]); - } else if (i === 5) { - assert.deepEqual(modKeysPressed(event), [ - "alt", - "shift", - "meta", - "ctrl", - ]); - } - }; + this.handleClick = (event) => { + if (i === 0) { + assert.deepEqual(modKeysPressed(event), []); + } else if (i === 1) { + assert.deepEqual(modKeysPressed(event), ["alt"]); + } else if (i === 2) { + assert.deepEqual(modKeysPressed(event), ["shift"]); + } else if (i === 3) { + assert.deepEqual(modKeysPressed(event), ["meta"]); + } else if (i === 4) { + assert.deepEqual(modKeysPressed(event), ["ctrl"]); + } else if (i === 5) { + assert.deepEqual(modKeysPressed(event), [ + "alt", + "shift", + "meta", + "ctrl", + ]); + } + }; - await render(hbs`