From fb44e693309bdbdde6d408475ffa4a12014aab8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20K=C4=85dzio=C5=82ka?= Date: Thu, 23 Jan 2025 10:42:32 +0100 Subject: [PATCH 1/2] test: new isClosed logic --- lib/src/mixins/bloc_action_mixin.dart | 3 +++ test/mixins/bloc_action_mixin_test.dart | 27 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/src/mixins/bloc_action_mixin.dart b/lib/src/mixins/bloc_action_mixin.dart index 1c56c37..e1ab599 100644 --- a/lib/src/mixins/bloc_action_mixin.dart +++ b/lib/src/mixins/bloc_action_mixin.dart @@ -61,6 +61,9 @@ mixin BlocActionMixin on BlocBase { previousAction = action; } + @override + bool get isClosed => super.isClosed || _streamController.isClosed; + @override Future close() async { previousAction = null; diff --git a/test/mixins/bloc_action_mixin_test.dart b/test/mixins/bloc_action_mixin_test.dart index 71f5d58..e04c045 100644 --- a/test/mixins/bloc_action_mixin_test.dart +++ b/test/mixins/bloc_action_mixin_test.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:flutter/widgets.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; @@ -75,4 +77,29 @@ void main() { expect(true, cubit.actionStreamController.isClosed); expect(true, cubit.isClosed); }); + + testWidgets('should be closed when either state or action stream is closed', + (tester) async { + final cubit = TestCubitWithMixin(); + when(() => injector.get()).thenReturn(cubit); + + Future build() async { + await tester.pumpWidget( + HookedBlocConfigProvider( + injector: () => injector.get, + child: HookBuilder( + builder: (context) { + useBloc(); + + return const SizedBox(); + }, + ), + ), + ); + } + + await build(); + await cubit.actionStreamController.close(); + expect(true, cubit.isClosed); + }); } From c4676da135cb2b774fe0568cb327d26ba31098be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20K=C4=85dzio=C5=82ka?= Date: Thu, 23 Jan 2025 10:48:28 +0100 Subject: [PATCH 2/2] fix: async import --- test/mixins/bloc_action_mixin_test.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/mixins/bloc_action_mixin_test.dart b/test/mixins/bloc_action_mixin_test.dart index e04c045..deb94ae 100644 --- a/test/mixins/bloc_action_mixin_test.dart +++ b/test/mixins/bloc_action_mixin_test.dart @@ -1,5 +1,3 @@ -import 'dart:async'; - import 'package:flutter/widgets.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_hooks/flutter_hooks.dart';