@@ -124,7 +124,7 @@ void main() {
124
124
125
125
// Tap on the Settings icon to change the index to 2
126
126
await tester.tap (find.byIcon (Icons .settings_outlined));
127
- await tester.pump (); // Wait for the animations to complete
127
+ await tester.pump ();
128
128
129
129
// Rebuild the widget tree with the same ProviderScope
130
130
await tester.pumpWidget (
@@ -145,5 +145,38 @@ void main() {
145
145
expect (find.byType (IntroPage ), findsNothing);
146
146
expect (find.byType (HomePage ), findsNothing);
147
147
});
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
+ });
148
181
});
149
182
}
0 commit comments