Skip to content

Commit

Permalink
Make stream controller a broadcast one in whenListenPresentation
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofMamak authored Mar 14, 2024
2 parents ac557f4 + 3f7de24 commit 4bd3450
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/bloc_presentation_test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ StreamController<T> whenListenPresentation<T>(
BlocPresentationMixin<dynamic, T> bloc, {
List<T>? initialEvents,
}) {
final presentationController = StreamController<T>();
final presentationController = StreamController<T>.broadcast();

initialEvents?.forEach(presentationController.add);

Expand Down
2 changes: 1 addition & 1 deletion packages/bloc_presentation_test/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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<StreamSubscription<dynamic>> 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,
);
},
);
});
}

0 comments on commit 4bd3450

Please sign in to comment.