From c92ab5209b329b75ae0357384fd4b60473204729 Mon Sep 17 00:00:00 2001 From: Vadim Date: Fri, 9 Jun 2023 14:51:15 +0200 Subject: [PATCH] `MeteringCommunicationBloc` tests --- .../bloc_communication_metering_test.dart | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 test/screens/metering/communication/bloc_communication_metering_test.dart diff --git a/test/screens/metering/communication/bloc_communication_metering_test.dart b/test/screens/metering/communication/bloc_communication_metering_test.dart new file mode 100644 index 0000000..1313c6b --- /dev/null +++ b/test/screens/metering/communication/bloc_communication_metering_test.dart @@ -0,0 +1,100 @@ +import 'package:bloc_test/bloc_test.dart'; +import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart'; +import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart'; +import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart'; +import 'package:test/test.dart'; + +void main() { + late MeteringCommunicationBloc bloc; + + setUp(() { + bloc = MeteringCommunicationBloc(); + }); + + tearDown(() { + bloc.close(); + }); + + group( + '`MeasureEvent` tests', + () { + blocTest( + 'Multiple consequtive measure events', + build: () => bloc, + act: (bloc) async { + bloc.add(const MeasureEvent()); + bloc.add(const MeasureEvent()); + bloc.add(const MeasureEvent()); + bloc.add(const MeasureEvent()); + }, + expect: () => [ + isA(), + isA(), + isA(), + isA(), + ], + ); + + blocTest( + 'Continuous metering simulation', + build: () => bloc, + act: (bloc) async { + bloc.add(const MeasureEvent()); + bloc.add(const MeteringInProgressEvent(1)); + bloc.add(const MeteringInProgressEvent(null)); + bloc.add(const MeteringInProgressEvent(null)); + bloc.add(const MeteringInProgressEvent(2)); + bloc.add(const MeasureEvent()); + bloc.add(const MeteringEndedEvent(2)); + }, + expect: () => [ + isA(), + isA().having((state) => state.ev100, 'ev100', 1), + isA().having((state) => state.ev100, 'ev100', null), + isA().having((state) => state.ev100, 'ev100', null), + isA().having((state) => state.ev100, 'ev100', 2), + isA(), + isA().having((state) => state.ev100, 'ev100', 2), + ], + ); + }, + ); + + group( + '`MeteringInProgressEvent` tests', + () { + blocTest( + 'Multiple consequtive in progress events', + build: () => bloc, + act: (bloc) async { + bloc.add(const MeteringInProgressEvent(1)); + bloc.add(const MeteringInProgressEvent(null)); + bloc.add(const MeteringInProgressEvent(null)); + bloc.add(const MeteringInProgressEvent(2)); + }, + expect: () => [ + isA().having((state) => state.ev100, 'ev100', 1), + isA().having((state) => state.ev100, 'ev100', null), + isA().having((state) => state.ev100, 'ev100', null), + isA().having((state) => state.ev100, 'ev100', 2), + ], + ); + }, + ); + + group( + '`MeteringEndedEvent` tests', + () { + blocTest( + 'Multiple consequtive ended events', + build: () => bloc, + act: (bloc) async { + bloc.add(const MeteringEndedEvent(1)); + }, + expect: () => [ + isA().having((state) => state.ev100, 'ev100', 1), + ], + ); + }, + ); +}