Skip to content

Commit

Permalink
ZoomChangedEvent tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vodemn committed Jun 14, 2023
1 parent d39cf75 commit a9f6487
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@ void main() {
meteringInteractor,
communicationBloc,
);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(cameraMethodChannel, cameraMethodCallSuccessHandler);
});

tearDown(() {
bloc.close();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(cameraMethodChannel, null);
});

group(
Expand Down Expand Up @@ -161,8 +165,7 @@ void main() {
verify(() => meteringInteractor.checkCameraPermission()).called(1);
},
expect: () => [
isA<CameraLoadingState>(),
// Proceed to `InitializeEvent` tests from here
...initializedStateSequence,
],
);
},
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
],
);
},
);
}

Expand Down

0 comments on commit a9f6487

Please sign in to comment.