ZoomChangedEvent tests

This commit is contained in:
Vadim 2023-06-14 23:23:54 +02:00
parent d39cf7575c
commit a9f648791e
3 changed files with 95 additions and 14 deletions

View file

@ -22,12 +22,32 @@ class ZoomChangedEvent extends CameraContainerEvent {
final double value;
const ZoomChangedEvent(this.value);
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
if (other.runtimeType != runtimeType) return false;
return other is ZoomChangedEvent && other.value == value;
}
@override
int get hashCode => Object.hash(value, runtimeType);
}
class ExposureOffsetChangedEvent extends CameraContainerEvent {
final double value;
const ExposureOffsetChangedEvent(this.value);
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
if (other.runtimeType != runtimeType) return false;
return other is ExposureOffsetChangedEvent && other.value == value;
}
@override
int get hashCode => Object.hash(value, runtimeType);
}
class ExposureOffsetResetEvent extends CameraContainerEvent {

View file

@ -34,6 +34,28 @@ class CameraActiveState extends CameraContainerState {
required this.exposureOffsetStep,
required this.currentExposureOffset,
});
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
if (other.runtimeType != runtimeType) return false;
return other is CameraActiveState &&
other.zoomRange == zoomRange &&
other.currentZoom == currentZoom &&
other.exposureOffsetRange == exposureOffsetRange &&
other.exposureOffsetStep == exposureOffsetStep &&
other.currentExposureOffset == currentExposureOffset;
}
@override
int get hashCode => Object.hash(
runtimeType,
zoomRange,
currentZoom,
exposureOffsetRange,
exposureOffsetStep,
currentExposureOffset,
);
}
class CameraErrorState extends CameraContainerState {

View file

@ -104,10 +104,14 @@ void main() {
meteringInteractor,
communicationBloc,
);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(cameraMethodChannel, cameraMethodCallSuccessHandler);
});
tearDown(() {
bloc.close();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(cameraMethodChannel, null);
});
group(
@ -161,8 +165,7 @@ void main() {
verify(() => meteringInteractor.checkCameraPermission()).called(1);
},
expect: () => [
isA<CameraLoadingState>(),
// Proceed to `InitializeEvent` tests from here
...initializedStateSequence,
],
);
},
@ -240,12 +243,6 @@ void main() {
'appLifecycleStateObserver',
setUp: () {
when(() => meteringInteractor.checkCameraPermission()).thenAnswer((_) async => true);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(cameraMethodChannel, cameraMethodCallSuccessHandler);
},
tearDown: () {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(cameraMethodChannel, null);
},
build: () => bloc,
act: (bloc) async {
@ -274,12 +271,6 @@ void main() {
'Returned ev100 == null',
setUp: () {
when(() => meteringInteractor.checkCameraPermission()).thenAnswer((_) async => true);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(cameraMethodChannel, cameraMethodCallSuccessHandler);
},
tearDown: () {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(cameraMethodChannel, null);
},
build: () => bloc,
act: (bloc) async {
@ -326,6 +317,54 @@ void main() {
// ],
// );
},
skip: true,
);
group(
'`ZoomChangedEvent` tests',
() {
blocTest<CameraContainerBloc, CameraContainerState>(
'Set zoom in range multiple times',
setUp: () {
when(() => meteringInteractor.checkCameraPermission()).thenAnswer((_) async => true);
},
build: () => bloc,
act: (bloc) async {
bloc.add(const InitializeEvent());
await Future.delayed(Duration.zero);
bloc.add(const ZoomChangedEvent(2.0));
bloc.add(const ZoomChangedEvent(2.0));
bloc.add(const ZoomChangedEvent(2.0));
bloc.add(const ZoomChangedEvent(3.0));
},
verify: (_) {
verify(() => meteringInteractor.checkCameraPermission()).called(1);
},
expect: () => [
...initializedStateSequence,
isA<CameraActiveState>()
.having((state) => state.zoomRange, 'zoomRange', const RangeValues(1.0, 7.0))
.having((state) => state.currentZoom, 'currentZoom', 2.0)
.having(
(state) => state.exposureOffsetRange,
'exposureOffsetRange',
const RangeValues(-4.0, 4.0),
)
.having((state) => state.exposureOffsetStep, 'exposureOffsetStep', 0.1666666)
.having((state) => state.currentExposureOffset, 'currentExposureOffset', 0.0),
isA<CameraActiveState>()
.having((state) => state.zoomRange, 'zoomRange', const RangeValues(1.0, 7.0))
.having((state) => state.currentZoom, 'currentZoom', 3.0)
.having(
(state) => state.exposureOffsetRange,
'exposureOffsetRange',
const RangeValues(-4.0, 4.0),
)
.having((state) => state.exposureOffsetStep, 'exposureOffsetStep', 0.1666666)
.having((state) => state.currentExposureOffset, 'currentExposureOffset', 0.0),
],
);
},
);
}