feat(channels): add inherited global compaction notice policy
This commit is contained in:
1 parent
7644d845b4
commit
ab6d5f1d3c
35 files changed
+287
-37
No files matched your search
@@ -4,7 +4,9 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
CredentialForm,
|
||||
channelValuesForSubmit,
|
||||
defaultChannelFieldValues,
|
||||
} from "@/components/settings/channels/CredentialForm";
|
||||
import { channelSetup } from "@/components/settings/channels/ChannelIdentity";
|
||||
import type { ChannelConfigField } from "@/components/settings/channels/catalog";
|
||||
|
||||
const fields: ChannelConfigField[] = [
|
||||
@@ -24,6 +26,34 @@ const fields: ChannelConfigField[] = [
|
||||
];
|
||||
|
||||
describe("CredentialForm", () => {
|
||||
it("preserves inherited notices and lets an explicit override return to the default", () => {
|
||||
const key = "channels.qq.showCompactionNotices";
|
||||
const setup = channelSetup({
|
||||
name: "qq", display_name: "QQ", type: "channel", enabled: false,
|
||||
installed: true, ready: false, status: "not_enabled",
|
||||
install_supported: true, requires_restart: false,
|
||||
setup: { fields: [{
|
||||
key, field: "showCompactionNotices", kind: "bool", choices: [],
|
||||
required: false, inheritable: true,
|
||||
}] },
|
||||
});
|
||||
const noticeFields = setup.fields!;
|
||||
expect(defaultChannelFieldValues(noticeFields)).toEqual({ [key]: "" });
|
||||
expect(channelValuesForSubmit(noticeFields, {}, new Set())).toEqual({});
|
||||
expect(defaultChannelFieldValues(noticeFields, { [key]: "false" })).toEqual({ [key]: "false" });
|
||||
expect(channelValuesForSubmit(noticeFields, { [key]: "true" }, new Set([key])))
|
||||
.toEqual({ [key]: "true" });
|
||||
expect(channelValuesForSubmit(noticeFields, { [key]: "" }, new Set([key])))
|
||||
.toEqual({ [key]: "" });
|
||||
|
||||
const onChange = vi.fn();
|
||||
render(<CredentialForm fields={noticeFields} values={{ [key]: "false" }}
|
||||
visibleSecrets={{}} onChange={onChange} onToggleSecret={vi.fn()} />);
|
||||
expect(screen.getByRole("radio", { name: "Off" })).toBeChecked();
|
||||
fireEvent.click(screen.getByRole("radio", { name: "Default" }));
|
||||
expect(onChange).toHaveBeenCalledWith(key, "");
|
||||
});
|
||||
|
||||
it("uses native radio semantics for option fields", () => {
|
||||
const onChange = vi.fn();
|
||||
render(
|
||||
|
||||
@@ -24,6 +24,32 @@ function feature(overrides: Partial<NanobotFeatureInfo>): NanobotFeatureInfo {
|
||||
}
|
||||
|
||||
describe("channelSetup", () => {
|
||||
it("offers a localized inherited option without changing ordinary booleans", () => {
|
||||
const setup = channelSetup(feature({ setup: { fields: [
|
||||
{
|
||||
key: "channels.plugin-chat.showCompactionNotices",
|
||||
field: "showCompactionNotices",
|
||||
kind: "bool",
|
||||
choices: [],
|
||||
required: false,
|
||||
inheritable: true,
|
||||
},
|
||||
{
|
||||
key: "channels.plugin-chat.sendProgress",
|
||||
field: "sendProgress",
|
||||
kind: "bool",
|
||||
choices: [],
|
||||
required: false,
|
||||
},
|
||||
] } }), "zh-CN");
|
||||
expect(setup.fields?.[0]?.options).toEqual([
|
||||
{ value: "", label: "默认" },
|
||||
{ value: "true", label: "True" },
|
||||
{ value: "false", label: "False" },
|
||||
]);
|
||||
expect(setup.fields?.[1]?.options?.map((option) => option.value)).toEqual(["true", "false"]);
|
||||
});
|
||||
|
||||
it("builds editable fields for a plugin-owned backend contract", () => {
|
||||
const setup = channelSetup(feature({
|
||||
setup: {
|
||||
|
||||
Reference in new issue
Block a user