Skip to content

Commit 223b584

Browse files
committed
Fix UI Providers Tests
1 parent 99e6d43 commit 223b584

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

lib/screens/dashboard.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Dashboard extends ConsumerWidget {
7777
onPressed: () {
7878
ref.read(navRailIndexStateProvider.notifier).state = 3;
7979
},
80-
icon: const Icon(Icons.terminal),
80+
icon: const Icon(Icons.terminal_outlined),
8181
selectedIcon: const Icon(Icons.terminal),
8282
),
8383
Text(

test/providers/ui_providers_test.dart

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
//import 'package:spot/spot.dart';
22
import 'package:apidash/providers/providers.dart';
33
import 'package:apidash/screens/common_widgets/common_widgets.dart';
4-
import 'package:apidash/screens/dashboard.dart';
54
import 'package:apidash/screens/envvar/environment_page.dart';
6-
import 'package:apidash/screens/home_page/collection_pane.dart';
75
import 'package:apidash/screens/home_page/editor_pane/details_card/response_pane.dart';
86
import 'package:apidash/screens/home_page/editor_pane/editor_default.dart';
97
import 'package:apidash/screens/home_page/editor_pane/editor_pane.dart';
108
import 'package:apidash/screens/home_page/editor_pane/url_card.dart';
119
import 'package:apidash/screens/home_page/home_page.dart';
10+
import 'package:apidash/screens/screens.dart';
1211
import 'package:apidash/screens/settings_page.dart';
1312
import 'package:apidash/screens/history/history_page.dart';
1413
import 'package:apidash/widgets/widgets.dart';
@@ -49,6 +48,7 @@ void main() {
4948
expect(find.byType(HomePage), findsOneWidget);
5049
expect(find.byType(EnvironmentPage), findsNothing);
5150
expect(find.byType(HistoryPage), findsNothing);
51+
expect(find.byType(TerminalPage), findsNothing);
5252
expect(find.byType(SettingsPage), findsNothing);
5353
});
5454

@@ -70,6 +70,7 @@ void main() {
7070
expect(find.byType(HomePage), findsNothing);
7171
expect(find.byType(EnvironmentPage), findsOneWidget);
7272
expect(find.byType(HistoryPage), findsNothing);
73+
expect(find.byType(TerminalPage), findsNothing);
7374
expect(find.byType(SettingsPage), findsNothing);
7475
});
7576

@@ -93,10 +94,11 @@ void main() {
9394
expect(find.byType(HomePage), findsNothing);
9495
expect(find.byType(EnvironmentPage), findsNothing);
9596
expect(find.byType(HistoryPage), findsOneWidget);
97+
expect(find.byType(TerminalPage), findsNothing);
9698
expect(find.byType(SettingsPage), findsNothing);
9799
});
98100
testWidgets(
99-
"Dashboard should display SettingsPage when navRailIndexStateProvider is 3",
101+
"Dashboard should display TerminalPage when navRailIndexStateProvider is 3",
100102
(WidgetTester tester) async {
101103
await tester.pumpWidget(
102104
ProviderScope(
@@ -115,6 +117,31 @@ void main() {
115117
expect(find.byType(HomePage), findsNothing);
116118
expect(find.byType(EnvironmentPage), findsNothing);
117119
expect(find.byType(HistoryPage), findsNothing);
120+
expect(find.byType(TerminalPage), findsOneWidget);
121+
expect(find.byType(SettingsPage), findsNothing);
122+
});
123+
124+
testWidgets(
125+
"Dashboard should display SettingsPage when navRailIndexStateProvider is 4",
126+
(WidgetTester tester) async {
127+
await tester.pumpWidget(
128+
ProviderScope(
129+
overrides: [
130+
navRailIndexStateProvider.overrideWith((ref) => 4),
131+
],
132+
child: const Portal(
133+
child: MaterialApp(
134+
home: Dashboard(),
135+
),
136+
),
137+
),
138+
);
139+
140+
// Verify that the SettingsPage is displayed
141+
expect(find.byType(HomePage), findsNothing);
142+
expect(find.byType(EnvironmentPage), findsNothing);
143+
expect(find.byType(HistoryPage), findsNothing);
144+
expect(find.byType(TerminalPage), findsNothing);
118145
expect(find.byType(SettingsPage), findsOneWidget);
119146
});
120147

@@ -138,7 +165,7 @@ void main() {
138165
// Verify that the navRailIndexStateProvider is updated
139166
final dashboard = tester.element(find.byType(Dashboard));
140167
final container = ProviderScope.containerOf(dashboard);
141-
expect(container.read(navRailIndexStateProvider), 3);
168+
expect(container.read(navRailIndexStateProvider), 4);
142169
});
143170

144171
testWidgets(
@@ -155,7 +182,7 @@ void main() {
155182
),
156183
);
157184

158-
// Tap on the Settings icon to change the index to 3
185+
// Tap on the Settings icon to change the index to 4
159186
await tester.tap(find.byIcon(Icons.settings_outlined));
160187
await tester.pump();
161188

@@ -173,12 +200,13 @@ void main() {
173200
// Verify that the navRailIndexStateProvider still has the updated value
174201
final dashboard = tester.element(find.byType(Dashboard));
175202
final container = ProviderScope.containerOf(dashboard);
176-
expect(container.read(navRailIndexStateProvider), 3);
203+
expect(container.read(navRailIndexStateProvider), 4);
177204

178205
// Verify that the SettingsPage is still displayed after the rebuild
179206
expect(find.byType(SettingsPage), findsOneWidget);
180207
expect(find.byType(HomePage), findsNothing);
181208
expect(find.byType(EnvironmentPage), findsNothing);
209+
expect(find.byType(TerminalPage), findsNothing);
182210
});
183211

184212
testWidgets(
@@ -216,10 +244,19 @@ void main() {
216244
// Verify that the selected icon is the filled version (selectedIcon)
217245
expect(find.byIcon(Icons.history_rounded), findsOneWidget);
218246

219-
// Go to SettingsPage
247+
// Go to TerminalPage
220248
container.read(navRailIndexStateProvider.notifier).state = 3;
221249
await tester.pump();
222250

251+
// Verify that the TerminalPage is displayed
252+
expect(find.byType(TerminalPage), findsOneWidget);
253+
// Verify that the selected icon is the filled version (selectedIcon)
254+
expect(find.byIcon(Icons.terminal), findsOneWidget);
255+
256+
// Go to SettingsPage
257+
container.read(navRailIndexStateProvider.notifier).state = 4;
258+
await tester.pump();
259+
223260
// Verify that the SettingsPage is displayed
224261
expect(find.byType(SettingsPage), findsOneWidget);
225262
// Verify that the selected icon is the filled version (selectedIcon)

0 commit comments

Comments
 (0)