cdcbaf4cee
平台壳生成完成和失败收口消费 notification.showLocal 新增 HostBridge 草稿通知 payload 与去重模型测试 迁移生成状态纯函数以通过组件 Fast Refresh 约束 更新原生壳方案、HostBridge 协议和共享决策记录
69 lines
2.2 KiB
TypeScript
69 lines
2.2 KiB
TypeScript
import { describe, expect, test, vi } from 'vitest';
|
|
|
|
import {
|
|
buildPlatformHostDraftFailureNotification,
|
|
buildPlatformHostDraftNotificationResetKeys,
|
|
buildPlatformHostDraftReadyNotification,
|
|
sendPlatformHostDraftNotificationOnce,
|
|
} from './platformHostNotificationModel';
|
|
|
|
describe('platformHostNotificationModel', () => {
|
|
test('builds draft ready notification from stable draft identity', () => {
|
|
expect(
|
|
buildPlatformHostDraftReadyNotification('match3d', [
|
|
'match3d-work-1',
|
|
'match3d-session-1',
|
|
]),
|
|
).toEqual({
|
|
key: 'draft-ready:match3d:抓大鹅草稿 match3d-session-1',
|
|
title: '生成完成',
|
|
body: '抓大鹅草稿 match3d-session-1 生成任务已完成,可以继续查看草稿。',
|
|
});
|
|
});
|
|
|
|
test('builds draft failure notification only when error text is useful', () => {
|
|
expect(
|
|
buildPlatformHostDraftFailureNotification('puzzle', [
|
|
'puzzle-session-1',
|
|
], ' 图片生成失败。 '),
|
|
).toEqual({
|
|
key: 'draft-failed:puzzle:拼图草稿 puzzle-session-1',
|
|
title: '生成失败',
|
|
body: '拼图草稿 puzzle-session-1 图片生成失败。',
|
|
});
|
|
expect(
|
|
buildPlatformHostDraftFailureNotification('puzzle', [
|
|
'puzzle-session-1',
|
|
], ' '),
|
|
).toBeNull();
|
|
expect(buildPlatformHostDraftReadyNotification('puzzle', [])).toBeNull();
|
|
});
|
|
|
|
test('sends host notification once and reset keys allow a later regeneration', () => {
|
|
const sentKeys = new Set<string>();
|
|
const send = vi.fn();
|
|
const notification = buildPlatformHostDraftReadyNotification('jump-hop', [
|
|
'jump-hop-session-1',
|
|
]);
|
|
|
|
expect(
|
|
sendPlatformHostDraftNotificationOnce(sentKeys, notification, send),
|
|
).toBe(true);
|
|
expect(
|
|
sendPlatformHostDraftNotificationOnce(sentKeys, notification, send),
|
|
).toBe(false);
|
|
expect(send).toHaveBeenCalledTimes(1);
|
|
|
|
for (const key of buildPlatformHostDraftNotificationResetKeys('jump-hop', [
|
|
'jump-hop-session-1',
|
|
])) {
|
|
sentKeys.delete(key);
|
|
}
|
|
|
|
expect(
|
|
sendPlatformHostDraftNotificationOnce(sentKeys, notification, send),
|
|
).toBe(true);
|
|
expect(send).toHaveBeenCalledTimes(2);
|
|
});
|
|
});
|