TrackedObject allows us to reference SiteSettings in autotracking contexts (e.g. JS getters referenced from a Glimmer template) without the need for EmberObject's `get()` function. TrackedObject is backwards-compatible with Ember's legacy reactivity model, so it can be referenced in things like computed properties. Co-authored-by: David Taylor <david@taylorhq.com>
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
import { module, test } from "qunit";
|
|
import { setupTest } from "ember-qunit";
|
|
import { getOwner } from "discourse-common/lib/get-owner";
|
|
import { inject as service } from "@ember/service";
|
|
import EmberObject, { computed } from "@ember/object";
|
|
|
|
class TestClass extends EmberObject {
|
|
@service siteSettings;
|
|
|
|
@computed("siteSettings.title")
|
|
get text() {
|
|
return `The title: ${this.siteSettings.title}`;
|
|
}
|
|
}
|
|
|
|
module("Unit | Service | site-settings", function (hooks) {
|
|
setupTest(hooks);
|
|
|
|
hooks.beforeEach(function () {
|
|
this.siteSettings = getOwner(this).lookup("service:site-settings");
|
|
});
|
|
|
|
test("contains settings", function (assert) {
|
|
assert.ok(this.siteSettings.title);
|
|
});
|
|
|
|
test("notifies getters", function (assert) {
|
|
this.siteSettings.title = "original";
|
|
|
|
getOwner(this).register("test-class:main", TestClass);
|
|
const object = getOwner(this).lookup("test-class:main");
|
|
assert.strictEqual(object.text, "The title: original");
|
|
|
|
this.siteSettings.title = "updated";
|
|
assert.strictEqual(object.text, "The title: updated");
|
|
});
|
|
});
|