Files
Auto-GPT/test/agent_message_tile_test.dart
hunteraraujo 33c900b73f Add AgentMessageTile Widget with Tests
This commit introduces the AgentMessageTile widget, a core component of the chat interface. The widget is designed to display agent messages, including a collapsible section for displaying a pretty-printed JSON code snippet.

The following features have been implemented:
- Rendering of agent title, message text, and expand/collapse button.
- Expandable section for displaying a JSON code snippet, complete with copy functionality.
- A minimum height constraint to ensure consistent appearance.
- Widget tests to validate rendering and interaction behavior.

These enhancements contribute to the overall chat functionality, providing a clear and interactive display of agent messages.
2023-08-24 21:17:11 -07:00

47 lines
1.6 KiB
Dart

import 'package:auto_gpt_flutter_client/views/chat/agent_message_tile.dart';
import 'package:auto_gpt_flutter_client/views/chat/json_code_snippet_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
// Test to verify that the AgentMessageTile renders correctly
testWidgets('Renders AgentMessageTile', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(
home: Scaffold(
body: AgentMessageTile(message: 'Test Message'),
),
));
// Verify that the agent title is displayed
expect(find.text('Agent'), findsOneWidget);
// Verify that the message text is displayed
expect(find.text('Test Message'), findsOneWidget);
});
// Test to verify that the expand/collapse functionality works
testWidgets('Toggle Expand/Collapse', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(
home: Scaffold(
body: AgentMessageTile(message: 'Test Message'),
),
));
// Verify that the JSON code snippet is not visible initially
expect(find.byType(JsonCodeSnippetView), findsNothing);
// Tap the expand/collapse button
await tester.tap(find.byIcon(Icons.keyboard_arrow_down));
await tester.pumpAndSettle();
// Verify that the JSON code snippet is now visible
expect(find.byType(JsonCodeSnippetView), findsOneWidget);
// Tap the expand/collapse button again
await tester.tap(find.byIcon(Icons.keyboard_arrow_up));
await tester.pumpAndSettle();
// Verify that the JSON code snippet is hidden again
expect(find.byType(JsonCodeSnippetView), findsNothing);
});
}