Skip to content

Commit ba4bd77

Browse files
committed
Test that nav rail index persist across widget rebuilds
1 parent b264a7e commit ba4bd77

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/providers/ui_providers_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,40 @@ void main() {
110110
final container = ProviderScope.containerOf(dashboard);
111111
expect(container.read(navRailIndexStateProvider), 1);
112112
});
113+
114+
testWidgets('Navigation Rail index should persist across widget rebuilds',
115+
(tester) async {
116+
// Pump the initial widget tree
117+
await tester.pumpWidget(
118+
const ProviderScope(
119+
child: MaterialApp(
120+
home: Dashboard(),
121+
),
122+
),
123+
);
124+
125+
// Tap on the Settings icon to change the index to 2
126+
await tester.tap(find.byIcon(Icons.settings_outlined));
127+
await tester.pump(); // Wait for the animations to complete
128+
129+
// Rebuild the widget tree with the same ProviderScope
130+
await tester.pumpWidget(
131+
const ProviderScope(
132+
child: MaterialApp(
133+
home: Dashboard(),
134+
),
135+
),
136+
);
137+
138+
// Verify that the navRailIndexStateProvider still has the updated value
139+
final dashboard = tester.element(find.byType(Dashboard));
140+
final container = ProviderScope.containerOf(dashboard);
141+
expect(container.read(navRailIndexStateProvider), 2);
142+
143+
// Verify that the SettingsPage is still displayed after the rebuild
144+
expect(find.byType(SettingsPage), findsOneWidget);
145+
expect(find.byType(IntroPage), findsNothing);
146+
expect(find.byType(HomePage), findsNothing);
147+
});
113148
});
114149
}

0 commit comments

Comments
 (0)