From d923410ad961feb2b854d65587a64dc229704425 Mon Sep 17 00:00:00 2001 From: Krzysztof Mamak Date: Tue, 12 Mar 2024 20:23:05 +0100 Subject: [PATCH 1/4] Make stream controller a broadcast one in whenListenPresentation, update CHANGELOG --- packages/bloc_presentation_test/CHANGELOG.md | 4 ++++ .../lib/src/when_listen_presentation.dart | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/bloc_presentation_test/CHANGELOG.md b/packages/bloc_presentation_test/CHANGELOG.md index 8f4e849..8f2d445 100644 --- a/packages/bloc_presentation_test/CHANGELOG.md +++ b/packages/bloc_presentation_test/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.0.2 + +- Make `StreamController` a broadcast one in `whenListenPresentation` + # 1.0.1 - Make `MockPresentationCubit` and `MockPresentationBloc` presentation streams broadcast ones. diff --git a/packages/bloc_presentation_test/lib/src/when_listen_presentation.dart b/packages/bloc_presentation_test/lib/src/when_listen_presentation.dart index c9faa4e..66a85e2 100644 --- a/packages/bloc_presentation_test/lib/src/when_listen_presentation.dart +++ b/packages/bloc_presentation_test/lib/src/when_listen_presentation.dart @@ -13,7 +13,7 @@ StreamController whenListenPresentation( BlocPresentationMixin bloc, { List? initialEvents, }) { - final presentationController = StreamController(); + final presentationController = StreamController.broadcast(); initialEvents?.forEach(presentationController.add); From 0d522e665a33f11fa0aa7075fe5db9fd74f2b9d8 Mon Sep 17 00:00:00 2001 From: Krzysztof Mamak Date: Wed, 13 Mar 2024 09:54:29 +0100 Subject: [PATCH 2/4] Bump bloc_presentation_test version to 1.0.2 in pubspec --- packages/bloc_presentation_test/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bloc_presentation_test/pubspec.yaml b/packages/bloc_presentation_test/pubspec.yaml index 6c8689a..2f7c26c 100644 --- a/packages/bloc_presentation_test/pubspec.yaml +++ b/packages/bloc_presentation_test/pubspec.yaml @@ -1,6 +1,6 @@ name: bloc_presentation_test description: A testing library for Blocs/Cubits which mixin BlocPresentationMixin. To be used with bloc_presentation package. -version: 1.0.1 +version: 1.0.2 homepage: https://github.com/leancodepl/bloc_presentation/tree/master/packages/bloc_presentation_test environment: From 2a78f94123b34acc241f3c915c84f47d2f2c4b76 Mon Sep 17 00:00:00 2001 From: Krzysztof Mamak Date: Wed, 13 Mar 2024 09:56:05 +0100 Subject: [PATCH 3/4] Add missing dot to bloc_presentation_test CHANGELOG entry --- packages/bloc_presentation_test/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bloc_presentation_test/CHANGELOG.md b/packages/bloc_presentation_test/CHANGELOG.md index 8f2d445..bbf5e52 100644 --- a/packages/bloc_presentation_test/CHANGELOG.md +++ b/packages/bloc_presentation_test/CHANGELOG.md @@ -1,6 +1,6 @@ # 1.0.2 -- Make `StreamController` a broadcast one in `whenListenPresentation` +- Make `StreamController` a broadcast one in `whenListenPresentation`. # 1.0.1 From 3f7de2438f26ea41c6bc5a85eedec37bf7684b20 Mon Sep 17 00:00:00 2001 From: Krzysztof Mamak Date: Wed, 13 Mar 2024 19:37:08 +0100 Subject: [PATCH 4/4] Add tests for whenListenPresentation --- .../test/when_listen_presentation_test.dart | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 packages/bloc_presentation_test/test/when_listen_presentation_test.dart diff --git a/packages/bloc_presentation_test/test/when_listen_presentation_test.dart b/packages/bloc_presentation_test/test/when_listen_presentation_test.dart new file mode 100644 index 0000000..345b0d2 --- /dev/null +++ b/packages/bloc_presentation_test/test/when_listen_presentation_test.dart @@ -0,0 +1,57 @@ +import 'dart:async'; + +import 'package:bloc_presentation_test/bloc_presentation_test.dart'; +import 'package:mocktail/mocktail.dart'; +import 'package:test/expect.dart'; +import 'package:test/scaffolding.dart'; + +import 'cubits/counter_cubit.dart'; + +class _MockCounterCubit extends Mock implements CounterCubit {} + +void main() { + late _MockCounterCubit cubit; + late List> subscriptions; + + setUp(() { + cubit = _MockCounterCubit(); + + subscriptions = []; + }); + + tearDown(() async { + await cubit.close(); + await subscriptions.map((sub) => sub.cancel()).wait; + }); + + group('whenListenPresentation', () { + test( + 'returns controller whose stream can be listened to more than once', + () { + final controller = whenListenPresentation(cubit); + + subscriptions.add(controller.stream.listen((_) {})); + + expect( + () => subscriptions.add(controller.stream.listen((_) {})), + returnsNormally, + ); + }, + ); + + test( + 'stubs cubit presentation with a stream that can be listened to more ' + 'than once', + () { + whenListenPresentation(cubit); + + subscriptions.add(cubit.presentation.listen((_) {})); + + expect( + () => subscriptions.add(cubit.presentation.listen((_) {})), + returnsNormally, + ); + }, + ); + }); +}