Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

test(mobile): 补充队列菜单状态行为覆盖

DavidShen7f5e8da1246b
diff --git a/apps/mobile/src/__tests__/pendingSendItems.test.ts b/apps/mobile/src/__tests__/pendingSendItems.test.ts
index 01a4c6918d..67c2c7d108 100644
--- a/apps/mobile/src/__tests__/pendingSendItems.test.ts
+++ b/apps/mobile/src/__tests__/pendingSendItems.test.ts
@@ -9,7 +9,9 @@
import { describe, expect, it } from 'vitest';
import { formatQuoteForSend } from '@cindy/maker-shared/chat-quotes';
import {
+ buildMobileMessageListExtraData,
buildPendingSendItems,
+ isPendingSendItemSelected,
pendingSendItemKey,
pendingSendSpins,
type MobilePendingSendActions,
@@ -186,6 +188,26 @@ describe('buildPendingSendItems', () => {
});
describe('pending_send 渲染接线', () => {
+ it('changes the list refresh signal and exposes queue actions when a bubble is selected', () => {
+ const [item] = build({
+ queue: [queued('selected')],
+ presentationByClientId: new Map([['selected', {
+ actions: {
+ remove: { disabled: false, disabledReason: null },
+ edit: { disabled: false, disabledReason: null },
+ steer: { disabled: false, disabledReason: null },
+ },
+ hint: null,
+ }]]),
+ });
+ const collapsed = buildMobileMessageListExtraData(null, false);
+ const expanded = buildMobileMessageListExtraData(item.clientId, false);
+
+ expect(expanded).not.toEqual(collapsed);
+ expect(isPendingSendItemSelected(item, collapsed.pendingSendSelectedClientId)).toBe(false);
+ expect(isPendingSendItemSelected(item, expanded.pendingSendSelectedClientId)).toBe(true);
+ });
+
it('keeps pendingSend on the renderer actions object', async () => {
// 回归防线:MessageRenderer 的 actions 是显式组装的 useMemo。漏掉这一项时 props 和
// 类型都还对(interface 上有、JSX 也传了),但 actions.pendingSend 是 undefined,渲染
@@ -200,7 +222,7 @@ describe('pending_send 渲染接线', () => {
const actionsEnd = source.indexOf('viewportLayout.contentWidth,\n ]);', actionsStart);
const actionsBlock = source.slice(actionsStart, actionsEnd);
expect(actionsBlock).toContain('pendingSend,');
- expect(source).toContain('pendingSendSelectedClientId: pendingSend?.selectedClientId ?? null');
+ expect(source).toContain('buildMobileMessageListExtraData(');
expect(source).toContain('extraData={messageListExtraData}');
// 渲染分支存在,且 items 的联合类型里有这一支。
expect(source).toContain("case 'pending_send':");
diff --git a/apps/mobile/src/session/MessageRenderer.tsx b/apps/mobile/src/session/MessageRenderer.tsx
index 761ce54dd8..8773ca3898 100644
--- a/apps/mobile/src/session/MessageRenderer.tsx
+++ b/apps/mobile/src/session/MessageRenderer.tsx
@@ -237,6 +237,7 @@ import {
PendingSendBubble,
type PendingSendBubbleActions,
} from '@/session/PendingSendBubble';
+import { buildMobileMessageListExtraData } from '@/session/pendingSendItems';
import { dedupeToolMediaByUrl } from '@cindy/maker-shared/message-render';
import { tokenizeThinkingText } from '@cindy/maker-shared/thinking-text';
import {
@@ -1385,10 +1386,13 @@ export function MessageRenderer({
// pending_send 的展开态不改变 listData;LegendList 会复用现有行,单靠 renderItem
// 闭包更新不足以保证可见行重绘。把选中项显式纳入 extraData,确保轻点气泡后
// 「取消 / 编辑 / 插话」操作行立即出现,不依赖滚动触发回收重渲染。
- const messageListExtraData = useMemo(() => ({
- pendingSendSelectedClientId: pendingSend?.selectedClientId ?? null,
- shareSelectionActive,
- }), [pendingSend?.selectedClientId, shareSelectionActive]);
+ const messageListExtraData = useMemo(
+ () => buildMobileMessageListExtraData(
+ pendingSend?.selectedClientId ?? null,
+ shareSelectionActive === true,
+ ),
+ [pendingSend?.selectedClientId, shareSelectionActive],
+ );
return (
// chat-text-quote:Provider 恒挂载(值可为 null),避免启用态翻转时整棵消息树
diff --git a/apps/mobile/src/session/PendingSendBubble.tsx b/apps/mobile/src/session/PendingSendBubble.tsx
index 5d4e326bba..f1e67cbe50 100644
--- a/apps/mobile/src/session/PendingSendBubble.tsx
+++ b/apps/mobile/src/session/PendingSendBubble.tsx
@@ -30,7 +30,11 @@ import {
getSentAttachmentThumbUri,
useSentAttachmentThumbsVersion,
} from '@/session/sentAttachmentThumbStore';
-import { pendingSendSpins, type MobilePendingSendItem } from '@/session/pendingSendItems';
+import {
+ isPendingSendItemSelected,
+ pendingSendSpins,
+ type MobilePendingSendItem,
+} from '@/session/pendingSendItems';
import {
isDesktopLocalMediaUrl,
type ResolveRemoteMediaFn,
@@ -191,7 +195,7 @@ export function PendingSendBubble({
const editing = item.phase === 'editing';
const failed = item.phase === 'failed';
const interactive = item.actions !== null || failed;
- const selected = interactive && actions.selectedClientId === item.clientId;
+ const selected = isPendingSendItemSelected(item, actions.selectedClientId);
const bubbleLabel = item.text || t('message.queue.attachmentMessage');
const uploadsPending = item.phase === 'uploading';
const rendersSentInlineBody = item.sentInlineTokens.some((token) => token.kind !== 'text');
diff --git a/apps/mobile/src/session/pendingSendItems.ts b/apps/mobile/src/session/pendingSendItems.ts
index a28a0b0f2c..f74d39099e 100644
--- a/apps/mobile/src/session/pendingSendItems.ts
+++ b/apps/mobile/src/session/pendingSendItems.ts
@@ -73,6 +73,31 @@ export interface MobilePendingSendItem {
hint: string | null;
}
+export interface MobileMessageListExtraData {
+ pendingSendSelectedClientId: string | null;
+ shareSelectionActive: boolean;
+}
+
+/**
+ * LegendList 的行外刷新信号。待发送气泡的展开态不改变 data,必须把选中项放进
+ * extraData,才能让已复用的可见行重新计算操作区。
+ */
+export function buildMobileMessageListExtraData(
+ pendingSendSelectedClientId: string | null,
+ shareSelectionActive: boolean,
+): MobileMessageListExtraData {
+ return { pendingSendSelectedClientId, shareSelectionActive };
+}
+
+/** 待发送气泡是否处于展开态;生产渲染与状态转换测试共用同一判据。 */
+export function isPendingSendItemSelected(
+ item: Pick<MobilePendingSendItem, 'actions' | 'clientId' | 'phase'>,
+ selectedClientId: string | null,
+): boolean {
+ const interactive = item.actions !== null || item.phase === 'failed';
+ return interactive && selectedClientId === item.clientId;
+}
+
export function pendingSendItemKey(clientId: string): string {
return `message-${clientId}`;
}