Skip to content

Commit 405decb

Browse files
committed
Test that navRailIndexStateProvider is properly disposed
1 parent a882d51 commit 405decb

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

test/providers/ui_providers_test.dart

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void main() {
9191
});
9292

9393
testWidgets(
94-
'Navigation Rail index should update when icon button is pressed',
94+
'navRailIndexStateProvider should update when icon button is pressed',
9595
(tester) async {
9696
await tester.pumpWidget(
9797
const ProviderScope(
@@ -111,7 +111,8 @@ void main() {
111111
expect(container.read(navRailIndexStateProvider), 1);
112112
});
113113

114-
testWidgets('Navigation Rail index should persist across widget rebuilds',
114+
testWidgets(
115+
'navRailIndexStateProvider should persist across widget rebuilds',
115116
(tester) async {
116117
// Pump the initial widget tree
117118
await tester.pumpWidget(
@@ -146,7 +147,8 @@ void main() {
146147
expect(find.byType(HomePage), findsNothing);
147148
});
148149

149-
testWidgets('UI should update correctly when Navigation Rail index changes',
150+
testWidgets(
151+
'UI should update correctly when navRailIndexStateProvider changes',
150152
(tester) async {
151153
await tester.pumpWidget(
152154
const ProviderScope(
@@ -178,5 +180,38 @@ void main() {
178180
// Verify that the selected icon is the filled version (selectedIcon)
179181
expect(find.byIcon(Icons.settings), findsOneWidget);
180182
});
183+
184+
testWidgets(
185+
'navRailIndexStateProvider should be disposed when Dashboard is removed',
186+
(tester) async {
187+
await tester.pumpWidget(
188+
const ProviderScope(
189+
child: MaterialApp(
190+
home: Dashboard(),
191+
),
192+
),
193+
);
194+
195+
// Grab the Dashboard widget and its ProviderContainer
196+
final dashboard = tester.element(find.byType(Dashboard));
197+
final container = ProviderScope.containerOf(dashboard);
198+
199+
// Pumping a different widget to remove the Dashboard from the widget tree
200+
await tester.pumpWidget(
201+
const MaterialApp(
202+
home: Scaffold(body: Text('Different Widget')),
203+
),
204+
);
205+
206+
// Verify that the ProviderContainer has been disposed
207+
// by trying to read from disposed container
208+
bool isDisposed = false;
209+
try {
210+
container.read(navRailIndexStateProvider);
211+
} catch (e) {
212+
isDisposed = true;
213+
}
214+
expect(isDisposed, true);
215+
});
181216
});
182217
}

0 commit comments

Comments
 (0)