Skip to content

Commit a882d51

Browse files
committed
Test that UI updates correctly when nav rail index changes
1 parent ba4bd77 commit a882d51

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

test/providers/ui_providers_test.dart

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void main() {
124124

125125
// Tap on the Settings icon to change the index to 2
126126
await tester.tap(find.byIcon(Icons.settings_outlined));
127-
await tester.pump(); // Wait for the animations to complete
127+
await tester.pump();
128128

129129
// Rebuild the widget tree with the same ProviderScope
130130
await tester.pumpWidget(
@@ -145,5 +145,38 @@ void main() {
145145
expect(find.byType(IntroPage), findsNothing);
146146
expect(find.byType(HomePage), findsNothing);
147147
});
148+
149+
testWidgets('UI should update correctly when Navigation Rail index changes',
150+
(tester) async {
151+
await tester.pumpWidget(
152+
const ProviderScope(
153+
child: MaterialApp(
154+
home: Dashboard(),
155+
),
156+
),
157+
);
158+
159+
// Grab the Dashboard widget and its ProviderContainer
160+
final dashboard = tester.element(find.byType(Dashboard));
161+
final container = ProviderScope.containerOf(dashboard);
162+
163+
// Go to IntroPage
164+
container.read(navRailIndexStateProvider.notifier).state = 1;
165+
await tester.pump();
166+
167+
// Verify that the IntroPage is displayed
168+
expect(find.byType(IntroPage), findsOneWidget);
169+
// Verify that the selected icon is the filled version (selectedIcon)
170+
expect(find.byIcon(Icons.help), findsOneWidget);
171+
172+
// Go to SettingsPage
173+
container.read(navRailIndexStateProvider.notifier).state = 2;
174+
await tester.pump();
175+
176+
// Verify that the SettingsPage is displayed
177+
expect(find.byType(SettingsPage), findsOneWidget);
178+
// Verify that the selected icon is the filled version (selectedIcon)
179+
expect(find.byIcon(Icons.settings), findsOneWidget);
180+
});
148181
});
149182
}

0 commit comments

Comments
 (0)