m3_lightmeter/test/screens/metering/communication/bloc_communication_metering_test.dart

102 lines
3.3 KiB
Dart
Raw Normal View History

2023-06-09 12:51:15 +00:00
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(
2023-06-15 12:57:03 +00:00
'`MeasureEvent`',
2023-06-09 12:51:15 +00:00
() {
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));
2023-06-09 12:51:15 +00:00
},
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(
2023-06-15 12:57:03 +00:00
'`MeteringInProgressEvent`',
2023-06-09 12:51:15 +00:00
() {
blocTest<MeteringCommunicationBloc, MeteringCommunicationState>(
'Multiple consequtive in progress events',
build: () => bloc,
act: (bloc) async {
2023-06-09 21:22:21 +00:00
bloc.add(const MeteringInProgressEvent(1));
bloc.add(const MeteringInProgressEvent(1));
2023-06-09 12:51:15 +00:00
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(
2023-06-15 12:57:03 +00:00
'`MeteringEndedEvent`',
2023-06-09 12:51:15 +00:00
() {
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),
],
);
},
);
}