From df25a1b1b366293ff67d52c91dfd9888ff85ef54 Mon Sep 17 00:00:00 2001 From: Sixtus Agbo Date: Sun, 17 Mar 2024 06:04:49 +0100 Subject: [PATCH] Add test case to verify proper disposal of selectedIdEditStateProvider --- test/providers/ui_providers_test.dart | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/providers/ui_providers_test.dart b/test/providers/ui_providers_test.dart index fb9056e1..dde4983f 100644 --- a/test/providers/ui_providers_test.dart +++ b/test/providers/ui_providers_test.dart @@ -299,5 +299,35 @@ void main() { // Verify that the selectedIdEditStateProvider is null expect(container.read(selectedIdEditStateProvider), null); }); + testWidgets("It should be properly disposed", (tester) async { + await tester.pumpWidget( + const ProviderScope( + child: MaterialApp( + home: CollectionPane(), + ), + ), + ); + + // Grab the Dashboard widget and its ProviderContainer + final collectionPane = tester.element(find.byType(CollectionPane)); + final container = ProviderScope.containerOf(collectionPane); + + // Pumping a different widget to remove the CollectionPane from the widget tree + await tester.pumpWidget( + const MaterialApp( + home: Scaffold(body: Text('Foo')), + ), + ); + + // Verify that the ProviderContainer has been disposed + // by trying to read from disposed container + bool isDisposed = false; + try { + container.read(selectedIdEditStateProvider); + } catch (e) { + isDisposed = true; + } + expect(isDisposed, true); + }); }); }