feat(webui): improve setup flows across chat channels (NAN-112) (#5356)
* 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
This commit is contained in:
1 parent
3cc3012b3a
commit
e8a29a0087
291 files changed
+12194
-3979
No files matched your search
@@ -259,6 +259,20 @@ describe("webui API helpers", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("forwards channel-owned connect parameters without overriding the channel", async () => {
|
||||
await startChannelConnect(mutationTransport, "plugin-chat", {
|
||||
region: "eu",
|
||||
interactive: false,
|
||||
channel: "another-channel",
|
||||
});
|
||||
|
||||
expect(requestMutation).toHaveBeenLastCalledWith(
|
||||
"settings.channel.connect.start",
|
||||
{ channel: "plugin-chat", region: "eu", interactive: false },
|
||||
150_000,
|
||||
);
|
||||
});
|
||||
|
||||
it("serializes workspace automation actions", async () => {
|
||||
await runAutomationAction(mutationTransport, "disable", "job 1/2");
|
||||
|
||||
@@ -810,6 +824,13 @@ describe("webui API helpers", () => {
|
||||
150_000,
|
||||
);
|
||||
|
||||
await enableNanobotFeature(mutationTransport, "whatsapp", { installOnly: true });
|
||||
expect(requestMutation).toHaveBeenLastCalledWith(
|
||||
"settings.feature.enable",
|
||||
{ name: "whatsapp", install_only: true },
|
||||
150_000,
|
||||
);
|
||||
|
||||
await disableNanobotFeature(mutationTransport, "matrix");
|
||||
expect(requestMutation).toHaveBeenLastCalledWith(
|
||||
"settings.feature.disable",
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
import { fireEvent, render, screen, within } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
CredentialForm,
|
||||
channelValuesForSubmit,
|
||||
} from "@/components/settings/channels/CredentialForm";
|
||||
import type { ChannelConfigField } from "@/components/settings/channels/catalog";
|
||||
|
||||
const fields: ChannelConfigField[] = [
|
||||
{
|
||||
key: "channels.matrix.password",
|
||||
label: "Password",
|
||||
secret: true,
|
||||
},
|
||||
{
|
||||
key: "channels.matrix.groupPolicy",
|
||||
label: "Group behavior",
|
||||
options: [
|
||||
{ value: "mention", label: "Mention only" },
|
||||
{ value: "open", label: "All messages" },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
describe("CredentialForm", () => {
|
||||
it("uses native radio semantics for option fields", () => {
|
||||
const onChange = vi.fn();
|
||||
render(
|
||||
<CredentialForm
|
||||
fields={[fields[1]!]}
|
||||
values={{ "channels.matrix.groupPolicy": "mention" }}
|
||||
visibleSecrets={{}}
|
||||
onChange={onChange}
|
||||
onToggleSecret={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
|
||||
const group = screen.getByRole("group", { name: "Group behavior" });
|
||||
expect(within(group).getByRole("radio", { name: "Mention only" })).toBeChecked();
|
||||
fireEvent.click(within(group).getByRole("radio", { name: "All messages" }));
|
||||
expect(onChange).toHaveBeenCalledWith("channels.matrix.groupPolicy", "open");
|
||||
});
|
||||
|
||||
it("associates option errors and exposes a stable focus target", () => {
|
||||
render(
|
||||
<CredentialForm
|
||||
fields={[fields[1]!]}
|
||||
values={{ "channels.matrix.groupPolicy": "mention" }}
|
||||
visibleSecrets={{}}
|
||||
onChange={vi.fn()}
|
||||
onToggleSecret={vi.fn()}
|
||||
errors={{ "channels.matrix.groupPolicy": "Required to complete setup." }}
|
||||
/>,
|
||||
);
|
||||
|
||||
const group = screen.getByRole("group", { name: "Group behavior" });
|
||||
const firstRadio = within(group).getByRole("radio", { name: "Mention only" });
|
||||
const secondRadio = within(group).getByRole("radio", { name: "All messages" });
|
||||
|
||||
expect(group).toHaveAttribute("id", "channel-field-channels-matrix-groupPolicy-group");
|
||||
expect(group).toHaveAttribute("aria-invalid", "true");
|
||||
expect(group).toHaveAccessibleDescription(
|
||||
"Required to complete setup.",
|
||||
);
|
||||
expect(firstRadio).toHaveAttribute("id", "channel-field-channels-matrix-groupPolicy");
|
||||
expect(secondRadio).toHaveAttribute("id", "channel-field-channels-matrix-groupPolicy-1");
|
||||
expect(firstRadio).toHaveAttribute("aria-invalid", "true");
|
||||
expect(firstRadio).toHaveAccessibleDescription(
|
||||
"Required to complete setup.",
|
||||
);
|
||||
|
||||
document.getElementById("channel-field-channels-matrix-groupPolicy")?.focus();
|
||||
expect(firstRadio).toHaveFocus();
|
||||
});
|
||||
|
||||
it("associates field errors and saved-secret removal actions", () => {
|
||||
const onClearSecret = vi.fn();
|
||||
render(
|
||||
<CredentialForm
|
||||
fields={[fields[0]!]}
|
||||
values={{}}
|
||||
configuredFields={new Set(["channels.matrix.password"])}
|
||||
visibleSecrets={{}}
|
||||
onChange={vi.fn()}
|
||||
onToggleSecret={vi.fn()}
|
||||
errors={{ "channels.matrix.password": "Required to complete setup." }}
|
||||
onClearSecret={onClearSecret}
|
||||
showSecretActions
|
||||
/>,
|
||||
);
|
||||
|
||||
const password = screen.getByLabelText("Password");
|
||||
expect(password).toHaveAttribute("aria-invalid", "true");
|
||||
expect(password).toHaveAccessibleDescription("Required to complete setup.");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Remove saved credential" }));
|
||||
expect(onClearSecret).toHaveBeenCalledWith("channels.matrix.password", true);
|
||||
});
|
||||
|
||||
it("uses null only for an explicitly cleared secret", () => {
|
||||
expect(
|
||||
channelValuesForSubmit(
|
||||
fields,
|
||||
{ "channels.matrix.password": "" },
|
||||
new Set(),
|
||||
new Set(["channels.matrix.password"]),
|
||||
),
|
||||
).toEqual({ "channels.matrix.password": null });
|
||||
expect(channelValuesForSubmit(fields, {}, new Set())).toEqual({});
|
||||
});
|
||||
});
|
||||
@@ -120,13 +120,26 @@ describe("channelSetup", () => {
|
||||
webui: "webui/index.ts",
|
||||
}), "zh-CN");
|
||||
|
||||
expect(setup.summary).toBe("钉钉需要 Stream 模式的应用凭据。");
|
||||
expect(setup.steps[0]).toBe("创建或选择一个已启用 Stream 模式的钉钉应用。");
|
||||
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", () => {
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { channelFieldMessageKey } from "@/channel-plugins/i18n";
|
||||
@@ -15,6 +12,7 @@ const expectedChannels = [
|
||||
"feishu",
|
||||
"matrix",
|
||||
"mattermost",
|
||||
"mochat",
|
||||
"msteams",
|
||||
"napcat",
|
||||
"qq",
|
||||
@@ -96,22 +94,6 @@ describe("channel locale registry", () => {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps i18n initialization independent from channel React modules", () => {
|
||||
const localeRegistry = readFileSync(
|
||||
resolve(process.cwd(), "src/channel-plugins/locale-registry.ts"),
|
||||
"utf8",
|
||||
);
|
||||
const i18nEntry = readFileSync(resolve(process.cwd(), "src/i18n/index.ts"), "utf8");
|
||||
|
||||
expect(localeRegistry).toContain("webui/locales/*.json");
|
||||
expect(localeRegistry).not.toContain("eager: true");
|
||||
expect(localeRegistry).not.toMatch(/channel-plugins\/registry|\.tsx|\breact\b/i);
|
||||
expect(i18nEntry).toContain("channel-plugins/locale-registry");
|
||||
expect(i18nEntry).toContain("import.meta.glob");
|
||||
expect(i18nEntry).not.toMatch(/import\s+\w+Common\s+from/);
|
||||
expect(i18nEntry).not.toContain("channel-plugins/registry");
|
||||
});
|
||||
});
|
||||
|
||||
describe("channel locale registry concurrency", () => {
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { ChannelQrConnectFlow } from "@/components/settings/channels/ChannelQrConnectFlow";
|
||||
import { FeishuConnectFlow } from "../../../nanobot/channels/feishu/webui/FeishuConnectFlow";
|
||||
|
||||
const { requestMutation } = vi.hoisted(() => ({ requestMutation: vi.fn() }));
|
||||
|
||||
vi.mock("@/providers/ClientProvider", () => {
|
||||
const client = { requestMutation };
|
||||
return { useClient: () => ({ client }) };
|
||||
});
|
||||
|
||||
const labels = {
|
||||
qrAlt: "Connection QR code",
|
||||
scanTitle: "Scan to connect",
|
||||
scanDescription: "Scan with your app",
|
||||
waiting: "Waiting",
|
||||
connected: "Connected",
|
||||
stopped: "Stopped",
|
||||
connecting: "Connecting",
|
||||
scanAgain: "Scan again",
|
||||
connect: "Connect",
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
requestMutation.mockReset().mockResolvedValue({
|
||||
session_id: "link-1",
|
||||
status: "succeeded",
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(cleanup);
|
||||
|
||||
describe("channel QR connect parameters", () => {
|
||||
it("forwards current channel parameters without restarting on rerender and preserves forced retries", async () => {
|
||||
const props = {
|
||||
token: "tok",
|
||||
channelName: "plugin-chat",
|
||||
autoStart: true,
|
||||
forceOnRepeat: true,
|
||||
labels,
|
||||
onFeaturesUpdate: vi.fn(),
|
||||
};
|
||||
const view = render(<ChannelQrConnectFlow {...props} startParams={{ region: "eu" }} />);
|
||||
await waitFor(() => expect(requestMutation).toHaveBeenCalledTimes(1));
|
||||
expect(requestMutation).toHaveBeenLastCalledWith(
|
||||
"settings.channel.connect.start",
|
||||
{ channel: "plugin-chat", region: "eu" },
|
||||
150_000,
|
||||
);
|
||||
await screen.findByText("Connected");
|
||||
|
||||
view.rerender(<ChannelQrConnectFlow {...props} startParams={{ region: "us" }} />);
|
||||
expect(requestMutation).toHaveBeenCalledTimes(1);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Scan again" }));
|
||||
await waitFor(() => expect(requestMutation).toHaveBeenCalledTimes(2));
|
||||
expect(requestMutation).toHaveBeenLastCalledWith(
|
||||
"settings.channel.connect.start",
|
||||
{ channel: "plugin-chat", region: "us", force: true },
|
||||
150_000,
|
||||
);
|
||||
});
|
||||
|
||||
it("preserves the Feishu-owned registration domain and instance creation mode", async () => {
|
||||
render(
|
||||
<FeishuConnectFlow
|
||||
token="tok"
|
||||
instanceId="support"
|
||||
mode="create"
|
||||
connectRequestId={1}
|
||||
onFeaturesUpdate={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
await waitFor(() => expect(requestMutation).toHaveBeenCalledWith(
|
||||
"settings.channel.connect.start",
|
||||
{ channel: "feishu", domain: "feishu", instance_id: "support", mode: "create" },
|
||||
150_000,
|
||||
));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,189 @@
|
||||
import { act, fireEvent, screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type { NanobotFeatureInfo, NanobotFeaturesPayload } from "@/lib/types";
|
||||
import {
|
||||
installSettingsViewTestHooks,
|
||||
jsonResponse,
|
||||
renderSettingsView,
|
||||
requestMutationMock,
|
||||
settingsPayload,
|
||||
} from "@/tests/settings-test-utils";
|
||||
|
||||
function deferred<T>() {
|
||||
let resolve!: (value: T) => void;
|
||||
let reject!: (error: Error) => void;
|
||||
const promise = new Promise<T>((res, rej) => { resolve = res; reject = rej; });
|
||||
return { promise, resolve, reject };
|
||||
}
|
||||
|
||||
function feature(enabled: boolean, instances = false): NanobotFeatureInfo {
|
||||
return {
|
||||
name: "test-chat",
|
||||
display_name: "Test Chat",
|
||||
type: "channel",
|
||||
installed: true,
|
||||
configured: true,
|
||||
enabled,
|
||||
running: enabled,
|
||||
runtime_status: enabled ? "running" : "stopped",
|
||||
ready: true,
|
||||
status: enabled ? "enabled" : "not_enabled",
|
||||
install_supported: true,
|
||||
requires_restart: false,
|
||||
setup: { fields: [], requirements: [] },
|
||||
...(instances ? { instances: [{
|
||||
id: "first",
|
||||
name: "First",
|
||||
configured: true,
|
||||
enabled,
|
||||
runtime_status: enabled ? "running" : "stopped",
|
||||
config_values: {},
|
||||
configured_fields: [],
|
||||
}, {
|
||||
id: "second",
|
||||
name: "Second",
|
||||
configured: true,
|
||||
enabled: false,
|
||||
runtime_status: "stopped",
|
||||
config_values: {},
|
||||
configured_fields: [],
|
||||
}] } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function payload(channel: NanobotFeatureInfo): NanobotFeaturesPayload {
|
||||
return { features: [channel], enabled_count: Number(channel.enabled) };
|
||||
}
|
||||
|
||||
function renderChannel(channel: NanobotFeatureInfo) {
|
||||
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => {
|
||||
const url = String(input);
|
||||
if (url === "/api/settings") return jsonResponse(settingsPayload());
|
||||
if (url === "/api/settings/nanobot-features") return jsonResponse(payload(channel));
|
||||
return { ok: false, status: 404, json: async () => ({}) } as Response;
|
||||
}));
|
||||
renderSettingsView({ initialSection: "channels" });
|
||||
}
|
||||
|
||||
describe("optimistic channel switches", () => {
|
||||
installSettingsViewTestHooks();
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
|
||||
for (const surface of ["catalog", "setup", "instance"] as const) {
|
||||
it.each([
|
||||
[false, true],
|
||||
[true, true],
|
||||
[false, false],
|
||||
[true, false],
|
||||
])(`${surface}: updates immediately from %s and settles with success=%s`, async (initial, succeeds) => {
|
||||
const mutation = deferred<unknown>();
|
||||
const validation = deferred<unknown>();
|
||||
requestMutationMock.mockImplementation((action: string) =>
|
||||
action === "settings.channel.validate" ? validation.promise : mutation.promise);
|
||||
vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
renderChannel(feature(initial, surface === "instance"));
|
||||
|
||||
const catalogSwitch = await screen.findByRole("switch", { name: "Test Chat channel" });
|
||||
if (surface !== "catalog") {
|
||||
fireEvent.click(screen.getByRole("button", { name: "View Test Chat settings" }));
|
||||
}
|
||||
const toggle = surface === "catalog"
|
||||
? catalogSwitch
|
||||
: surface === "instance"
|
||||
? await screen.findByRole("switch", { name: "First instance" })
|
||||
: within(await screen.findByRole("dialog")).getByRole("switch");
|
||||
|
||||
if (!initial && succeeds) {
|
||||
toggle.focus();
|
||||
await userEvent.setup().keyboard("[Space]");
|
||||
} else {
|
||||
fireEvent.click(toggle);
|
||||
}
|
||||
expect(toggle).toHaveAttribute("aria-checked", String(!initial));
|
||||
expect(toggle).toBeDisabled();
|
||||
fireEvent.click(toggle);
|
||||
expect(requestMutationMock).toHaveBeenCalledTimes(1);
|
||||
if (surface === "instance") {
|
||||
const other = screen.getByRole("switch", { name: "Second instance" });
|
||||
expect(other).toHaveAttribute("aria-checked", "false");
|
||||
expect(other).toBeDisabled();
|
||||
fireEvent.click(other);
|
||||
expect(requestMutationMock).toHaveBeenCalledTimes(1);
|
||||
}
|
||||
|
||||
await act(async () => { fireEvent(window, new Event("focus")); });
|
||||
expect(toggle).toHaveAttribute("aria-checked", String(!initial));
|
||||
expect(toggle).toBeDisabled();
|
||||
|
||||
if (surface === "setup" && !initial) {
|
||||
await act(async () => validation.resolve({
|
||||
name: "test-chat", status: "connected", can_enable: true,
|
||||
checks: [], missing_fields: [], requires_restart: false,
|
||||
}));
|
||||
expect(requestMutationMock).toHaveBeenCalledTimes(2);
|
||||
expect(toggle).toHaveAttribute("aria-checked", "true");
|
||||
expect(toggle).toBeDisabled();
|
||||
}
|
||||
const result = payload(feature(!initial, surface === "instance"));
|
||||
await act(async () => {
|
||||
if (succeeds) {
|
||||
mutation.resolve(surface === "setup" && !initial ? { nanobot_features: result } : result);
|
||||
} else {
|
||||
mutation.reject(new Error("Channel update failed"));
|
||||
}
|
||||
});
|
||||
if (surface === "catalog" && initial && succeeds) {
|
||||
await waitFor(() => expect(toggle).not.toBeInTheDocument());
|
||||
} else {
|
||||
await waitFor(() => expect(toggle).toBeEnabled());
|
||||
expect(toggle).toHaveAttribute("aria-checked", String(succeeds ? !initial : initial));
|
||||
}
|
||||
if (!succeeds) expect(screen.getByText("Channel update failed")).toBeVisible();
|
||||
if (surface === "instance") {
|
||||
expect(screen.getByRole("switch", { name: "Second instance" })).toBeEnabled();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
it("rolls back when server validation rejects activation without saving", async () => {
|
||||
const validation = deferred<unknown>();
|
||||
requestMutationMock.mockReturnValue(validation.promise);
|
||||
renderChannel(feature(false));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "View Test Chat settings" }));
|
||||
const toggle = within(await screen.findByRole("dialog")).getByRole("switch");
|
||||
fireEvent.click(toggle);
|
||||
expect(toggle).toHaveAttribute("aria-checked", "true");
|
||||
|
||||
await act(async () => validation.resolve({
|
||||
name: "test-chat", status: "invalid", can_enable: false, message: "Credentials rejected",
|
||||
checks: [], missing_fields: [], requires_restart: false,
|
||||
}));
|
||||
expect(toggle).toHaveAttribute("aria-checked", "false");
|
||||
expect(toggle).toBeEnabled();
|
||||
expect(screen.getByText("Credentials rejected")).toBeVisible();
|
||||
expect(requestMutationMock).toHaveBeenCalledTimes(1);
|
||||
expect(requestMutationMock.mock.calls[0][0]).toBe("settings.channel.validate");
|
||||
});
|
||||
|
||||
it("does not show installation-only requests as optimistic activation", async () => {
|
||||
const installation = deferred<unknown>();
|
||||
requestMutationMock.mockReturnValue(installation.promise);
|
||||
const channel = { ...feature(false), installed: false, requires_dependencies: true };
|
||||
renderChannel(channel);
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Install Test Chat" }));
|
||||
expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.feature.enable", { name: "test-chat", install_only: true }, 150_000,
|
||||
);
|
||||
|
||||
channel.installed = true;
|
||||
await act(async () => { fireEvent(window, new Event("focus")); });
|
||||
const toggle = await screen.findByRole("switch", { name: "Test Chat channel" });
|
||||
expect(toggle).toHaveAttribute("aria-checked", "false");
|
||||
expect(toggle).toBeDisabled();
|
||||
await act(async () => installation.resolve(payload(channel)));
|
||||
expect(toggle).toHaveAttribute("aria-checked", "false");
|
||||
expect(toggle).toBeEnabled();
|
||||
});
|
||||
});
|
||||
@@ -33,44 +33,6 @@ describe("channel UI contributions", () => {
|
||||
expect(channelUiOwner("wechat")).toBe("weixin");
|
||||
});
|
||||
|
||||
it("uses the DingTalk Open Platform brand mark", () => {
|
||||
expect(channelUiPresentation("dingtalk")?.logoUrl).toBe(
|
||||
"https://img.alicdn.com/imgextra/i3/O1CN01WMvMRG1ks3Ixc9x1v_!!6000000004738-55-tps-32-32.svg",
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps the core setup panel independent of concrete channel plugins", () => {
|
||||
const source = readFileSync(
|
||||
resolve(process.cwd(), "src/components/settings/channels/ChannelSetupPanel.tsx"),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
expect(source).not.toMatch(/feature\.name\s*===\s*["'](?:feishu|weixin)["']/);
|
||||
expect(source).not.toMatch(/channel-plugins\/(?:feishu|weixin)/);
|
||||
expect(source).not.toMatch(/(?:Feishu|Weixin)(?:AssistantsPanel|ConnectFlow)/);
|
||||
});
|
||||
|
||||
it("discovers UI contributions only from channel-owned packages", () => {
|
||||
const source = readFileSync(
|
||||
resolve(process.cwd(), "src/channel-plugins/registry.ts"),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
expect(source).toContain("../../../nanobot/channels/*/webui/index.{ts,tsx}");
|
||||
expect(source).not.toContain("webui/**/*.{ts,tsx}");
|
||||
expect(source).not.toContain('"./*/index.tsx"');
|
||||
});
|
||||
|
||||
it("derives channel identity from the package directory", () => {
|
||||
for (const channel of ["feishu", "weixin"]) {
|
||||
const source = readFileSync(
|
||||
resolve(process.cwd(), `../nanobot/channels/${channel}/webui/index.tsx`),
|
||||
"utf8",
|
||||
);
|
||||
expect(source).not.toMatch(/\bchannel\s*:/);
|
||||
}
|
||||
});
|
||||
|
||||
it("includes channel-owned UI in Tailwind's production scan", () => {
|
||||
const source = readFileSync(resolve(process.cwd(), "tailwind.config.js"), "utf8");
|
||||
|
||||
|
||||
@@ -228,7 +228,6 @@ const LOCALIZED_CHANNEL_SHELL_KEYS = [
|
||||
"settings.channels.instanceConfigured",
|
||||
"settings.channels.instanceNeedsSetup",
|
||||
"settings.channels.managedByWebui",
|
||||
"settings.channels.officialGuide",
|
||||
"settings.channels.optional",
|
||||
"settings.channels.providerPreset",
|
||||
"settings.channels.requiredSetup",
|
||||
@@ -237,11 +236,9 @@ const LOCALIZED_CHANNEL_SHELL_KEYS = [
|
||||
"settings.channels.savedSettings",
|
||||
"settings.channels.saveSettings",
|
||||
"settings.channels.selectChannel",
|
||||
"settings.channels.setupSteps",
|
||||
"settings.channels.showSecret",
|
||||
"settings.channels.toggleChannel",
|
||||
"settings.channels.toggleInstance",
|
||||
"settings.channels.tryIt",
|
||||
"settings.channels.validation.connected",
|
||||
"settings.channels.validation.configured",
|
||||
"settings.channels.validation.invalid",
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import { act, cleanup, render, screen } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { AutomationsSettings } from "@/components/settings/system/AutomationsSettings";
|
||||
import i18n from "@/i18n";
|
||||
|
||||
afterEach(cleanup);
|
||||
|
||||
function renderAutomations(channel: string) {
|
||||
return render(
|
||||
<AutomationsSettings
|
||||
payload={{ jobs: [{
|
||||
id: "task-1",
|
||||
name: "Scheduled task",
|
||||
enabled: true,
|
||||
schedule: { kind: "every", every_ms: 60_000 },
|
||||
payload: { message: "Summarize updates" },
|
||||
state: {},
|
||||
origin: { channel },
|
||||
}] }}
|
||||
loading={false}
|
||||
query=""
|
||||
filter="all"
|
||||
sort="name"
|
||||
actionKey={null}
|
||||
error={null}
|
||||
onQueryChange={vi.fn()}
|
||||
onFilterChange={vi.fn()}
|
||||
onSortChange={vi.fn()}
|
||||
onAction={vi.fn()}
|
||||
onRequestEdit={vi.fn()}
|
||||
onRequestDelete={vi.fn()}
|
||||
onBackToChat={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("automation channel identity", () => {
|
||||
it("uses channel-owned names in the list and details when the language changes", async () => {
|
||||
renderAutomations("email");
|
||||
expect(screen.getAllByText("Email")).toHaveLength(2);
|
||||
|
||||
for (const [locale, name] of [
|
||||
["zh-CN", "电子邮件"],
|
||||
["ja", "メール"],
|
||||
["es", "Correo electrónico"],
|
||||
]) {
|
||||
await act(() => i18n.changeLanguage(locale));
|
||||
expect(screen.getAllByText(name)).toHaveLength(2);
|
||||
expect(screen.queryByText("Email")).not.toBeInTheDocument();
|
||||
}
|
||||
});
|
||||
|
||||
it("resolves aliases through the owning channel namespace", async () => {
|
||||
await i18n.changeLanguage("zh-CN");
|
||||
renderAutomations("wechat");
|
||||
expect(screen.getAllByText("微信")).toHaveLength(2);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["api", "API"],
|
||||
["cli", "CLI"],
|
||||
["extension-chat", "extension-chat"],
|
||||
])("preserves the label for %s", (channel, label) => {
|
||||
renderAutomations(channel);
|
||||
expect(screen.getAllByText(label)).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
File diff suppressed because it is too large.
Load diff
@@ -162,7 +162,7 @@ describe("Settings system domains", () => {
|
||||
expect(screen.getByTestId("settings-section-transition")).not.toHaveClass("settings-feature-page");
|
||||
});
|
||||
|
||||
it("does not show the Settings kicker on the standalone Automations surface", async () => {
|
||||
it("opens a chat from the standalone automations empty state", async () => {
|
||||
const onBackToChat = vi.fn();
|
||||
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => {
|
||||
const url = String(input);
|
||||
@@ -389,7 +389,7 @@ describe("Settings system domains", () => {
|
||||
expect(screen.getByRole("button", { name: "MCP" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows nanobot optional features and enables one", async () => {
|
||||
it("installs optional channel support before enabling and disabling it", async () => {
|
||||
const fetchMock = vi.fn(async (input: RequestInfo | URL) => {
|
||||
const url = String(input);
|
||||
if (url === "/api/settings") return jsonResponse(settingsPayload());
|
||||
@@ -403,6 +403,7 @@ describe("Settings system domains", () => {
|
||||
webui: "webui/index.ts",
|
||||
type: "channel",
|
||||
enabled: false,
|
||||
configured: true,
|
||||
installed: false,
|
||||
ready: false,
|
||||
status: "missing_dependency",
|
||||
@@ -415,25 +416,31 @@ describe("Settings system domains", () => {
|
||||
return { ok: false, status: 404, json: async () => ({}) } as Response;
|
||||
});
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
requestMutationMock.mockImplementation(async (action: string) => {
|
||||
requestMutationMock.mockImplementation(async (action: string, values: Record<string, unknown>) => {
|
||||
if (action === "settings.feature.enable") {
|
||||
const enabled = values.install_only !== true;
|
||||
return {
|
||||
features: [{
|
||||
name: "matrix",
|
||||
display_name: "Matrix",
|
||||
webui: "webui/index.ts",
|
||||
type: "channel",
|
||||
enabled: true,
|
||||
running: true,
|
||||
runtime_status: "running",
|
||||
enabled,
|
||||
running: enabled,
|
||||
runtime_status: enabled ? "running" : "stopped",
|
||||
configured: true,
|
||||
installed: true,
|
||||
ready: true,
|
||||
status: "enabled",
|
||||
status: enabled ? "enabled" : "not_enabled",
|
||||
install_supported: true,
|
||||
requires_restart: true,
|
||||
}],
|
||||
enabled_count: 1,
|
||||
last_action: { ok: true, message: "Enabled channel 'matrix'", enabled: true },
|
||||
enabled_count: enabled ? 1 : 0,
|
||||
last_action: {
|
||||
ok: true,
|
||||
message: enabled ? "Enabled channel 'matrix'" : "Installed support for channel 'matrix'",
|
||||
enabled,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (action === "settings.feature.disable") {
|
||||
@@ -463,13 +470,23 @@ describe("Settings system domains", () => {
|
||||
const matrixRow = await screen.findByRole("button", { name: "View Matrix settings" });
|
||||
expect(matrixRow).toHaveAttribute("aria-haspopup", "dialog");
|
||||
fireEvent.click(matrixRow);
|
||||
expect(screen.getByRole("heading", { name: "Matrix", exact: true })).toBeVisible();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Matrix channel" }));
|
||||
expect(screen.getByRole("dialog", { name: "Install support for Matrix?" })).toBeInTheDocument();
|
||||
expect(screen.getByText("nanobot will add what Matrix needs, then turn it on. Continue?")).toBeInTheDocument();
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("switch", { name: "Matrix channel" })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Install Matrix" })).toHaveFocus();
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Install and enable" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Install Matrix" }));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.feature.enable",
|
||||
{ name: "matrix", install_only: true },
|
||||
150_000,
|
||||
),
|
||||
);
|
||||
const matrixToggle = await screen.findByRole("switch", { name: "Matrix channel" });
|
||||
expect(matrixToggle).toHaveAttribute("aria-checked", "false");
|
||||
expect(requestMutationMock).toHaveBeenCalledTimes(1);
|
||||
fireEvent.click(matrixToggle);
|
||||
|
||||
await waitFor(() =>
|
||||
expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
|
||||
Reference in new issue
Block a user