Skip to content

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

FIX: Extract tag names from objects in tag-list site setting (#37554)

Alan Guo Xiang Tan2b7282ff4444
diff --git a/frontend/discourse/admin/components/site-settings/tag-list.gjs b/frontend/discourse/admin/components/site-settings/tag-list.gjs
index 43edf75764a..c87efe261c8 100644
--- a/frontend/discourse/admin/components/site-settings/tag-list.gjs
+++ b/frontend/discourse/admin/components/site-settings/tag-list.gjs
@@ -15,7 +15,7 @@ export default class TagList extends Component {
@action
changeSelectedTags(tags) {
- this.set("value", tags.join("|"));
+ this.set("value", tags.map((t) => t.name).join("|"));
}
<template>
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
new file mode 100644
index 00000000000..4412c4d7ba1
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/site-settings/tag-list-test.gjs
@@ -0,0 +1,40 @@
+import { render } 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";
+
+module("Integration | Component | site-settings/tag-list", function (hooks) {
+ setupRenderingTest(hooks);
+
+ hooks.beforeEach(function () {
+ this.set("subject", selectKit());
+ });
+
+ test("selecting a tag updates the value with the tag name", async function (assert) {
+ this.set("value", "");
+
+ await render(<template><TagList @value={{this.value}} /></template>);
+
+ await this.subject.expand();
+ await this.subject.selectRowByName("monkey");
+
+ assert.strictEqual(this.value, "monkey");
+ });
+
+ test("displays pre-selected tags from pipe-delimited value", async function (assert) {
+ this.set("value", "foo|bar|baz");
+
+ await render(<template><TagList @value={{this.value}} /></template>);
+
+ assert.strictEqual(this.subject.header().value(), "foo,bar,baz");
+ });
+
+ test("displays no tags when value is empty", async function (assert) {
+ this.set("value", "");
+
+ await render(<template><TagList @value={{this.value}} /></template>);
+
+ assert.strictEqual(this.subject.header().value(), null);
+ });
+});