Files
KelvandGitHub ba2d6f9405 DEV: refactor setting object mixin to helper class (#30529)
This PR moves the logic from the setting-object mixin to a helper class. I've opted to maintain the interface of the previous classes (ThemeSettings / SiteSetting) that used the mixed-in methods through aliases so that we limit the amount of changes here (these are referenced in the string form and across classes/templates).

Another option we may consider in future if we want to optimize for performance is straight duplication which would trade off this overhead of aliasing/chaining calls through the helper for some duplicate code - only 2 models require these methods at the time of this PR.
2025-01-06 12:02:46 +08:00

55 lines
1.6 KiB
JavaScript

import EmberObject from "@ember/object";
import { setupTest } from "ember-qunit";
import { module, test } from "qunit";
import SettingObjectHelper from "admin/lib/setting-object-helper";
module("Unit | Lib | setting-object-helper", function (hooks) {
setupTest(hooks);
test("flat array", function (assert) {
const settingObj = EmberObject.create({
valid_values: ["foo", "bar"],
});
const helper = new SettingObjectHelper(settingObj);
assert.strictEqual(helper.computedValueProperty, null);
assert.strictEqual(helper.computedNameProperty, null);
});
test("object", function (assert) {
const settingObj = EmberObject.create({
valid_values: [{ value: "foo", name: "bar" }],
});
const helper = new SettingObjectHelper(settingObj);
assert.strictEqual(helper.computedValueProperty, "value");
assert.strictEqual(helper.computedNameProperty, "name");
});
test("no values", function (assert) {
const settingObj = EmberObject.create({
valid_values: [],
});
const helper = new SettingObjectHelper(settingObj);
assert.strictEqual(helper.computedValueProperty, null);
assert.strictEqual(helper.computedNameProperty, null);
});
test("value/name properties defined", function (assert) {
const settingObj = EmberObject.create({
valueProperty: "foo",
nameProperty: "bar",
valid_values: [],
});
const helper = new SettingObjectHelper(settingObj);
assert.strictEqual(helper.computedValueProperty, "foo");
assert.strictEqual(helper.computedNameProperty, "bar");
});
});