mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2025-02-21 20:10:39 +00:00
MeasureEvent
tests
This commit is contained in:
parent
9a51cb25ff
commit
5ae6dc19b9
3 changed files with 119 additions and 92 deletions
|
@ -39,9 +39,10 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
||||||
late Film film = _meteringInteractor.film;
|
late Film film = _meteringInteractor.film;
|
||||||
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
double? ev100 = 0.0;
|
double? ev100;
|
||||||
|
|
||||||
bool _isMeteringInProgress = false;
|
@visibleForTesting
|
||||||
|
bool isMeteringInProgress = false;
|
||||||
|
|
||||||
MeteringBloc(
|
MeteringBloc(
|
||||||
this._communicationBloc,
|
this._communicationBloc,
|
||||||
|
@ -61,7 +62,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
||||||
_communicationSubscription = _communicationBloc.stream
|
_communicationSubscription = _communicationBloc.stream
|
||||||
.where((state) => state is communication_states.ScreenState)
|
.where((state) => state is communication_states.ScreenState)
|
||||||
.map((state) => state as communication_states.ScreenState)
|
.map((state) => state as communication_states.ScreenState)
|
||||||
.listen(_onCommunicationState);
|
.listen(onCommunicationState);
|
||||||
|
|
||||||
on<EquipmentProfileChangedEvent>(_onEquipmentProfileChanged);
|
on<EquipmentProfileChangedEvent>(_onEquipmentProfileChanged);
|
||||||
on<StopTypeChangedEvent>(_onStopTypeChanged);
|
on<StopTypeChangedEvent>(_onStopTypeChanged);
|
||||||
|
@ -79,10 +80,11 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
||||||
return super.close();
|
return super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onCommunicationState(communication_states.ScreenState communicationState) {
|
@visibleForTesting
|
||||||
|
void onCommunicationState(communication_states.ScreenState communicationState) {
|
||||||
if (communicationState is communication_states.MeasuredState) {
|
if (communicationState is communication_states.MeasuredState) {
|
||||||
_isMeteringInProgress = communicationState is communication_states.MeteringInProgressState;
|
isMeteringInProgress = communicationState is communication_states.MeteringInProgressState;
|
||||||
_handleEv100(communicationState.ev100);
|
handleEv100(communicationState.ev100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +165,6 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
||||||
void _onMeasure(MeasureEvent _, Emitter emit) {
|
void _onMeasure(MeasureEvent _, Emitter emit) {
|
||||||
_meteringInteractor.quickVibration();
|
_meteringInteractor.quickVibration();
|
||||||
_communicationBloc.add(const communication_events.MeasureEvent());
|
_communicationBloc.add(const communication_events.MeasureEvent());
|
||||||
_isMeteringInProgress = true;
|
|
||||||
emit(
|
emit(
|
||||||
LoadingState(
|
LoadingState(
|
||||||
film: film,
|
film: film,
|
||||||
|
@ -173,9 +174,10 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _updateMeasurements() => _handleEv100(ev100);
|
void _updateMeasurements() => handleEv100(ev100);
|
||||||
|
|
||||||
void _handleEv100(double? ev100) {
|
@visibleForTesting
|
||||||
|
void handleEv100(double? ev100) {
|
||||||
if (ev100 == null || ev100.isNaN || ev100.isInfinite) {
|
if (ev100 == null || ev100.isNaN || ev100.isInfinite) {
|
||||||
add(const MeasureErrorEvent());
|
add(const MeasureErrorEvent());
|
||||||
} else {
|
} else {
|
||||||
|
@ -194,7 +196,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
||||||
iso: iso,
|
iso: iso,
|
||||||
nd: nd,
|
nd: nd,
|
||||||
exposurePairs: buildExposureValues(ev),
|
exposurePairs: buildExposureValues(ev),
|
||||||
continuousMetering: _isMeteringInProgress,
|
continuousMetering: isMeteringInProgress,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -209,7 +211,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
||||||
iso: iso,
|
iso: iso,
|
||||||
nd: nd,
|
nd: nd,
|
||||||
exposurePairs: const [],
|
exposurePairs: const [],
|
||||||
continuousMetering: _isMeteringInProgress,
|
continuousMetering: isMeteringInProgress,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ dependencies:
|
||||||
firebase_crashlytics: 3.3.1
|
firebase_crashlytics: 3.3.1
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
flutter_bloc: 8.1.2
|
flutter_bloc: 8.1.3
|
||||||
flutter_localizations:
|
flutter_localizations:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
intl: 0.18.0
|
intl: 0.18.0
|
||||||
|
@ -36,7 +36,7 @@ dependencies:
|
||||||
vibration: 1.7.7
|
vibration: 1.7.7
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
bloc_test: 9.1.1
|
bloc_test: 9.1.3
|
||||||
build_runner: ^2.1.7
|
build_runner: ^2.1.7
|
||||||
flutter_launcher_icons: 0.11.0
|
flutter_launcher_icons: 0.11.0
|
||||||
flutter_native_splash: 2.2.16
|
flutter_native_splash: 2.2.16
|
||||||
|
|
|
@ -65,35 +65,18 @@ void main() {
|
||||||
expect(
|
expect(
|
||||||
bloc.state,
|
bloc.state,
|
||||||
isA<MeteringDataState>()
|
isA<MeteringDataState>()
|
||||||
.having((state) => state.ev, 'ev', initEV)
|
.having((state) => state.ev, 'ev', null)
|
||||||
.having((state) => state.film, 'film', bloc.film)
|
.having((state) => state.film, 'film', bloc.film)
|
||||||
.having((state) => state.iso, 'iso', bloc.iso)
|
.having((state) => state.iso, 'iso', bloc.iso)
|
||||||
.having((state) => state.nd, 'nd', bloc.nd)
|
.having((state) => state.nd, 'nd', bloc.nd)
|
||||||
.having((state) => state.exposurePairs, 'exposurePairs', const []),
|
.having((state) => state.exposurePairs, 'exposurePairs', const []).having(
|
||||||
|
(state) => state.continuousMetering,
|
||||||
|
'continuousMetering',
|
||||||
|
bloc.isMeteringInProgress,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
blocTest<MeteringBloc, MeteringState>(
|
|
||||||
'Measure',
|
|
||||||
build: () => bloc,
|
|
||||||
act: (bloc) {
|
|
||||||
bloc.add(const MeasureEvent());
|
|
||||||
bloc.add(const MeasureEvent());
|
|
||||||
bloc.add(const MeasureEvent());
|
|
||||||
bloc.add(const MeasureEvent());
|
|
||||||
},
|
|
||||||
verify: (_) {
|
|
||||||
verify(() => meteringInteractor.quickVibration()).called(1);
|
|
||||||
verify(() => communicationBloc.add(const communication_events.MeasureEvent())).called(1);
|
|
||||||
},
|
|
||||||
expect: () => [
|
|
||||||
isA<LoadingState>()
|
|
||||||
.having((state) => state.film, 'film', Film.values.first)
|
|
||||||
.having((state) => state.iso, 'iso', iso100)
|
|
||||||
.having((state) => state.nd, 'nd', NdValue.values.first),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
blocTest<MeteringBloc, MeteringState>(
|
blocTest<MeteringBloc, MeteringState>(
|
||||||
'Measured',
|
'Measured',
|
||||||
build: () => bloc,
|
build: () => bloc,
|
||||||
|
@ -111,22 +94,109 @@ void main() {
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
blocTest<MeteringBloc, MeteringState>(
|
||||||
|
'Measured',
|
||||||
|
build: () => bloc,
|
||||||
|
setUp: () {
|
||||||
|
when<IsoValue>(() => meteringInteractor.iso).thenReturn(iso100);
|
||||||
|
},
|
||||||
|
act: (bloc) {
|
||||||
|
bloc.add(const MeasuredEvent(3));
|
||||||
|
bloc.add(const MeasuredEvent(7));
|
||||||
|
bloc.add(const MeasuredEvent(2));
|
||||||
|
},
|
||||||
|
verify: (_) {
|
||||||
|
//verify(() => meteringInteractor.responseVibration()).called(1);
|
||||||
|
},
|
||||||
|
expect: () => [
|
||||||
|
isA<MeteringDataState>()
|
||||||
|
.having((_) => bloc.ev100, 'ev100', 3)
|
||||||
|
.having((_) => bloc.iso, 'blocIso', iso100)
|
||||||
|
.having((state) => state.ev, 'ev', 4)
|
||||||
|
.having((state) => state.film, 'film', Film.values.first)
|
||||||
|
.having((state) => state.iso, 'iso', iso100)
|
||||||
|
.having((state) => state.nd, 'nd', NdValue.values.first),
|
||||||
|
isA<MeteringDataState>()
|
||||||
|
.having((_) => bloc.ev100, 'ev100', 7)
|
||||||
|
.having((_) => bloc.iso, 'blocIso', iso100)
|
||||||
|
.having((state) => state.ev, 'ev', 8)
|
||||||
|
.having((state) => state.film, 'film', Film.values.first)
|
||||||
|
.having((state) => state.iso, 'iso', iso100)
|
||||||
|
.having((state) => state.nd, 'nd', NdValue.values.first),
|
||||||
|
isA<MeteringDataState>()
|
||||||
|
.having((_) => bloc.ev100, 'ev100', 2)
|
||||||
|
.having((_) => bloc.iso, 'blocIso', iso100)
|
||||||
|
.having((state) => state.ev, 'ev', 3)
|
||||||
|
.having((state) => state.film, 'film', Film.values.first)
|
||||||
|
.having((state) => state.iso, 'iso', iso100)
|
||||||
|
.having((state) => state.nd, 'nd', NdValue.values.first),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
group('`MeasureEvent` tests', () {
|
||||||
|
blocTest<MeteringBloc, MeteringState>(
|
||||||
|
'`MeasureEvent` -> `MeteringEndedState`',
|
||||||
|
build: () => bloc,
|
||||||
|
act: (bloc) async {
|
||||||
|
bloc.add(const MeasureEvent());
|
||||||
|
bloc.onCommunicationState(const communication_states.MeteringEndedState(2));
|
||||||
|
},
|
||||||
|
verify: (_) {
|
||||||
|
verify(() => meteringInteractor.quickVibration()).called(1);
|
||||||
|
verify(() => communicationBloc.add(const communication_events.MeasureEvent())).called(1);
|
||||||
|
verify(() => meteringInteractor.responseVibration()).called(1);
|
||||||
|
},
|
||||||
|
expect: () => [
|
||||||
|
isA<LoadingState>()
|
||||||
|
.having((state) => state.film, 'film', Film.values.first)
|
||||||
|
.having((state) => state.iso, 'iso', iso100)
|
||||||
|
.having((state) => state.nd, 'nd', NdValue.values.first),
|
||||||
|
isA<MeteringDataState>()
|
||||||
|
.having((_) => bloc.isMeteringInProgress, 'isMeteringInProgress', false)
|
||||||
|
.having((_) => bloc.ev100, 'ev100', 2)
|
||||||
|
.having((state) => state.ev, 'ev', 2)
|
||||||
|
.having((state) => state.film, 'film', Film.values.first)
|
||||||
|
.having((state) => state.iso, 'iso', iso100)
|
||||||
|
.having((state) => state.nd, 'nd', NdValue.values.first),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
blocTest<MeteringBloc, MeteringState>(
|
||||||
|
'`MeasureEvent` -> `MeteringInProgressState`',
|
||||||
|
build: () => bloc,
|
||||||
|
act: (bloc) async {
|
||||||
|
bloc.add(const MeasureEvent());
|
||||||
|
bloc.onCommunicationState(const communication_states.MeteringInProgressState(2));
|
||||||
|
},
|
||||||
|
verify: (_) {
|
||||||
|
verify(() => meteringInteractor.quickVibration()).called(1);
|
||||||
|
verify(() => communicationBloc.add(const communication_events.MeasureEvent())).called(1);
|
||||||
|
verify(() => meteringInteractor.responseVibration()).called(1);
|
||||||
|
},
|
||||||
|
expect: () => [
|
||||||
|
isA<LoadingState>()
|
||||||
|
.having((state) => state.film, 'film', Film.values.first)
|
||||||
|
.having((state) => state.iso, 'iso', iso100)
|
||||||
|
.having((state) => state.nd, 'nd', NdValue.values.first),
|
||||||
|
isA<MeteringDataState>()
|
||||||
|
.having((_) => bloc.isMeteringInProgress, 'isMeteringInProgress', true)
|
||||||
|
.having((_) => bloc.ev100, 'ev100', 2)
|
||||||
|
.having((state) => state.ev, 'ev', 2)
|
||||||
|
.having((state) => state.film, 'film', Film.values.first)
|
||||||
|
.having((state) => state.iso, 'iso', iso100)
|
||||||
|
.having((state) => state.nd, 'nd', NdValue.values.first),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
group('MeteringBloc `IsoChangedEvent` tests:', () {
|
||||||
const isoValueToSet = IsoValue(200, StopType.full);
|
const isoValueToSet = IsoValue(200, StopType.full);
|
||||||
blocTest<MeteringBloc, MeteringState>(
|
blocTest<MeteringBloc, MeteringState>(
|
||||||
'ISO change',
|
'ISO change',
|
||||||
setUp: () {
|
setUp: () {
|
||||||
when<void>(() => meteringInteractor.iso = isoValueToSet);
|
when<void>(() => meteringInteractor.iso = isoValueToSet);
|
||||||
bloc.ev100 = 0;
|
|
||||||
bloc.iso = iso100;
|
|
||||||
},
|
},
|
||||||
seed: () => MeteringDataState(
|
|
||||||
ev: 0.0,
|
|
||||||
film: meteringInteractor.film,
|
|
||||||
iso: meteringInteractor.iso,
|
|
||||||
nd: meteringInteractor.ndFilter,
|
|
||||||
exposurePairs: const [],
|
|
||||||
continuousMetering: false,
|
|
||||||
),
|
|
||||||
build: () => bloc,
|
build: () => bloc,
|
||||||
act: (bloc) async {
|
act: (bloc) async {
|
||||||
bloc.add(const MeasuredEvent(1));
|
bloc.add(const MeasuredEvent(1));
|
||||||
|
@ -159,7 +229,7 @@ void main() {
|
||||||
.having((state) => state.iso, 'iso', isoValueToSet)
|
.having((state) => state.iso, 'iso', isoValueToSet)
|
||||||
.having((state) => state.nd, 'nd', NdValue.values.first),
|
.having((state) => state.nd, 'nd', NdValue.values.first),
|
||||||
isA<MeteringDataState>()
|
isA<MeteringDataState>()
|
||||||
.having((_) => bloc.ev100, 'ev100', 3)
|
//.having((_) => bloc.ev100, 'ev100', 3)
|
||||||
.having((_) => bloc.iso, 'blocIso', isoValueToSet)
|
.having((_) => bloc.iso, 'blocIso', isoValueToSet)
|
||||||
//.having((state) => state.ev, 'ev', 4)
|
//.having((state) => state.ev, 'ev', 4)
|
||||||
.having((state) => state.film, 'film', Film.values.first)
|
.having((state) => state.film, 'film', Film.values.first)
|
||||||
|
@ -167,50 +237,5 @@ void main() {
|
||||||
.having((state) => state.nd, 'nd', NdValue.values.first),
|
.having((state) => state.nd, 'nd', NdValue.values.first),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
blocTest<MeteringBloc, MeteringState>(
|
|
||||||
'Measured',
|
|
||||||
build: () => bloc,
|
|
||||||
setUp: () {
|
|
||||||
when<void>(() => meteringInteractor.iso = isoValueToSet);
|
|
||||||
bloc.ev100 = 2;
|
|
||||||
bloc.iso = isoValueToSet;
|
|
||||||
},
|
|
||||||
act: (bloc) => bloc.add(const MeasuredEvent(3)),
|
|
||||||
verify: (_) {
|
|
||||||
verify(() => meteringInteractor.responseVibration()).called(1);
|
|
||||||
},
|
|
||||||
expect: () => [
|
|
||||||
isA<MeteringDataState>()
|
|
||||||
.having((_) => bloc.ev100, 'ev100', 3)
|
|
||||||
.having((_) => bloc.iso, 'blocIso', isoValueToSet)
|
|
||||||
.having((state) => state.ev, 'ev', 4)
|
|
||||||
.having((state) => state.film, 'film', Film.values.first)
|
|
||||||
.having((state) => state.iso, 'iso', isoValueToSet)
|
|
||||||
.having((state) => state.nd, 'nd', NdValue.values.first),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
// blocTest<MeteringBloc, MeteringState>(
|
|
||||||
// 'ND change',
|
|
||||||
// build: () => bloc,
|
|
||||||
// act: (bloc) => bloc.add(NdChangedEvent(NdValue.values[1])),
|
|
||||||
// expect: () => [
|
|
||||||
// isA<MeteringDataState>()
|
|
||||||
// .having((state) => state.ev, 'ev', -1)
|
|
||||||
// .having((state) => state.nd, 'nd', NdValue.values[1]),
|
|
||||||
// ],
|
|
||||||
// );
|
|
||||||
|
|
||||||
// blocTest<MeteringBloc, MeteringState>(
|
|
||||||
// 'Measure',
|
|
||||||
// build: () => bloc,
|
|
||||||
// act: (bloc) => bloc.add(NdChangedEvent(NdValue.values[1])),
|
|
||||||
// expect: () => [
|
|
||||||
// isA<MeteringDataState>()
|
|
||||||
// .having((state) => state.ev, 'ev', -1)
|
|
||||||
// .having((state) => state.nd, 'nd', NdValue.values[1]),
|
|
||||||
// ],
|
|
||||||
// );
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue