/** * GroupLiveService 的附件保留(2026-11-06) * * 回归点:`toMessage` 曾经丢掉 `MxMessage.media`, * 导致容器交付的 `m.file` / `m.image` 在群聊里只剩空气泡,刷新后也看不到。 */ import { TestBed } from '@angular/core/testing'; import { GroupLiveService } from './group-live.service'; import { GroupStoreService } from './group-store.service'; import { MatrixClientService } from './matrix-client.service'; import { FmodeApi } from './api/fmode-api'; import { SessionService } from './session.service'; describe('GroupLiveService → Message 转换', () => { let svc: GroupLiveService; beforeEach(() => { localStorage.clear(); TestBed.configureTestingModule({ providers: [ SessionService, GroupStoreService, GroupLiveService, { provide: MatrixClientService, useValue: {} }, { provide: FmodeApi, useValue: {} }, ], }); TestBed.inject(SessionService).setSession('r:t', { id: 'u1', name: 'x' } as never); svc = TestBed.inject(GroupLiveService); }); /** 通过私有方法验证:纯转换逻辑,不涉及网络 */ const toMessage = (agentId: string, m: Record): Record => ( svc as unknown as { toMessage: (a: string, x: Record) => Record; } ).toMessage(agentId, m); it('🔴 附件消息保留 media', () => { const out = toMessage('a1', { eventId: 'e1', sender: '@x:fmode.cn', senderName: 'lj', kind: 'text', body: '成果如下', ts: 1700000000000, live: true, media: { name: '报告.pdf', url: 'https://x/1.pdf', mimeType: 'application/pdf', size: 1234 }, }); expect(out['file']).toEqual({ kind: 'file', name: '报告.pdf', url: 'https://x/1.pdf', mimeType: 'application/pdf', size: 1234, }); }); it('纯文本消息不带 file 字段(避免渲染空附件卡)', () => { const out = toMessage('a1', { eventId: 'e2', sender: '@x:fmode.cn', kind: 'text', body: '你好', ts: 1700000000000, live: true, }); expect('file' in out).toBe(false); }); it('归属记在 agentId 上', () => { const out = toMessage('agent-x', { eventId: 'e3', sender: '@matrix-id:fmode.cn', kind: 'text', body: 'x', ts: 1, live: true, }); expect(out['conversationId']).toBe('agent-x'); }); });