m3_lightmeter/test/screens/metering/communication/bloc_communication_metering_test.dart
Vadim e001c153fb
ML-11 Implement volume buttons actions (#86)
* [Android] wip

* implemented `VolumeEventsService`

* implemented `VolumeKeysListener` (wip)

* Added screenshots links

* [Android] nullable typo

* implemented `VolumeKeysNotifier`

* deinitialize camera when on Settings screen

* disable volume handling when on Settings screen

* used "platform" package to mock `isAndroid`

* init/deinit camera on settings open

* allow volume action override only on metering screen

* lints

* cleanup

* await dispose

* tests

* reduced `SwitchListTile.contentPadding`

* fixed tests

* removed `VolumeAction.zoom`

* added social preview

* typo

* fixed `CameraContainerBloc` tests

* added `Stream.empty()` tests
2023-07-09 13:39:33 +02:00

127 lines
4.2 KiB
Dart

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`',
() {
blocTest<MeteringCommunicationBloc, MeteringCommunicationState>(
'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<MeasureState>(),
isA<MeasureState>(),
isA<MeasureState>(),
isA<MeasureState>(),
],
);
blocTest<MeteringCommunicationBloc, MeteringCommunicationState>(
'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));
bloc.add(const MeteringEndedEvent(2));
},
expect: () => [
isA<MeasureState>(),
isA<MeteringInProgressState>().having((state) => state.ev100, 'ev100', 1),
isA<MeteringInProgressState>().having((state) => state.ev100, 'ev100', null),
isA<MeteringInProgressState>().having((state) => state.ev100, 'ev100', 2),
isA<MeasureState>(),
isA<MeteringEndedState>().having((state) => state.ev100, 'ev100', 2),
],
);
},
);
group(
'`MeteringInProgressEvent`',
() {
blocTest<MeteringCommunicationBloc, MeteringCommunicationState>(
'Multiple consequtive in progress events',
build: () => bloc,
act: (bloc) async {
bloc.add(const MeteringInProgressEvent(1));
bloc.add(const MeteringInProgressEvent(1));
bloc.add(const MeteringInProgressEvent(1));
bloc.add(const MeteringInProgressEvent(null));
bloc.add(const MeteringInProgressEvent(null));
bloc.add(const MeteringInProgressEvent(2));
},
expect: () => [
isA<MeteringInProgressState>().having((state) => state.ev100, 'ev100', 1),
isA<MeteringInProgressState>().having((state) => state.ev100, 'ev100', null),
isA<MeteringInProgressState>().having((state) => state.ev100, 'ev100', 2),
],
);
},
);
group(
'`MeteringEndedEvent`',
() {
blocTest<MeteringCommunicationBloc, MeteringCommunicationState>(
'Multiple consequtive ended events',
build: () => bloc,
act: (bloc) async {
bloc.add(const MeteringEndedEvent(1));
},
expect: () => [
isA<MeteringEndedState>().having((state) => state.ev100, 'ev100', 1),
],
);
},
);
group(
'`SettingsOpenedEvent`/`SettingsClosedEvent`',
() {
blocTest<MeteringCommunicationBloc, MeteringCommunicationState>(
'Multiple consequtive settings events',
build: () => bloc,
act: (bloc) async {
bloc.add(const SettingsOpenedEvent());
bloc.add(const SettingsOpenedEvent());
bloc.add(const SettingsOpenedEvent());
bloc.add(const SettingsClosedEvent());
bloc.add(const SettingsClosedEvent());
bloc.add(const SettingsClosedEvent());
bloc.add(const SettingsOpenedEvent());
bloc.add(const SettingsClosedEvent());
},
expect: () => [
isA<SettingsOpenedState>(),
isA<SettingsClosedState>(),
isA<SettingsOpenedState>(),
isA<SettingsClosedState>(),
],
);
},
);
}