mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-19 07:43:46 +08:00
Currently the AI features settings pages show site settings in one big list, making it difficult to navigate. Each setting also needs to be saved individually. This converts all AI feature settings pages to use FormKit with settings grouped by theme... for example, AI Helper (/admin/plugins/discourse-ai/ai-features/5/edit) has 4 groups: Access & Permissions, Enabled Features, Automation, Personas. Now these settings are all saved together as a single form, with the setting field component acting as a bridge to site settings. Also includes: - Fixes FormKit warning for unsaved changes from subroutes (the back button wasn't working) - Adds `@route` support to breadcrumbs (helps fix the unsaved changes issue above) - Hides "(optional)" labels on all fields via scoped CSS (temporary, eventually needs a feature in FormKit) Setting groups are managed in `ai-feature-setting-groups.js` Example before/after for the AI Helper settings... Before: <img width="573" alt="image" src="https://github.com/user-attachments/assets/679eb40b-5c33-4815-9b45-c988333d9db0" /> <img width="616" alt="image" src="https://github.com/user-attachments/assets/58822b9f-66a0-451b-89ce-ab63e5c73164" /> After: <img width="415" alt="image" src="https://github.com/user-attachments/assets/8ba019b6-afe1-488a-bc52-f0ed68dcc3d5" /> <img width="988" alt="image" src="https://github.com/user-attachments/assets/8a7f4091-9d95-47aa-a479-510f77bd703d" />
190 lines
5.3 KiB
JavaScript
Vendored
190 lines
5.3 KiB
JavaScript
Vendored
import { setupTest } from "ember-qunit";
|
|
import { module, test } from "qunit";
|
|
|
|
module(
|
|
"Unit | Controller | admin-plugins/show/discourse-ai-features/edit",
|
|
function (hooks) {
|
|
setupTest(hooks);
|
|
|
|
test("getValidationFor returns correct validation for integer with min/max", function (assert) {
|
|
const controller = this.owner.lookup(
|
|
"controller:admin-plugins/show/discourse-ai-features/edit"
|
|
);
|
|
|
|
const setting = {
|
|
type: "integer",
|
|
min: 0,
|
|
max: 100,
|
|
};
|
|
|
|
const validation = controller.getValidationFor(setting);
|
|
|
|
assert.strictEqual(
|
|
validation,
|
|
"number|between:0,100",
|
|
"should return number with between validator"
|
|
);
|
|
});
|
|
|
|
test("getValidationFor returns correct validation for integer with only min", function (assert) {
|
|
const controller = this.owner.lookup(
|
|
"controller:admin-plugins/show/discourse-ai-features/edit"
|
|
);
|
|
|
|
const setting = {
|
|
type: "integer",
|
|
min: 5,
|
|
};
|
|
|
|
const validation = controller.getValidationFor(setting);
|
|
|
|
assert.strictEqual(
|
|
validation,
|
|
"number|between:5,",
|
|
"should return number with between validator (min only)"
|
|
);
|
|
});
|
|
|
|
test("getValidationFor returns correct validation for integer with only max", function (assert) {
|
|
const controller = this.owner.lookup(
|
|
"controller:admin-plugins/show/discourse-ai-features/edit"
|
|
);
|
|
|
|
const setting = {
|
|
type: "integer",
|
|
max: 50,
|
|
};
|
|
|
|
const validation = controller.getValidationFor(setting);
|
|
|
|
assert.strictEqual(
|
|
validation,
|
|
"number|between:,50",
|
|
"should return number with between validator (max only)"
|
|
);
|
|
});
|
|
|
|
test("getValidationFor returns number for integer without constraints", function (assert) {
|
|
const controller = this.owner.lookup(
|
|
"controller:admin-plugins/show/discourse-ai-features/edit"
|
|
);
|
|
|
|
const setting = {
|
|
type: "integer",
|
|
};
|
|
|
|
const validation = controller.getValidationFor(setting);
|
|
|
|
assert.strictEqual(
|
|
validation,
|
|
"number",
|
|
"should return just number validator"
|
|
);
|
|
});
|
|
|
|
test("getValidationFor returns undefined for non-integer types", function (assert) {
|
|
const controller = this.owner.lookup(
|
|
"controller:admin-plugins/show/discourse-ai-features/edit"
|
|
);
|
|
|
|
const setting = {
|
|
type: "string",
|
|
};
|
|
|
|
const validation = controller.getValidationFor(setting);
|
|
|
|
assert.strictEqual(
|
|
validation,
|
|
undefined,
|
|
"should return undefined for non-integer types"
|
|
);
|
|
});
|
|
|
|
test("valuesEqual compares using toString", function (assert) {
|
|
const controller = this.owner.lookup(
|
|
"controller:admin-plugins/show/discourse-ai-features/edit"
|
|
);
|
|
|
|
assert.true(
|
|
controller.valuesEqual("123", 123),
|
|
"string '123' should equal number 123"
|
|
);
|
|
assert.true(
|
|
controller.valuesEqual(true, "true"),
|
|
"boolean true should equal string 'true'"
|
|
);
|
|
assert.true(
|
|
controller.valuesEqual(false, "false"),
|
|
"boolean false should equal string 'false'"
|
|
);
|
|
assert.true(
|
|
controller.valuesEqual("abc", "abc"),
|
|
"identical strings should be equal"
|
|
);
|
|
assert.false(
|
|
controller.valuesEqual("123", "456"),
|
|
"different values should not be equal"
|
|
);
|
|
});
|
|
|
|
test("valuesEqual handles null and undefined", function (assert) {
|
|
const controller = this.owner.lookup(
|
|
"controller:admin-plugins/show/discourse-ai-features/edit"
|
|
);
|
|
|
|
assert.false(
|
|
controller.valuesEqual(null, "null"),
|
|
"null should not equal string 'null'"
|
|
);
|
|
assert.false(
|
|
controller.valuesEqual(undefined, "undefined"),
|
|
"undefined should not equal string 'undefined'"
|
|
);
|
|
assert.true(controller.valuesEqual(null, null), "null should equal null");
|
|
assert.true(
|
|
controller.valuesEqual(undefined, undefined),
|
|
"undefined should equal undefined"
|
|
);
|
|
assert.false(
|
|
controller.valuesEqual(null, undefined),
|
|
"null should not equal undefined"
|
|
);
|
|
});
|
|
|
|
test("findSetting returns correct setting by name", function (assert) {
|
|
const controller = this.owner.lookup(
|
|
"controller:admin-plugins/show/discourse-ai-features/edit"
|
|
);
|
|
|
|
controller.settings = [
|
|
{ setting: "setting_one", value: "value1" },
|
|
{ setting: "setting_two", value: "value2" },
|
|
{ setting: "setting_three", value: "value3" },
|
|
];
|
|
|
|
const result = controller.findSetting("setting_two");
|
|
|
|
assert.deepEqual(
|
|
result,
|
|
{ setting: "setting_two", value: "value2" },
|
|
"should return the correct setting"
|
|
);
|
|
});
|
|
|
|
test("findSetting returns undefined for non-existent setting", function (assert) {
|
|
const controller = this.owner.lookup(
|
|
"controller:admin-plugins/show/discourse-ai-features/edit"
|
|
);
|
|
|
|
controller.settings = [{ setting: "setting_one", value: "value1" }];
|
|
|
|
const result = controller.findSetting("nonexistent");
|
|
|
|
assert.strictEqual(
|
|
result,
|
|
undefined,
|
|
"should return undefined for non-existent setting"
|
|
);
|
|
});
|
|
}
|
|
);
|