File size: 1,673 Bytes
b225a21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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);
  });
}