diff --git a/test/src/refresh_when_network_available_extension_test.dart b/test/src/refresh_when_network_available_extension_test.dart index fb671bd..31c5229 100644 --- a/test/src/refresh_when_network_available_extension_test.dart +++ b/test/src/refresh_when_network_available_extension_test.dart @@ -74,4 +74,50 @@ void main() { expect(numberOfFetchDataCalls, 2); }); }); + + group('ConnectivityStreamProvider tests', () { + test('provides connectivity stream with expected values', () async { + final mockConnectivity = MockConnectivity(); + + // Simulate the connectivity stream emitting the following values: + final connectivityStream = Stream>.fromIterable([ + [ConnectivityResult.none], + [ConnectivityResult.mobile], + [ConnectivityResult.wifi], + ]); + + when(() => mockConnectivity.onConnectivityChanged) + .thenAnswer((_) => connectivityStream); + + final container = ProviderContainer( + overrides: [ + connectivityStreamProvider.overrideWith( + (StreamProviderRef> ref) => + mockConnectivity.onConnectivityChanged.distinct(), + ), + ], + ); + + final emittedValues = >[]; + + // Listen to the connectivity stream provider + final listener = container.listen>>( + connectivityStreamProvider, (previous, next) { + if (next.hasValue) { + emittedValues.add(next.value!); + } + }); + + // Wait for the stream to emit all values + await Future.delayed(const Duration(milliseconds: 100)); + + listener.close(); + + expect(emittedValues, [ + [ConnectivityResult.none], + [ConnectivityResult.mobile], + [ConnectivityResult.wifi], + ]); + }); + }); }