Skip to content

Commit 25abd5b

Browse files
committed
Adding unit tests for ai panel
1 parent 3b05a6f commit 25abd5b

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

ui/test/ai_panel_test.dart

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:ui/ai_panel.dart';
4+
5+
void main() {
6+
group('AiChatPanel', () {
7+
testWidgets('renders and hides with show=false', (WidgetTester tester) async {
8+
await tester.pumpWidget(
9+
MaterialApp(
10+
home: AiChatPanel(
11+
show: false,
12+
provider: null,
13+
systemPrompt: '',
14+
currentGraph: null,
15+
),
16+
),
17+
);
18+
// Should have opacity 0.0
19+
final animatedOpacity = tester.widget<AnimatedOpacity>(find.byType(AnimatedOpacity));
20+
expect(animatedOpacity.opacity, equals(0.0));
21+
});
22+
23+
testWidgets('renders and shows with show=true', (WidgetTester tester) async {
24+
await tester.pumpWidget(
25+
MaterialApp(
26+
home: AiChatPanel(
27+
show: true,
28+
provider: null,
29+
systemPrompt: '',
30+
currentGraph: null,
31+
),
32+
),
33+
);
34+
// Should find header
35+
expect(find.text('AI Assistant'), findsOneWidget);
36+
});
37+
38+
testWidgets('calls onClose when close button is tapped', (WidgetTester tester) async {
39+
bool closed = false;
40+
await tester.pumpWidget(
41+
MaterialApp(
42+
home: AiChatPanel(
43+
show: true,
44+
provider: null,
45+
systemPrompt: '',
46+
currentGraph: null,
47+
onClose: () => closed = true,
48+
),
49+
),
50+
);
51+
await tester.tap(find.byIcon(Icons.close));
52+
expect(closed, isTrue);
53+
});
54+
55+
testWidgets('shows No AI provider if provider is null', (WidgetTester tester) async {
56+
await tester.pumpWidget(
57+
MaterialApp(
58+
home: AiChatPanel(
59+
show: true,
60+
provider: null,
61+
systemPrompt: '',
62+
currentGraph: null,
63+
),
64+
),
65+
);
66+
expect(find.text('No AI provider'), findsOneWidget);
67+
});
68+
69+
testWidgets('animates panel visibility when show changes', (WidgetTester tester) async {
70+
await tester.pumpWidget(
71+
MaterialApp(
72+
home: AiChatPanel(
73+
show: false,
74+
provider: null,
75+
systemPrompt: '',
76+
currentGraph: null,
77+
),
78+
),
79+
);
80+
81+
// Initially hidden - opacity should be 0
82+
final initialOpacity = tester.widget<AnimatedOpacity>(find.byType(AnimatedOpacity));
83+
expect(initialOpacity.opacity, equals(0.0));
84+
85+
// Change to show
86+
await tester.pumpWidget(
87+
MaterialApp(
88+
home: AiChatPanel(
89+
show: true,
90+
provider: null,
91+
systemPrompt: '',
92+
currentGraph: null,
93+
),
94+
),
95+
);
96+
97+
// Should animate to visible - opacity should be 1
98+
final finalOpacity = tester.widget<AnimatedOpacity>(find.byType(AnimatedOpacity));
99+
expect(finalOpacity.opacity, equals(1.0));
100+
});
101+
});
102+
}

0 commit comments

Comments
 (0)