This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/unit/services/site-settings-test.js
Jarek Radosz 59f1d01381
DEV: Convert SiteSettings to a tracked object (#19015)
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>
2022-11-17 18:44:23 +01:00

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");
});
});