Skip to content

A platform for community discussion. Free, open, simple.

DEV: Convert 9 components to glimmer (#44570)

Jarek Radosz3279b67fba94
diff --git a/frontend/discourse/admin/components/site-settings/enum.gjs b/frontend/discourse/admin/components/site-settings/enum.gjs
index c39a640b792..f4f7cad5e37 100644
--- a/frontend/discourse/admin/components/site-settings/enum.gjs
+++ b/frontend/discourse/admin/components/site-settings/enum.gjs
@@ -1,27 +1,23 @@
-/* eslint-disable ember/no-classic-components */
-import Component from "@ember/component";
-import { fn, hash } from "@ember/helper";
-import { tagName } from "@ember-decorators/component";
+import { hash } from "@ember/helper";
import ComboBox from "discourse/select-kit/components/combo-box";
-@tagName("")
-export default class Enum extends Component {
- <template>
- <div ...attributes>
- <ComboBox
- @content={{this.setting.validValues}}
- @nameProperty={{this.setting.computedNameProperty}}
- @onChange={{fn (mut this.value)}}
- @options={{hash
- castInteger=true
- allowAny=this.setting.allowsNone
- disabled=@disabled
- }}
- @value={{this.value}}
- @valueProperty={{this.setting.computedValueProperty}}
- />
+const Enum = <template>
+ <div ...attributes>
+ <ComboBox
+ @content={{@setting.validValues}}
+ @nameProperty={{@setting.computedNameProperty}}
+ @onChange={{@changeValueCallback}}
+ @options={{hash
+ castInteger=true
+ disabled=@disabled
+ }}
+ @value={{@value}}
+ @valueProperty={{@setting.computedValueProperty}}
+ />
- {{this.preview}}
- </div>
- </template>
-}
+ {{@preview}}
+ </div>
+</template>;
+
+export default Enum;
diff --git a/frontend/discourse/admin/components/site-settings/group-list.gjs b/frontend/discourse/admin/components/site-settings/group-list.gjs
index 6b36690e0de..cef1df7e923 100644
--- a/frontend/discourse/admin/components/site-settings/group-list.gjs
+++ b/frontend/discourse/admin/components/site-settings/group-list.gjs
@@ -1,29 +1,22 @@
-/* eslint-disable ember/no-classic-components */
-import Component from "@ember/component";
-import { action, computed } from "@ember/object";
+import Component from "@glimmer/component";
+import { action } from "@ember/object";
import { service } from "@ember/service";
-import { tagName } from "@ember-decorators/component";
import {
mapEveryoneToLoggedInUsersIds,
mapLoggedInUsersToEveryoneForStorage,
} from "discourse/lib/group-list-setting-aliasing";
import ListSetting from "discourse/select-kit/components/list-setting";
-@tagName("")
export default class GroupList extends Component {
+ @service site;
@service siteSettings;
tokenSeparator = "|";
nameProperty = "name";
valueProperty = "id";
- @computed(
- "site.groups",
- "setting.disallowed_groups",
- "siteSettings.granular_anonymous_and_logged_in_groups_permissions"
- )
get groupChoices() {
- const disallowed = (this.setting?.disallowed_groups || "")
+ const disallowed = (this.args.setting?.disallowed_groups || "")
.split("|")
.filter(Boolean);
const groups = (this.site.groups || []).filter(
@@ -47,12 +40,10 @@ export default class GroupList extends Component {
.filter(Boolean);
}
- @computed(
- "value",
- "siteSettings.granular_anonymous_and_logged_in_groups_permissions"
- )
get settingValue() {
- const ids = (this.value || "").split(this.tokenSeparator).filter(Boolean);
+ const ids = (this.args.value || "")
+ .split(this.tokenSeparator)
+ .filter(Boolean);
return mapEveryoneToLoggedInUsersIds(
ids,
this.siteSettings.granular_anonymous_and_logged_in_groups_permissions
@@ -64,23 +55,18 @@ export default class GroupList extends Component {
const ids = mapLoggedInUsersToEveryoneForStorage(
value,
this.siteSettings.granular_anonymous_and_logged_in_groups_permissions,
- this.setting?.value,
+ this.args.setting?.value,
this.tokenSeparator
);
- const storedValue = ids.join(this.tokenSeparator);
- if (this.changeValueCallback) {
- this.changeValueCallback(storedValue);
- } else {
- this.set("value", storedValue);
- }
+ this.args.changeValueCallback(ids.join(this.tokenSeparator));
}
<template>
<div ...attributes>
<ListSetting
@choices={{this.groupChoices}}
- @mandatoryValues={{this.setting.mandatory_values}}
+ @mandatoryValues={{@setting.mandatory_values}}
@nameProperty={{this.nameProperty}}
@onChange={{this.onChangeGroupListSetting}}
@settingName="name"
diff --git a/frontend/discourse/admin/components/site-settings/host-list.gjs b/frontend/discourse/admin/components/site-settings/host-list.gjs
index 34b8a81c8e8..28349457b59 100644
--- a/frontend/discourse/admin/components/site-settings/host-list.gjs
+++ b/frontend/discourse/admin/components/site-settings/host-list.gjs
@@ -1,18 +1,16 @@
-/* eslint-disable ember/no-classic-components */
-import Component from "@ember/component";
+import Component from "@glimmer/component";
import { hash } from "@ember/helper";
-import { action, computed } from "@ember/object";
-import { tagName } from "@ember-decorators/component";
+import { action } from "@ember/object";
import ListSetting from "discourse/select-kit/components/list-setting";
-@tagName("")
export default class HostList extends Component {
tokenSeparator = "|";
- choices = null;
- @computed("value")
get settingValue() {
- return this.value.toString().split(this.tokenSeparator).filter(Boolean);
+ return this.args.value
+ .toString()
+ .split(this.tokenSeparator)
+ .filter(Boolean);
}
@action
@@ -21,7 +19,7 @@ export default class HostList extends Component {
return;
}
- this.set("value", value.join(this.tokenSeparator));
+ this.args.changeValueCallback(value.join(this.tokenSeparator));
}
<template>
@@ -29,8 +27,8 @@ export default class HostList extends Component {
<ListSetting
@choices={{this.settingValue}}
@onChange={{this.onChange}}
- @options={{hash allowAny=this.allowAny disabled=@disabled}}
- @settingName={{this.setting.setting}}
+ @options={{hash allowAny=@allowAny disabled=@disabled}}
+ @settingName={{@setting.setting}}
@value={{this.settingValue}}
/>
</div>
diff --git a/frontend/discourse/admin/components/site-settings/named-list.gjs b/frontend/discourse/admin/components/site-settings/named-list.gjs
index 87efbe9398c..36841c8724a 100644
--- a/frontend/discourse/admin/components/site-settings/named-list.gjs
+++ b/frontend/discourse/admin/components/site-settings/named-list.gjs
@@ -1,22 +1,20 @@
-/* eslint-disable ember/no-classic-components */
-import Component from "@ember/component";
+import Component from "@glimmer/component";
import { hash } from "@ember/helper";
-import { action, computed } from "@ember/object";
-import { tagName } from "@ember-decorators/component";
+import { action } from "@ember/object";
import ListSetting from "discourse/select-kit/components/list-setting";
-@tagName("")
export default class NamedList extends Component {
tokenSeparator = "|";
- @computed("value")
get settingValue() {
- return this.value.toString().split(this.tokenSeparator).filter(Boolean);
+ return this.args.value
+ .toString()
+ .split(this.tokenSeparator)
+ .filter(Boolean);
}
- @computed("setting.choices.[]", "settingValue")
get settingChoices() {
- let choices = this.setting.choices;
+ let choices = this.args.setting.choices;
if (this.settingValue) {
const valuesSet = new Set(choices.map((choice) => choice.value));
@@ -33,7 +31,7 @@ export default class NamedList extends Component {
@action
onChangeListSetting(value) {
- this.set("value", value.join(this.tokenSeparator));
+ this.args.changeValueCallback(value.join(this.tokenSeparator));
}
<template>
@@ -42,8 +40,8 @@ export default class NamedList extends Component {
@choices={{this.settingChoices}}
@nameProperty="name"
@onChange={{this.onChangeListSetting}}
- @options={{hash allowAny=this.allowAny}}
- @settingName={{this.setting.setting}}
+ @options={{hash allowAny=@allowAny}}
+ @settingName={{@setting.setting}}
@value={{this.settingValue}}
@valueProperty="value"
/>
diff --git a/frontend/discourse/admin/components/site-settings/simple-list.gjs b/frontend/discourse/admin/components/site-settings/simple-list.gjs
index 41bf612a4ab..acf75e1c690 100644
--- a/frontend/discourse/admin/components/site-settings/simple-list.gjs
+++ b/frontend/discourse/admin/components/site-settings/simple-list.gjs
@@ -1,26 +1,23 @@
-/* eslint-disable ember/no-classic-components */
-import Component from "@ember/component";
+import Component from "@glimmer/component";
import { action } from "@ember/object";
-import { tagName } from "@ember-decorators/component";
import SimpleList from "discourse/admin/components/simple-list";
-@tagName("")
export default class SiteSettingSimpleList extends Component {
inputDelimiter = "|";
@action
onChange(value) {
- this.set("value", value.join(this.inputDelimiter || "\n"));
+ this.args.changeValueCallback(value.join(this.inputDelimiter || "\n"));
}
<template>
<div ...attributes>
<SimpleList
- @allowAny={{this.setting.allow_any}}
- @choices={{this.setting.choices}}
+ @allowAny={{@setting.allow_any}}
+ @choices={{@setting.choices}}
@inputDelimiter={{this.inputDelimiter}}
@onChange={{this.onChange}}
- @values={{this.value}}
+ @values={{@value}}
/>
</div>
</template>
diff --git a/frontend/discourse/admin/components/site-settings/tag-group-list.gjs b/frontend/discourse/admin/components/site-settings/tag-group-list.gjs
index 4087dcb4c04..9d1737feba9 100644
--- a/frontend/discourse/admin/components/site-settings/tag-group-list.gjs
+++ b/frontend/discourse/admin/components/site-settings/tag-group-list.gjs
@@ -1,20 +1,16 @@
-/* eslint-disable ember/no-classic-components */
-import Component from "@ember/component";
+import Component from "@glimmer/component";
import { hash } from "@ember/helper";
-import { action, computed } from "@ember/object";
-import { tagName } from "@ember-decorators/component";
+import { action } from "@ember/object";
import TagGroupChooser from "discourse/select-kit/components/tag-group-chooser";
-@tagName("")
export default class TagGroupList extends Component {
- @computed("value")
get selectedTagGroups() {
- return this.value.split("|").filter(Boolean);
+ return this.args.value.split("|").filter(Boolean);
}
@action
onTagGroupChange(tagGroups) {
- this.set("value", tagGroups.join("|"));
+ this.args.changeValueCallback(tagGroups.join("|"));
}
<template>
diff --git a/frontend/discourse/admin/components/site-settings/tag-list.gjs b/frontend/discourse/admin/components/site-settings/tag-list.gjs
index ee2f9ece336..b61a220b0b5 100644
--- a/frontend/discourse/admin/components/site-settings/tag-list.gjs
+++ b/frontend/discourse/admin/components/site-settings/tag-list.gjs
@@ -1,20 +1,16 @@
-/* eslint-disable ember/no-classic-components */
-import Component from "@ember/component";
+import Component from "@glimmer/component";
import { hash } from "@ember/helper";
-import { action, computed } from "@ember/object";
-import { tagName } from "@ember-decorators/component";
+import { action } from "@ember/object";
import TagChooser from "discourse/select-kit/components/tag-chooser";
-@tagName("")
export default class TagList extends Component {
- @computed("value")
get selectedTags() {
- return this.value.split("|").filter(Boolean);
+ return this.args.value.split("|").filter(Boolean);
}
@action
changeSelectedTags(tags) {
- this.set("value", tags.map((t) => t.name).join("|"));
+ this.args.changeValueCallback(tags.map((t) => t.name).join("|"));
}
<template>
diff --git a/frontend/discourse/admin/components/site-settings/url-list.gjs b/frontend/discourse/admin/components/site-settings/url-list.gjs
index d3dc0c6a30d..c8bb19fb444 100644
--- a/frontend/discourse/admin/components/site-settings/url-list.gjs
+++ b/frontend/discourse/admin/components/site-settings/url-list.gjs
@@ -1,16 +1,20 @@
-/* eslint-disable ember/no-classic-components */
-import Component from "@ember/component";
-import { tagName } from "@ember-decorators/component";
+import Component from "@glimmer/component";
+import { action } from "@ember/object";
import ValueList from "discourse/admin/components/value-list";
-@tagName("")
export default class UrlList extends Component {
+ @action
+ onChange(values) {
+ this.args.changeValueCallback(values.join("\n"));
+ }
+
<template>
<div ...attributes>
<ValueList
@addKey="admin.site_settings.add_url"
@disabled={{@disabled}}
- @values={{this.value}}
+ @onChange={{this.onChange}}
+ @values={{@value}}
/>
</div>
</template>
diff --git a/frontend/discourse/admin/components/site-settings/value-list.gjs b/frontend/discourse/admin/components/site-settings/value-list.gjs
index 9d343935909..620d5c4ae2b 100644
--- a/frontend/discourse/admin/components/site-settings/value-list.gjs
+++ b/frontend/discourse/admin/components/site-settings/value-list.gjs
@@ -1,13 +1,20 @@
-/* eslint-disable ember/no-classic-components */
-import Component from "@ember/component";
-import { tagName } from "@ember-decorators/component";
+import Component from "@glimmer/component";
+import { action } from "@ember/object";
import ValueList from "discourse/admin/components/value-list";
-@tagName("")
export default class SiteSettingValueList extends Component {
+ @action
+ onChange(values) {
+ this.args.changeValueCallback(values.join("\n"));
+ }
+
<template>
<div ...attributes>
- <ValueList @disabled={{@disabled}} @values={{this.value}} />
+ <ValueList
+ @disabled={{@disabled}}
+ @onChange={{this.onChange}}
+ @values={{@value}}
+ />
</div>
</template>
}
diff --git a/frontend/discourse/tests/integration/components/site-settings/enum-test.gjs b/frontend/discourse/tests/integration/components/site-settings/enum-test.gjs
new file mode 100644
index 00000000000..43f59da0bc4
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/site-settings/enum-test.gjs
@@ -0,0 +1,56 @@
+import { tracked } from "@glimmer/tracking";
+import { render, settled } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import Enum from "discourse/admin/components/site-settings/enum";
+import SiteSetting from "discourse/admin/models/site-setting";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import selectKit from "discourse/tests/helpers/select-kit-helper";
+
+class State {
+ @tracked value = "simple";
+}
+
+module("Integration | Component | SiteSettings | Enum", function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("reports the picked value and follows @value", async function (assert) {
+ const state = new State();
+ const setting = SiteSetting.create({
+ setting: "tag_style",
+ type: "enum",
+ valid_values: [
+ { name: "Simple", value: "simple" },
+ { name: "Box", value: "box" },
+ ],
+ });
+ const changes = [];
+ const changeValue = (value) => {
+ changes.push(value);
+ state.value = value;
+ };
+
+ await render(
+ <template>
+ <Enum
+ @changeValueCallback={{changeValue}}
+ @setting={{setting}}
+ @value={{state.value}}
+ />
+ </template>
+ );
+
+ await selectKit().expand();
+ await selectKit().selectRowByValue("box");
+
+ assert.deepEqual(changes, ["box"], "reports the picked value");
+
+ state.value = "simple";
+ await settled();
+
+ assert.strictEqual(
+ selectKit().header().value(),
+ "simple",
+ "renders a value set by the caller"
+ );
+ });
+});
diff --git a/frontend/discourse/tests/integration/components/site-settings/host-list-test.gjs b/frontend/discourse/tests/integration/components/site-settings/host-list-test.gjs
new file mode 100644
index 00000000000..fa9fa019824
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/site-settings/host-list-test.gjs
@@ -0,0 +1,56 @@
+import { tracked } from "@glimmer/tracking";
+import { render, settled } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import HostList from "discourse/admin/components/site-settings/host-list";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import selectKit from "discourse/tests/helpers/select-kit-helper";
+
+class State {
+ @tracked value = "a.com|b.com";
+}
+
+module("Integration | Component | SiteSettings | HostList", function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("reports changes as a pipe-joined string and follows @value", async function (assert) {
+ const state = new State();
+ const setting = { setting: "blocked_onebox_domains" };
+ const changes = [];
+ const changeValue = (value) => {
+ changes.push(value);
+ state.value = value;
+ };
+
+ await render(
+ <template>
+ <HostList
+ @allowAny={{true}}
+ @changeValueCallback={{changeValue}}
+ @setting={{setting}}
+ @value={{state.value}}
+ />
+ </template>
+ );
+
+ const subject = selectKit(".list-setting");
+ await subject.expand();
+ await subject.fillInFilter("c.com");
+ await subject.keyboard("Enter");
+
+ assert.deepEqual(changes, ["a.com|b.com|c.com"], "reports the new list");
+
+ await subject.fillInFilter("*.d.com");
+ await subject.keyboard("Enter");
+
+ assert.deepEqual(changes, ["a.com|b.com|c.com"], "ignores wildcard hosts");
+
+ state.value = "z.com";
+ await settled();
+
+ assert.strictEqual(
+ subject.header().value(),
+ "z.com",
+ "renders a value set by the caller"
+ );
+ });
+});
diff --git a/frontend/discourse/tests/integration/components/site-settings/named-list-test.gjs b/frontend/discourse/tests/integration/components/site-settings/named-list-test.gjs
new file mode 100644
index 00000000000..e1a9b32377d
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/site-settings/named-list-test.gjs
@@ -0,0 +1,55 @@
+import { tracked } from "@glimmer/tracking";
+import { render, settled } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import NamedList from "discourse/admin/components/site-settings/named-list";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import selectKit from "discourse/tests/helpers/select-kit-helper";
+
+class State {
+ @tracked value = "1";
+}
+
+module("Integration | Component | SiteSettings | NamedList", function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("reports changes as a pipe-joined string and follows @value", async function (assert) {
+ const state = new State();
+ const setting = {
+ setting: "named_list_setting",
+ choices: [
+ { name: "One", value: "1" },
+ { name: "Two", value: "2" },
+ ],
+ };
+ const changes = [];
+ const changeValue = (value) => {
+ changes.push(value);
+ state.value = value;
+ };
+
+ await render(
+ <template>
+ <NamedList
+ @changeValueCallback={{changeValue}}
+ @setting={{setting}}
+ @value={{state.value}}
+ />
+ </template>
+ );
+
+ const subject = selectKit(".list-setting");
+ await subject.expand();
+ await subject.selectRowByValue("2");
+
+ assert.deepEqual(changes, ["1|2"], "reports the new list");
+
+ state.value = "2";
+ await settled();
+
+ assert.strictEqual(
+ subject.header().value(),
+ "2",
+ "renders a value set by the caller"
+ );
+ });
+});
diff --git a/frontend/discourse/tests/integration/components/site-settings/simple-list-test.gjs b/frontend/discourse/tests/integration/components/site-settings/simple-list-test.gjs
new file mode 100644
index 00000000000..195fbe74505
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/site-settings/simple-list-test.gjs
@@ -0,0 +1,45 @@
+import { tracked } from "@glimmer/tracking";
+import { click, fillIn, render, settled } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import SiteSettingSimpleList from "discourse/admin/components/site-settings/simple-list";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+
+class State {
+ @tracked value = "a|b";
+}
+
+module("Integration | Component | SiteSettings | SimpleList", function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("reports changes as a pipe-joined string and follows @value", async function (assert) {
+ const state = new State();
+ const setting = {};
+ const changes = [];
+ const changeValue = (value) => {
+ changes.push(value);
+ state.value = value;
+ };
+
+ await render(
+ <template>
+ <SiteSettingSimpleList
+ @changeValueCallback={{changeValue}}
+ @setting={{setting}}
+ @value={{state.value}}
+ />
+ </template>
+ );
+
+ await fillIn(".add-value-input", "c");
+ await click(".add-value-btn");
+
+ assert.deepEqual(changes, ["a|b|c"], "reports the new list");
+
+ state.value = "z";
+ await settled();
+
+ assert
+ .dom(".values .value-input")
+ .hasValue("z", "renders a value set by the caller");
+ });
+});
diff --git a/frontend/discourse/tests/integration/components/site-settings/tag-group-list-test.gjs b/frontend/discourse/tests/integration/components/site-settings/tag-group-list-test.gjs
new file mode 100644
index 00000000000..6d6daf7b680
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/site-settings/tag-group-list-test.gjs
@@ -0,0 +1,50 @@
+import { tracked } from "@glimmer/tracking";
+import { render, settled } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import TagGroupList from "discourse/admin/components/site-settings/tag-group-list";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import selectKit from "discourse/tests/helpers/select-kit-helper";
+
+class State {
+ @tracked value = "";
+}
+
+module(
+ "Integration | Component | SiteSettings | TagGroupList",
+ function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("reports changes as a pipe-joined string and follows @value", async function (assert) {
+ const state = new State();
+ const changes = [];
+ const changeValue = (value) => {
+ changes.push(value);
+ state.value = value;
+ };
+
+ await render(
+ <template>
+ <TagGroupList
+ @changeValueCallback={{changeValue}}
+ @value={{state.value}}
+ />
+ </template>
+ );
+
+ const subject = selectKit(".tag-group-chooser");
+ await subject.expand();
+ await subject.selectRowByName("TagGroup1");
+
+ assert.deepEqual(changes, ["TagGroup1"], "reports the picked group");
+
+ state.value = "TagGroup2";
+ await settled();
+
+ assert.strictEqual(
+ subject.header().value(),
+ "TagGroup2",
+ "renders a value set by the caller"
+ );
+ });
+ }
+);
diff --git a/frontend/discourse/tests/integration/components/site-settings/tag-list-test.gjs b/frontend/discourse/tests/integration/components/site-settings/tag-list-test.gjs
index 8a1bda4c978..bdd6d16a225 100644
--- a/frontend/discourse/tests/integration/components/site-settings/tag-list-test.gjs
+++ b/frontend/discourse/tests/integration/components/site-settings/tag-list-test.gjs
@@ -1,9 +1,14 @@
-import { render } from "@ember/test-helpers";
+import { tracked } from "@glimmer/tracking";
+import { render, settled } from "@ember/test-helpers";
import { module, test } from "qunit";
import TagList from "discourse/admin/components/site-settings/tag-list";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import selectKit from "discourse/tests/helpers/select-kit-helper";
+class State {
+ @tracked value = "";
+}
+
module("Integration | Component | SiteSettings | TagList", function (hooks) {
setupRenderingTest(hooks);
@@ -11,15 +16,24 @@ module("Integration | Component | SiteSettings | TagList", function (hooks) {
this.set("subject", selectKit());
});
- test("selecting a tag updates the value with the tag name", async function (assert) {
- this.set("value", "");
+ test("selecting a tag reports the tag name", async function (assert) {
+ const state = new State();
+ const changes = [];
+ const changeValue = (value) => {
+ changes.push(value);
+ state.value = value;
+ };
- await render(<template><TagList @value={{this.value}} /></template>);
+ await render(
+ <template>
+ <TagList @changeValueCallback={{changeValue}} @value={{state.value}} />
+ </template>
+ );
await this.subject.expand();
await this.subject.selectRowByName("monkey");
- assert.strictEqual(this.value, "monkey");
+ assert.deepEqual(changes, ["monkey"]);
});
test("displays pre-selected tags from pipe-delimited value", async function (assert) {
@@ -30,6 +44,18 @@ module("Integration | Component | SiteSettings | TagList", function (hooks) {
assert.strictEqual(this.subject.header().value(), "foo,bar,baz");
});
+ test("follows a value set by the caller", async function (assert) {
+ const state = new State();
+ state.value = "foo";
+
+ await render(<template><TagList @value={{state.value}} /></template>);
+
+ state.value = "foo|bar";
+ await settled();
+
+ assert.strictEqual(this.subject.header().value(), "foo,bar");
+ });
+
test("displays no tags when value is empty", async function (assert) {
this.set("value", "");
diff --git a/frontend/discourse/tests/integration/components/site-settings/url-list-test.gjs b/frontend/discourse/tests/integration/components/site-settings/url-list-test.gjs
new file mode 100644
index 00000000000..4cf92ab826c
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/site-settings/url-list-test.gjs
@@ -0,0 +1,47 @@
+import { tracked } from "@glimmer/tracking";
+import { render, settled } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import UrlList from "discourse/admin/components/site-settings/url-list";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import selectKit from "discourse/tests/helpers/select-kit-helper";
+
+class State {
+ @tracked value = "https://a.com\nhttps://b.com";
+}
+
+module("Integration | Component | SiteSettings | UrlList", function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("reports changes as a newline-joined string and follows @value", async function (assert) {
+ const state = new State();
+ const changes = [];
+ const changeValue = (value) => {
+ changes.push(value);
+ state.value = value;
+ };
+
+ await render(
+ <template>
+ <UrlList @changeValueCallback={{changeValue}} @value={{state.value}} />
+ </template>
+ );
+
+ await selectKit().expand();
+ await selectKit().fillInFilter("https://c.com");
+ await selectKit().keyboard("Enter");
+
+ assert.deepEqual(
+ changes,
+ ["https://a.com\nhttps://b.com\nhttps://c.com"],
+ "reports the new list through the callback"
+ );
+ assert.dom(".values .value").exists({ count: 3 }, "shows the added url");
+
+ state.value = "https://z.com";
+ await settled();
+
+ assert
+ .dom(".values .value-input")
+ .hasValue("https://z.com", "renders a value set by the caller");
+ });
+});
diff --git a/frontend/discourse/tests/integration/components/site-settings/value-list-test.gjs b/frontend/discourse/tests/integration/components/site-settings/value-list-test.gjs
new file mode 100644
index 00000000000..a724e57a4b8
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/site-settings/value-list-test.gjs
@@ -0,0 +1,50 @@
+import { tracked } from "@glimmer/tracking";
+import { render, settled } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import SiteSettingValueList from "discourse/admin/components/site-settings/value-list";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import selectKit from "discourse/tests/helpers/select-kit-helper";
+
+class State {
+ @tracked value = "a\nb";
+}
+
+module("Integration | Component | SiteSettings | ValueList", function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("reports changes as a newline-joined string and follows @value", async function (assert) {
+ const state = new State();
+ const changes = [];
+ const changeValue = (value) => {
+ changes.push(value);
+ state.value = value;
+ };
+
+ await render(
+ <template>
+ <SiteSettingValueList
+ @changeValueCallback={{changeValue}}
+ @value={{state.value}}
+ />
+ </template>
+ );
+
+ await selectKit().expand();
+ await selectKit().fillInFilter("c");
+ await selectKit().keyboard("Enter");
+
+ assert.deepEqual(
+ changes,
+ ["a\nb\nc"],
+ "reports the new list through the callback"
+ );
+ assert.dom(".values .value").exists({ count: 3 }, "shows the added value");
+
+ state.value = "z";
+ await settled();
+
+ assert
+ .dom(".values .value-input")
+ .hasValue("z", "renders a value set by the caller");
+ });
+});
diff --git a/frontend/discourse/tests/integration/components/theme-site-setting-editor-test.gjs b/frontend/discourse/tests/integration/components/theme-site-setting-editor-test.gjs
index 7c6b0f2816d..1c99775cfae 100644
--- a/frontend/discourse/tests/integration/components/theme-site-setting-editor-test.gjs
+++ b/frontend/discourse/tests/integration/components/theme-site-setting-editor-test.gjs
@@ -4,6 +4,7 @@ import ThemeSiteSettingEditor from "discourse/admin/components/theme-site-settin
import SiteSetting from "discourse/admin/models/site-setting";
import Theme from "discourse/admin/models/theme";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import selectKit from "discourse/tests/helpers/select-kit-helper";
module("Integration | Component | ThemeSiteSettingEditor", function (hooks) {
setupRenderingTest(hooks);
@@ -40,4 +41,38 @@ module("Integration | Component | ThemeSiteSettingEditor", function (hooks) {
`/admin/logs/staff_action_logs?filters=${encodeURIComponent(JSON.stringify({ subject: "Test Theme: enable_welcome_banner", action_name: "change_theme_site_setting" }))}&force_refresh=true`
);
});
+
+ test("an enum setting buffers the picked value", async function (assert) {
+ const setting = SiteSetting.create({
+ setting: "tag_style",
+ value: "simple",
+ default: "simple",
+ type: "enum",
+ valid_values: [
+ { name: "Simple", value: "simple" },
+ { name: "Box", value: "box" },
+ ],
+ });
+ const model = Theme.create({ name: "Test Theme" });
+
+ await render(
+ <template>
+ <ThemeSiteSettingEditor @model={{model}} @setting={{setting}} />
+ </template>
+ );
+
+ await selectKit().expand();
+ await selectKit().selectRowByValue("box");
+
+ assert.strictEqual(
+ setting.buffered.get("value"),
+ "box",
+ "writes the picked value to the setting's buffer"
+ );
+ assert.strictEqual(
+ selectKit().header().value(),
+ "box",
+ "shows the buffered value"
+ );
+ });
});