* feat(webui): improve channel setup flows * fix(webui): refine channel setup interactions (NAN-112) * fix(webui): keep email setup sections channel-owned * fix(webui): remove concrete channel details from shared components * refactor(webui): remove unused channel setup resources * fix(webui): finish channel-owned setup boundaries * fix(webui): update channel switches optimistically * test(channels): remove obsolete absence assertions * fix(webui): flatten channel instance settings disclosure * fix(webui): complete channel setup and connection flows * fix(whatsapp): wait for session database release * fix(webui): preserve scrolling channel controls * fix(webui): stage channel connection checks * fix(channels): align verification actions * fix(email): expose connection checks * fix(webui): align channel field actions * fix(email): verify account credentials * fix(wecom): bypass system proxy for websocket * fix(channels): stabilize async connection cleanup * fix(webui): autosave channel credentials * fix(email): make provider presets non-destructive * test(weixin): isolate persisted QR credentials
160 lines
4.4 KiB
TypeScript
160 lines
4.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
channelIsRunning,
|
|
channelSetup,
|
|
channelStatusLabel,
|
|
channelToggleChecked,
|
|
} from "@/components/settings/channels/ChannelIdentity";
|
|
import type { NanobotFeatureInfo } from "@/lib/types";
|
|
|
|
function feature(overrides: Partial<NanobotFeatureInfo>): NanobotFeatureInfo {
|
|
return {
|
|
name: "plugin-chat",
|
|
display_name: "Plugin Chat",
|
|
type: "channel",
|
|
enabled: false,
|
|
installed: true,
|
|
ready: false,
|
|
status: "not_enabled",
|
|
install_supported: true,
|
|
requires_restart: true,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("channelSetup", () => {
|
|
it("builds editable fields for a plugin-owned backend contract", () => {
|
|
const setup = channelSetup(feature({
|
|
setup: {
|
|
fields: [
|
|
{
|
|
key: "channels.plugin-chat.apiToken",
|
|
field: "apiToken",
|
|
kind: "secret",
|
|
choices: [],
|
|
required: true,
|
|
},
|
|
{
|
|
key: "channels.plugin-chat.region",
|
|
field: "region",
|
|
kind: "enum",
|
|
choices: ["us", "eu"],
|
|
required: false,
|
|
},
|
|
],
|
|
official_url: "https://plugin.example/setup",
|
|
},
|
|
}));
|
|
|
|
expect(setup.officialUrl).toBe("https://plugin.example/setup");
|
|
expect(setup.officialLabel).toBe("Open official setup");
|
|
expect(setup.fields).toEqual([
|
|
expect.objectContaining({
|
|
key: "channels.plugin-chat.apiToken",
|
|
label: "Api Token",
|
|
secret: true,
|
|
optional: false,
|
|
}),
|
|
expect.objectContaining({
|
|
key: "channels.plugin-chat.region",
|
|
options: [
|
|
{ value: "us", label: "Us" },
|
|
{ value: "eu", label: "Eu" },
|
|
],
|
|
}),
|
|
]);
|
|
});
|
|
|
|
it("filters catalog-only fields that the backend does not accept", () => {
|
|
const setup = channelSetup(feature({
|
|
name: "discord",
|
|
display_name: "Discord",
|
|
webui: "webui/index.ts",
|
|
setup: {
|
|
fields: [{
|
|
key: "channels.discord.token",
|
|
field: "token",
|
|
kind: "secret",
|
|
choices: [],
|
|
required: true,
|
|
}],
|
|
},
|
|
}));
|
|
|
|
expect(setup.fields?.map((field) => field.key)).toEqual(["channels.discord.token"]);
|
|
expect(setup.manualFields).toBeUndefined();
|
|
});
|
|
|
|
it("uses backend defaults and choices with catalog presentation labels", () => {
|
|
const setup = channelSetup(feature({
|
|
name: "discord",
|
|
display_name: "Discord",
|
|
webui: "webui/index.ts",
|
|
setup: {
|
|
fields: [{
|
|
key: "channels.discord.groupPolicy",
|
|
field: "groupPolicy",
|
|
kind: "enum",
|
|
choices: ["open"],
|
|
required: false,
|
|
default_value: "open",
|
|
}],
|
|
},
|
|
}));
|
|
|
|
expect(setup.fields).toEqual([
|
|
expect.objectContaining({
|
|
key: "channels.discord.groupPolicy",
|
|
label: "Group behavior",
|
|
defaultValue: "open",
|
|
options: [{ value: "open", label: "All messages" }],
|
|
}),
|
|
]);
|
|
});
|
|
|
|
it("loads setup copy from the channel-owned locale", () => {
|
|
const setup = channelSetup(feature({
|
|
name: "dingtalk",
|
|
display_name: "DingTalk",
|
|
webui: "webui/index.ts",
|
|
}), "zh-CN");
|
|
|
|
expect(setup.docsLabel).toBe("打开钉钉配置指南");
|
|
expect(setup.officialLabel).toBe("打开钉钉开发者后台");
|
|
expect(setup.fields).toContainEqual(expect.objectContaining({
|
|
key: "channels.dingtalk.allowFrom",
|
|
label: "允许的用户",
|
|
}));
|
|
});
|
|
|
|
it("loads custom setup section labels from the channel-owned locale", () => {
|
|
const setup = channelSetup(feature({
|
|
name: "email",
|
|
display_name: "Email",
|
|
webui: "webui/index.ts",
|
|
}));
|
|
|
|
expect(setup.sectionLabels).toEqual({
|
|
receiving: "Receiving mail",
|
|
sending: "Sending mail",
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("channel runtime state", () => {
|
|
const tx = (_key: string, fallback: string) => fallback;
|
|
|
|
it("only reports a channel on when the runtime is explicitly running", () => {
|
|
const running = feature({ enabled: true, runtime_status: "running" });
|
|
const unknown = feature({ enabled: true });
|
|
|
|
expect(channelIsRunning(running)).toBe(true);
|
|
expect(channelToggleChecked(running)).toBe(true);
|
|
expect(channelStatusLabel(running, tx)).toBe("On");
|
|
expect(channelIsRunning(unknown)).toBe(false);
|
|
expect(channelToggleChecked(unknown)).toBe(false);
|
|
expect(channelStatusLabel(unknown, tx)).toBe("Not running");
|
|
});
|
|
});
|