Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

feat(web): a greyed-out remote-control switch explains what is missing (#1029)

lmlihengd478fa8982b4
diff --git a/changelog/unreleased/2026-10-12-messaging-enable-hint.md b/changelog/unreleased/2026-10-12-messaging-enable-hint.md
new file mode 100644
index 00000000..09265a58
--- /dev/null
+++ b/changelog/unreleased/2026-10-12-messaging-enable-hint.md
@@ -0,0 +1,15 @@
+# A greyed-out remote-control switch says what to do first
+
+- **Date:** 2026-10-12
+- **Type:** feature
+- **Scope:** `web`, `docs`
+
+[中文版](2026-10-12-messaging-enable-hint.zh.md)
+
+Ported from upstream PenguinHarness (#1029, commit `7e97d50b`).
+
+In a conversation's remote-control editor, the **Enable connection** switch stays greyed out while a step is missing, but a click on it is no longer ignored. The click sends nothing to the server. It shows the hint line's reason as a toast, briefly highlights that line, and moves the focus to where the step is done: the QR code on WeChat and QQ, the first empty credential field on Feishu and Telegram, or the **Save** button when the form has unsaved changes. When another channel holds the connection, the reason names that channel and the focus stays where it is.
+
+The missing-credential reason is worded per channel: scan on WeChat, scan or enter and save the App ID and App Secret on QQ, enter and save the App ID and App Secret on Feishu, and enter and save the Bot Token on Telegram. The Remote control documentation describes the click.
+
+No API, wire format or stored data changes.
diff --git a/changelog/unreleased/2026-10-12-messaging-enable-hint.zh.md b/changelog/unreleased/2026-10-12-messaging-enable-hint.zh.md
new file mode 100644
index 00000000..f719443b
--- /dev/null
+++ b/changelog/unreleased/2026-10-12-messaging-enable-hint.zh.md
@@ -0,0 +1,15 @@
+# 远程控制的启用开关置灰时,点击会说明先做什么
+
+- **Date:** 2026-10-12
+- **Type:** feature
+- **Scope:** `web`, `docs`
+
+[English](2026-10-12-messaging-enable-hint.md)
+
+移植自上游 PenguinHarness(#1029,提交 `7e97d50b`)。
+
+对话的远程控制编辑器里,前序步骤未完成时**启用连接**开关仍呈置灰样式,但点击它不再没有反应。点击不会向服务器发出请求:它把提示行的原因弹为提示消息,短暂强调该行,并把焦点移到要补的地方。微信和 QQ 移到扫码区,飞书和 Telegram 移到第一个未填写的凭证字段,表单有未保存的修改时移到**保存**按钮。另一个渠道已启用时,提示会点名该渠道,焦点保持不动。
+
+缺少凭证时的提示按渠道措辞:微信为扫码,QQ 为扫码或填写并保存 App ID 与 App Secret,飞书为填写并保存 App ID 与 App Secret,Telegram 为填写并保存 Bot Token。远程控制文档补充了这一行为。
+
+接口、线上格式与已存数据都没有变化。
diff --git a/packages/docs/content/remote-control.en.md b/packages/docs/content/remote-control.en.md
index abaf5ccc..e9dbc8e0 100644
--- a/packages/docs/content/remote-control.en.md
+++ b/packages/docs/content/remote-control.en.md
@@ -53,7 +53,7 @@ The settings run from top to bottom in this order:
Below the form, three collapsed sections explain the selected channel: **Set up the bot** (the setup steps and an **Open tutorial** link), **What binding does**, and **Troubleshooting**.
-When the **Enable connection** switch is unavailable, a line under the test buttons says why: the credentials are not saved yet, the form has unsaved changes, or another channel of this conversation is already enabled.
+When the **Enable connection** switch is greyed out, a line under the test buttons says why: the credentials are not saved yet, the form has unsaved changes, or another channel of this conversation is already enabled. Selecting the greyed-out switch also says what is missing (a scan, the credentials, a save, or another channel to turn off first) and, for the first three, moves the focus to where you do it.
A saved secret is never shown again. Leave its field empty to keep it. To delete it, turn off the connection, select the clear option under the field, such as **Clear stored App Secret** or **Clear stored Bot Token**, and select **Save**.
diff --git a/packages/docs/content/remote-control.zh.md b/packages/docs/content/remote-control.zh.md
index 949895a3..466de543 100644
--- a/packages/docs/content/remote-control.zh.md
+++ b/packages/docs/content/remote-control.zh.md
@@ -53,7 +53,7 @@ description: 把对话连接到飞书、Telegram、QQ 或微信机器人,在
表单下方有三个折叠区块,讲解所选渠道:**如何创建机器人**(包括设置步骤和**前往教程**链接)、**绑定后会发生什么**和**常见问题**。
-**启用连接**开关不可用时,测试按钮下方会写明原因:凭证还没保存、表单有未保存的修改,或者这个对话已经启用了另一个渠道。
+**启用连接**开关置灰时,测试按钮下方会写明原因:凭证还没保存、表单有未保存的修改,或者这个对话已经启用了另一个渠道。点击置灰的开关,也会提示还差哪一步(扫码、填写凭证、保存,或先停用另一个渠道);前三种情况还会把焦点移到要操作的地方。
已保存的密钥不会再显示出来。字段留空即保留原密钥。要删除密钥,先关闭连接,再勾选字段下方的清除选项,例如 **清除已存 App Secret** 或 **清除已存 Bot Token**,然后选择**保存**。
diff --git a/packages/web/src/features/messaging/messaging-binding-editor.tsx b/packages/web/src/features/messaging/messaging-binding-editor.tsx
index 73d3303f..ad8e829c 100644
--- a/packages/web/src/features/messaging/messaging-binding-editor.tsx
+++ b/packages/web/src/features/messaging/messaging-binding-editor.tsx
@@ -39,7 +39,7 @@
* The GET is re-polled while the host shows the editor (the hook's `poll` flag) so
* connect/error flips show up live.
*/
-import { useEffect, useRef, useState } from "react";
+import { useEffect, useId, useRef, useState } from "react";
import type { ReactNode } from "react";
import type {
MessagingBindingInfo,
@@ -84,6 +84,13 @@ import {
/** How often the visible editor refreshes the runtime status (connects settle within a poll or two). */
const STATUS_POLL_MS = 3000;
+/** How long the hint line holds its attention colour after a click on the gated switch. */
+const HINT_EMPHASIS_MS = 1500;
+
+/** What a focus hand-off may land on inside the scan block; the first match wins. */
+const FOCUSABLE =
+ "button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex='-1'])";
+
/**
* Per-channel external links: the walkthrough (setup FAQ fold) and where the channel issues
* the credential (field corner). The second is a developer console for some channels and a
@@ -219,10 +226,15 @@ export interface MessagingBindingEditorState {
sendingTest: boolean;
/** The credential probe needs a testable credential: the selected channel's draft or stored secret. */
testable: boolean;
- /** The enable switch is gated (see toggleHint for the reason shown to the user). */
- toggleBlocked: boolean;
- /** Why the switch is gated, when a reason is worth showing (null otherwise). */
- toggleHint: string | null;
+ /** A save or a toggle is in flight: the switch is natively disabled until it settles. */
+ toggleBusy: boolean;
+ /**
+ * What must happen before the switch may enable the selected channel (null when nothing
+ * must). The switch only looks disabled while gated: a click explains instead of toggling.
+ */
+ enableGate: EnablePrerequisite | null;
+ /** The id hosts give their Save action, so a switch gated on unsaved edits can focus it. */
+ saveButtonId: string;
/**
* A flow OUTSIDE the form saved this channel's binding — either scan-to-connect, whose
* credentials never pass through the browser. Folds the result into that channel's facts
@@ -272,6 +284,57 @@ export function telegramTestNotices(res: TelegramTestResponse): MessagingTestNot
return notices;
}
+/** Where a click on the prerequisite-gated switch moves focus. */
+export type EnableFocus = "scan" | "credential" | "save";
+
+/** The unmet prerequisite that keeps the selected channel from being enabled. */
+export interface EnablePrerequisite {
+ /** The sentence the hint line shows, and a click on the switch repeats as a toast. */
+ hint: string;
+ /**
+ * Where that click sends focus: the QR block on the scan channels, the first empty
+ * credential field on the typed ones, or the Save action. Null when the fix is turning
+ * another channel off, which is not on this form.
+ */
+ focus: EnableFocus | null;
+}
+
+/**
+ * Why the selected channel cannot be enabled yet, strongest reason first: another channel
+ * holds the connection, no credential is stored, the form has unsaved edits. Null when it can,
+ * and always while it is enabled: turning a live connection off is never gated.
+ */
+export function enablePrerequisite({
+ channel,
+ facts,
+ enabledChannel,
+ dirty,
+}: {
+ channel: MessagingChannel;
+ facts: Pick<MessagingChannelFacts, "enabled" | "secretConfigured">;
+ /** The channel enabled on this Session, if any. */
+ enabledChannel: MessagingChannel | null;
+ /** Unsaved edits on the selected channel's form. */
+ dirty: boolean;
+}): EnablePrerequisite | null {
+ if (facts.enabled) return null;
+ if (enabledChannel !== null && enabledChannel !== channel) {
+ return {
+ hint: S.messaging.otherEnabledHint(S.messaging.channelName[enabledChannel]),
+ focus: null,
+ };
+ }
+ if (!facts.secretConfigured) {
+ return {
+ hint: S.messaging.credentialMissingHint[channel],
+ // QQ's typed fields are the fallback below its QR, so the scan is where it starts too.
+ focus: channel === "qq" || channel === "wechat" ? "scan" : "credential",
+ };
+ }
+ if (dirty) return { hint: S.messaging.saveBeforeEnable, focus: "save" };
+ return null;
+}
+
export function useMessagingBinding(
sessionId: string,
opts: {
@@ -298,6 +361,7 @@ export function useMessagingBinding(
const [toggling, setToggling] = useState(false);
const [testing, setTesting] = useState(false);
const [sendingTest, setSendingTest] = useState(false);
+ const saveButtonId = useId();
/** Which session the form was loaded for (the initial load runs once per session, not per poll flip). */
const loadedFor = useRef<string | null>(null);
@@ -369,7 +433,6 @@ export function useMessagingBinding(
: channels.wechat.enabled
? "wechat"
: null;
- const otherEnabled = enabledChannel !== null && enabledChannel !== selected;
const dirty = form !== null && baseline !== null && formDirty(form, baseline);
/** One channel's PUT/state response lands only in that channel's facts + form baseline. */
@@ -480,17 +543,9 @@ export function useMessagingBinding(
}
};
- // Enabling needs a saved credential, no unsaved edits, and the other channel dark;
- // disabling is always allowed. The hint names the strongest reason.
- const enableBlocked = !facts.enabled && (otherEnabled || !facts.secretConfigured || dirty);
- const toggleHint =
- !facts.enabled && enabledChannel !== null && otherEnabled
- ? S.messaging.otherEnabledHint(S.messaging.channelName[enabledChannel])
- : !facts.enabled && !facts.secretConfigured
- ? S.messaging.credentialMissingHint
- : !facts.enabled && dirty
- ? S.messaging.saveBeforeEnable
- : null;
+ // Enabling needs a saved credential, no unsaved edits, and the other channels dark;
+ // disabling is always allowed.
+ const enableGate = enablePrerequisite({ channel: selected, facts, enabledChannel, dirty });
return {
sessionId,
@@ -505,8 +560,9 @@ export function useMessagingBinding(
testing,
sendingTest,
testable: form !== null && formTestable(form, facts.secretConfigured),
- toggleBlocked: enableBlocked || toggling || busy,
- toggleHint,
+ toggleBusy: toggling || busy,
+ enableGate,
+ saveButtonId,
adoptBinding: (binding) =>
applyChannel(binding.channel, binding, channels[binding.channel].status),
save,
@@ -640,10 +696,62 @@ function DeliveryOptionRow({
* `MessagingBindingHelp` below that.
*/
export function MessagingBindingBody({ b }: { b: MessagingBindingEditorState }) {
+ // Per-instance ids for the gated switch's focus hand-off: a dialog and a dock panel may be
+ // open on the same Session at once, and a fixed id would send one's focus into the other.
+ const idBase = useId();
+ const [hintEmphasized, setHintEmphasized] = useState(false);
+ const emphasisTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
+ useEffect(() => {
+ return () => {
+ if (emphasisTimer.current !== null) clearTimeout(emphasisTimer.current);
+ };
+ }, []);
const { form } = b;
if (!form) return null;
const channel = form.channel;
const facts = b.channels[channel];
+ const gate = b.enableGate;
+ const hintInk = hintEmphasized ? toneInk.attention : "text-gray-400 dark:text-gray-500";
+ const ids = {
+ hint: `${idBase}-enable-hint`,
+ scan: `${idBase}-scan`,
+ appId: `${idBase}-app-id`,
+ appSecret: `${idBase}-app-secret`,
+ botToken: `${idBase}-bot-token`,
+ };
+ /**
+ * A click on the switch while a prerequisite is unmet sends nothing. It repeats the hint as
+ * a toast, turns the hint line to the attention colour for a moment, and moves focus to
+ * where the missing step is done. A click while the line is still lit skips the toast, so a
+ * few quick presses do not stack copies of one sentence.
+ */
+ const explainGate = (prerequisite: EnablePrerequisite) => {
+ if (emphasisTimer.current === null) toastInfo(prerequisite.hint);
+ else clearTimeout(emphasisTimer.current);
+ setHintEmphasized(true);
+ emphasisTimer.current = setTimeout(() => {
+ emphasisTimer.current = null;
+ setHintEmphasized(false);
+ }, HINT_EMPHASIS_MS);
+ if (prerequisite.focus === "scan") {
+ const block = document.getElementById(ids.scan);
+ block?.scrollIntoView({ block: "nearest" });
+ block?.querySelector<HTMLElement>(FOCUSABLE)?.focus({ preventScroll: true });
+ } else if (prerequisite.focus === "credential") {
+ // The first credential field still empty; with all of them typed, Save is what is left.
+ const fields: [id: string, value: string][] =
+ channel === "telegram"
+ ? [[ids.botToken, form.telegram.botToken]]
+ : [
+ [ids.appId, form.feishu.appId],
+ [ids.appSecret, form.feishu.appSecret],
+ ];
+ const empty = fields.find(([, value]) => value.trim() === "");
+ document.getElementById(empty?.[0] ?? b.saveButtonId)?.focus();
+ } else if (prerequisite.focus === "save") {
+ document.getElementById(b.saveButtonId)?.focus();
+ }
+ };
// The delivery preferences of the selected channel, and the patch that writes one back.
// Every sub-state carries the same three, so resolving the channel once here keeps the
// rows at the bottom free of a selector they have nothing to say about.
@@ -702,10 +810,23 @@ export function MessagingBindingBody({ b }: { b: MessagingBindingEditorState })
className="flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300"
data-tooltip={S.messaging.bindByEnableHint}
>
+ {/* Natively disabled only while a request is in flight. A missing prerequisite
+ dims it the same way but leaves it clickable (aria-disabled), because a
+ control that ignores a click never says what it is waiting for. */}
<Switch
checked={facts.enabled}
- disabled={b.toggleBlocked}
- onChange={(v) => void b.toggleEnabled(v)}
+ disabled={b.toggleBusy}
+ {...(gate !== null
+ ? {
+ "aria-disabled": true,
+ "aria-describedby": ids.hint,
+ className: "cursor-not-allowed opacity-60",
+ }
+ : {})}
+ onChange={(v) => {
+ if (gate !== null) explainGate(gate);
+ else void b.toggleEnabled(v);
+ }}
/>
{S.messaging.enabled}
</label>
@@ -818,8 +939,10 @@ export function MessagingBindingBody({ b }: { b: MessagingBindingEditorState })
{/* The gating reason closes the control block rather than sitting under the switch:
it comes and goes with the switch's own state, so anything below it shifts by a
line — trailing the probes leaves both of them at a fixed offset. */}
- {b.toggleHint !== null && (
- <p className="text-xs text-gray-400 dark:text-gray-500">{b.toggleHint}</p>
+ {gate !== null && (
+ <p id={ids.hint} className={`text-xs transition-colors ${hintInk}`}>
+ {gate.hint}
+ </p>
)}
{/* The credential fields trail the controls above; explanations live in the FAQ folds
below the save area. */}
@@ -842,6 +965,7 @@ export function MessagingBindingBody({ b }: { b: MessagingBindingEditorState })
>
<PasswordInput
size="sm"
+ id={ids.botToken}
aria-label={S.telegram.botToken}
{...(facts.secretConfigured ? { placeholder: S.telegram.botTokenKeepHint } : {})}
error={errorText(b.fieldErrors.botToken)}
@@ -871,11 +995,13 @@ export function MessagingBindingBody({ b }: { b: MessagingBindingEditorState })
{/* The easy path leads: scanning is what most people will do, and the fields below
are the fallback for a bot the scan cannot reach. Both are inside this channel's
branch, so nothing above the fields moves when the QR opens. */}
- <QQScanConnect
- sessionId={b.sessionId}
- enabled={facts.enabled}
- onBound={(binding) => b.adoptBinding(binding)}
- />
+ <div id={ids.scan}>
+ <QQScanConnect
+ sessionId={b.sessionId}
+ enabled={facts.enabled}
+ onBound={(binding) => b.adoptBinding(binding)}
+ />
+ </div>
<p className="text-xs text-gray-400 dark:text-gray-500">{S.qq.scanOrManual}</p>
<CornerLinkedField
label={S.qq.appId}
@@ -928,12 +1054,14 @@ export function MessagingBindingBody({ b }: { b: MessagingBindingEditorState })
<>
{/* The whole credential form: there is nothing to type on this channel, so the QR
is not the easy path but the only one. */}
- <WeChatScanConnect
- sessionId={b.sessionId}
- enabled={facts.enabled}
- bound={facts.secretConfigured}
- onBound={(binding) => b.adoptBinding(binding)}
- />
+ <div id={ids.scan}>
+ <WeChatScanConnect
+ sessionId={b.sessionId}
+ enabled={facts.enabled}
+ bound={facts.secretConfigured}
+ onBound={(binding) => b.adoptBinding(binding)}
+ />
+ </div>
{facts.secretMasked !== null && (
<StoredSecretRow
masked={facts.secretMasked}
@@ -964,6 +1092,7 @@ export function MessagingBindingBody({ b }: { b: MessagingBindingEditorState })
>
<Input
size="sm"
+ id={ids.appId}
aria-label={S.feishu.appId}
error={errorText(b.fieldErrors.appId)}
value={form.feishu.appId}
@@ -975,6 +1104,7 @@ export function MessagingBindingBody({ b }: { b: MessagingBindingEditorState })
</CornerLinkedField>
<PasswordInput
size="sm"
+ id={ids.appSecret}
label={S.feishu.appSecret}
{...(facts.secretConfigured
? { placeholder: S.feishu.appSecretKeepHint }
diff --git a/packages/web/src/features/messaging/messaging-binding-modal.tsx b/packages/web/src/features/messaging/messaging-binding-modal.tsx
index 89bef29f..b924b49c 100644
--- a/packages/web/src/features/messaging/messaging-binding-modal.tsx
+++ b/packages/web/src/features/messaging/messaging-binding-modal.tsx
@@ -57,6 +57,7 @@ export function MessagingBindingModal({
{S.common.close}
</Button>
<Button
+ id={b.saveButtonId}
size="sm"
variant="primary"
disabled={b.busy || b.form === null}
diff --git a/packages/web/src/features/messaging/messaging-panel.tsx b/packages/web/src/features/messaging/messaging-panel.tsx
index a2f0eda4..25155af6 100644
--- a/packages/web/src/features/messaging/messaging-panel.tsx
+++ b/packages/web/src/features/messaging/messaging-panel.tsx
@@ -36,7 +36,13 @@ export function MessagingPanel({ sessionId, active }: { sessionId: string; activ
<MessagingBindingBody b={b} />
{/* The dialog places Save in its footer; the panel keeps it under the form. */}
<div className="flex items-center justify-end gap-2">
- <Button variant="primary" size="sm" disabled={b.busy} onClick={() => void b.save()}>
+ <Button
+ id={b.saveButtonId}
+ variant="primary"
+ size="sm"
+ disabled={b.busy}
+ onClick={() => void b.save()}
+ >
{b.busy ? S.common.saving : S.common.save}
</Button>
</div>
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index 509cba6b..695355fe 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -3774,8 +3774,16 @@ export const en: Strings = {
/** Why the enable switch is gated while the OTHER channel holds the connection. */
otherEnabledHint: (other: string): string =>
`Only one channel can be enabled per conversation: turn off the ${other} connection first`,
- /** Why the enable switch is gated while the selected channel has no stored credential. */
- credentialMissingHint: "Enter and save the credential first, then enable the connection",
+ /**
+ * Why the enable switch is gated while the selected channel has no stored credential — one
+ * per channel, because what is missing differs: a scan, typed fields, or either.
+ */
+ credentialMissingHint: {
+ feishu: "Enter and save the App ID and App Secret first, then enable the connection",
+ telegram: "Enter and save the Bot Token first, then enable the connection",
+ qq: "Scan the QR code, or enter and save the App ID and App Secret, then enable the connection",
+ wechat: "Scan the QR code to link WeChat first, then enable the connection",
+ },
/** Why the clear checkbox is gated while the channel's connection is enabled. */
disableBeforeClearHint: "Disable the connection before clearing the credential",
/** The saved delivery option: render a reply's Markdown in the channel's own markup. */
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index 97e82979..23902b60 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -3816,8 +3816,16 @@ export const zh = {
},
/** Why the enable switch is gated while the OTHER channel holds the connection. */
otherEnabledHint: (other: string): string => `同一会话只能启用一个渠道:先停用${other}连接`,
- /** Why the enable switch is gated while the selected channel has no stored credential. */
- credentialMissingHint: "先填写并保存凭证,再启用连接",
+ /**
+ * Why the enable switch is gated while the selected channel has no stored credential — one
+ * per channel, because what is missing differs: a scan, typed fields, or either.
+ */
+ credentialMissingHint: {
+ feishu: "先填写 App ID 与 App Secret 并保存,再启用连接",
+ telegram: "先填写 Bot Token 并保存,再启用连接",
+ qq: "先扫码,或填写 App ID 与 App Secret 并保存,再启用连接",
+ wechat: "先扫码绑定微信,再启用连接",
+ },
/** Why the clear checkbox is gated while the channel's connection is enabled. */
disableBeforeClearHint: "先停用连接,才能清除凭证",
/** The saved delivery option: render a reply's Markdown in the channel's own markup. */
diff --git a/packages/web/test/messaging-binding-editor.test.ts b/packages/web/test/messaging-binding-editor.test.ts
index fbb55611..5306ef7b 100644
--- a/packages/web/test/messaging-binding-editor.test.ts
+++ b/packages/web/test/messaging-binding-editor.test.ts
@@ -8,6 +8,8 @@
* - A stored secret is removed through the clear checkbox, gated on screen while the channel
* holds the connection; the connection switch carries the bind/unbind sentence as its
* tooltip, and its gating reason when another channel holds the connection.
+ * - A gated switch stays clickable; the gate names, per channel, what is missing and where a
+ * click sends focus to supply it.
* - A connection error gets its own line, whole, and stays on screen after the connection
* recovers; arrival is reported while connecting and erroring, naming the inbound stage when
* a message arrived but its task never started.
@@ -26,6 +28,7 @@ import type { MessagingChannel } from "@lmliheng/penguin-server/api";
import {
MessagingBindingBody,
MessagingBindingHelp,
+ enablePrerequisite,
telegramTestNotices,
type MessagingBindingEditorState,
type MessagingChannelFacts,
@@ -79,8 +82,9 @@ function stateOf(
testing: false,
sendingTest: false,
testable: false,
- toggleBlocked: false,
- toggleHint: null,
+ toggleBusy: false,
+ enableGate: null,
+ saveButtonId: "save-under-test",
adoptBinding: () => {},
save: noop,
toggleEnabled: noop,
@@ -460,16 +464,66 @@ describe("MessagingBindingBody", () => {
);
});
- it("shows the switch's gating reason when the other channel holds the connection", () => {
+ it("shows the switch's gating reason, and leaves a gated switch clickable", () => {
const hint = S.messaging.otherEnabledHint(S.messaging.channelName.feishu);
const html = render(
stateOf(
"telegram",
{ feishu: { ...DARK, secretConfigured: true, enabled: true } },
- { toggleBlocked: true, toggleHint: hint },
+ { enableGate: { hint, focus: null } },
),
);
expect(html).toContain(hint);
+ // Dimmed and announced as unavailable, but not natively disabled: a click has to reach
+ // the handler that explains what to do first.
+ const toggle = /<button[^>]*role="switch"[^>]*>/.exec(html)?.[0] ?? "";
+ expect(toggle).toContain('aria-disabled="true"');
+ expect(toggle).not.toContain('disabled=""');
+ });
+});
+
+describe("enablePrerequisite", () => {
+ const stored = { enabled: false, secretConfigured: true };
+ const blank = { enabled: false, secretConfigured: false };
+
+ it("names what each channel is missing and where focus goes to supply it", () => {
+ const expected = {
+ feishu: "credential",
+ telegram: "credential",
+ qq: "scan",
+ wechat: "scan",
+ } as const;
+ for (const channel of ["feishu", "telegram", "qq", "wechat"] as MessagingChannel[]) {
+ // No stored credential: the per-channel sentence, focus on the scan or the typed field.
+ expect(
+ enablePrerequisite({ channel, facts: blank, enabledChannel: null, dirty: false }),
+ ).toEqual({ hint: S.messaging.credentialMissingHint[channel], focus: expected[channel] });
+ // Stored but edited since: save first.
+ expect(
+ enablePrerequisite({ channel, facts: stored, enabledChannel: null, dirty: true }),
+ ).toEqual({ hint: S.messaging.saveBeforeEnable, focus: "save" });
+ // Another channel holds the connection: that outranks the rest, and its fix is not on
+ // this form, so focus stays put.
+ const other: MessagingChannel = channel === "feishu" ? "telegram" : "feishu";
+ expect(
+ enablePrerequisite({ channel, facts: blank, enabledChannel: other, dirty: true }),
+ ).toEqual({
+ hint: S.messaging.otherEnabledHint(S.messaging.channelName[other]),
+ focus: null,
+ });
+ // Nothing missing; and turning a live connection off is never gated.
+ expect(
+ enablePrerequisite({ channel, facts: stored, enabledChannel: null, dirty: false }),
+ ).toBeNull();
+ expect(
+ enablePrerequisite({
+ channel,
+ facts: { enabled: true, secretConfigured: true },
+ enabledChannel: channel,
+ dirty: true,
+ }),
+ ).toBeNull();
+ }
});
});