From 8ce3c9e9385ed663e6b241fc88cba5d8eee35efd Mon Sep 17 00:00:00 2001 From: Vadim Date: Fri, 9 Jun 2023 14:11:55 +0200 Subject: [PATCH] refined `IsoChangedEvent` tests --- test/screens/metering/bloc_metering_test.dart | 98 ++++++++++++++++++- 1 file changed, 95 insertions(+), 3 deletions(-) diff --git a/test/screens/metering/bloc_metering_test.dart b/test/screens/metering/bloc_metering_test.dart index a376f34..0869066 100644 --- a/test/screens/metering/bloc_metering_test.dart +++ b/test/screens/metering/bloc_metering_test.dart @@ -147,7 +147,7 @@ void main() { '`IsoChangedEvent` tests', () { blocTest( - '`IsoChangedEvent` -> success', + 'Pick different ISO (ev100 != null)', build: () => bloc, seed: () => MeteringDataState( ev100: 1.0, @@ -167,13 +167,43 @@ void main() { isA() .having((state) => state.ev100, 'ev100', 1.0) .having((state) => state.ev, 'ev', 2.0) + .having((state) => state.film, 'film', Film.values.first) .having((state) => state.iso, 'iso', const IsoValue(200, StopType.full)) + .having((state) => state.nd, 'nd', NdValue.values.first) .having((state) => state.isMetering, 'isMetering', false), ], ); blocTest( - '`IsoChangedEvent` -> same ISO picked', + 'Pick different ISO (ev100 = null)', + build: () => bloc, + seed: () => MeteringDataState( + ev100: null, + film: Film.values[1], + iso: const IsoValue(100, StopType.full), + nd: NdValue.values.first, + isMetering: false, + ), + act: (bloc) async { + bloc.add(const IsoChangedEvent(IsoValue(200, StopType.full))); + }, + verify: (_) { + verify(() => meteringInteractor.film = Film.values.first).called(1); + verify(() => meteringInteractor.iso = const IsoValue(200, StopType.full)).called(1); + }, + expect: () => [ + isA() + .having((state) => state.ev100, 'ev100', null) + .having((state) => state.ev, 'ev', null) + .having((state) => state.film, 'film', Film.values.first) + .having((state) => state.iso, 'iso', const IsoValue(200, StopType.full)) + .having((state) => state.nd, 'nd', NdValue.values.first) + .having((state) => state.isMetering, 'isMetering', false), + ], + ); + + blocTest( + 'Pick same ISO', build: () => bloc, seed: () => MeteringDataState( ev100: 1.0, @@ -191,13 +221,75 @@ void main() { }, expect: () => [], ); + + blocTest( + 'Pick different ISO & measure', + build: () => bloc, + seed: () => MeteringDataState( + ev100: 1.0, + film: Film.values[1], + iso: const IsoValue(100, StopType.full), + nd: NdValue.values.first, + isMetering: false, + ), + act: (bloc) async { + bloc.add(const IsoChangedEvent(IsoValue(200, StopType.full))); + bloc.add(const MeasureEvent()); + bloc.onCommunicationState(const communication_states.MeteringEndedState(2)); + }, + verify: (_) { + verify(() => meteringInteractor.film = Film.values.first).called(1); + verify(() => meteringInteractor.iso = const IsoValue(200, StopType.full)).called(1); + }, + expect: () => [ + isA() + .having((state) => state.ev100, 'ev100', 1.0) + .having((state) => state.ev, 'ev', 2.0) + .having((state) => state.film, 'film', Film.values.first) + .having((state) => state.iso, 'iso', const IsoValue(200, StopType.full)) + .having((state) => state.nd, 'nd', NdValue.values.first) + .having((state) => state.isMetering, 'isMetering', false), + isA(), + isA() + .having((state) => state.ev100, 'ev100', 2.0) + .having((state) => state.ev, 'ev', 3.0) + .having((state) => state.film, 'film', Film.values.first) + .having((state) => state.iso, 'iso', const IsoValue(200, StopType.full)) + .having((state) => state.nd, 'nd', NdValue.values.first) + .having((state) => state.isMetering, 'isMetering', false), + ], + ); }, ); group( '`NdChangedEvent` tests', () { - // + blocTest( + '`NdChangedEvent` -> success', + build: () => bloc, + seed: () => MeteringDataState( + ev100: 1.0, + film: Film.values[1], + iso: const IsoValue(100, StopType.full), + nd: NdValue.values.first, + isMetering: false, + ), + act: (bloc) async { + bloc.add(const NdChangedEvent(NdValue(2))); + }, + verify: (_) { + verify(() => meteringInteractor.film = Film.values.first).called(1); + verify(() => meteringInteractor.ndFilter = const NdValue(2)).called(1); + }, + expect: () => [ + isA() + .having((state) => state.ev100, 'ev100', 1.0) + .having((state) => state.ev, 'ev', 2.0) + .having((state) => state.iso, 'iso', const IsoValue(200, StopType.full)) + .having((state) => state.isMetering, 'isMetering', false), + ], + ); }, );