import 'package:flutter_test/flutter_test.dart'; import 'package:social_app/features/chat/data/models/ag_ui_event.dart'; void main() { group('AgUiEvent parsing', () { test('parses TEXT_MESSAGE_END with ui_schema payload', () { final event = AgUiEvent.fromJson({ 'type': 'TEXT_MESSAGE_END', 'messageId': 'msg_1', 'answer': '你好', 'role': 'assistant', 'status': 'success', 'ui_schema': { 'version': '2.0', 'root': { 'type': 'stack', 'direction': 'vertical', 'appearance': 'card', 'children': [ {'type': 'text', 'role': 'title', 'content': '创建成功'}, ], }, }, }); expect(event, isA()); final textEnd = event as TextMessageEndEvent; expect(textEnd.messageId, 'msg_1'); expect(textEnd.answer, '你好'); expect(textEnd.uiSchema?['version'], '2.0'); }); test('parses TOOL_CALL_RESULT snake_case fields', () { final event = AgUiEvent.fromJson({ 'type': 'TOOL_CALL_RESULT', 'messageId': 'tool_1', 'tool_call_id': 'call_1', 'tool_name': 'calendar_read', 'status': 'success', 'result': '找到 2 条结果', }); expect(event, isA()); final result = event as ToolCallResultEvent; expect(result.toolCallId, 'call_1'); expect(result.toolName, 'calendar_read'); expect(result.resultSummary, '找到 2 条结果'); expect(result.status, 'success'); }); test('parses history snapshot with ui_schema', () { final snapshot = HistorySnapshot.fromJson({ 'scope': 'history_day', 'threadId': 'thread_1', 'day': '2026-03-16', 'hasMore': false, 'messages': [ { 'id': 'm1', 'seq': 1, 'role': 'assistant', 'content': '已处理', 'ui_schema': { 'version': '2.0', 'root': { 'type': 'stack', 'direction': 'vertical', 'appearance': 'card', 'children': [], }, }, 'timestamp': '2026-03-16T10:00:00Z', }, ], }); expect(snapshot.scope, 'history_day'); expect(snapshot.messages, hasLength(1)); expect(snapshot.messages.first.uiSchema, isNotNull); }); test('parses history user attachments list', () { final snapshot = HistorySnapshot.fromJson({ 'scope': 'history_day', 'threadId': 'thread_1', 'day': '2026-03-16', 'hasMore': false, 'messages': [ { 'id': 'm1', 'seq': 1, 'role': 'user', 'content': '请看图', 'attachments': [ {'url': 'https://signed.example/a.png', 'mimeType': 'image/png'}, {'url': 'https://signed.example/b.jpg', 'mimeType': 'image/jpeg'}, ], 'timestamp': '2026-03-16T10:00:00Z', }, ], }); final userMessage = snapshot.messages.first; expect(userMessage.attachments, hasLength(2)); expect(userMessage.attachments.first.url, 'https://signed.example/a.png'); expect(userMessage.attachments.last.mimeType, 'image/jpeg'); }); }); }