2023-11-01 19:45:48 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:lightmeter/data/models/volume_action.dart';
|
|
|
|
import 'package:lightmeter/data/volume_events_service.dart';
|
|
|
|
import 'package:lightmeter/screens/metering/utils/notifier_volume_keys.dart';
|
|
|
|
import 'package:mocktail/mocktail.dart';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
2023-11-01 20:09:56 +00:00
|
|
|
import '../../../function_mock.dart';
|
2023-11-01 19:45:48 +00:00
|
|
|
|
2023-11-01 20:09:56 +00:00
|
|
|
class _MockVolumeEventsService extends Mock implements VolumeEventsService {}
|
2023-11-01 19:45:48 +00:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
late _MockVolumeEventsService mockVolumeEventsService;
|
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
mockVolumeEventsService = _MockVolumeEventsService();
|
|
|
|
});
|
|
|
|
|
|
|
|
test(
|
|
|
|
'Listen to `volumeButtonsEventStream()`',
|
|
|
|
() async {
|
|
|
|
final StreamController<int> volumeButtonsEvents = StreamController<int>();
|
|
|
|
when(() => mockVolumeEventsService.volumeButtonsEventStream()).thenAnswer((_) => volumeButtonsEvents.stream);
|
|
|
|
|
|
|
|
final volumeKeysNotifier = VolumeKeysNotifier(mockVolumeEventsService);
|
2023-11-01 20:09:56 +00:00
|
|
|
final functions = MockValueChanged<VolumeKey>();
|
2023-11-01 19:45:48 +00:00
|
|
|
volumeKeysNotifier.addListener(() => functions.onChanged(volumeKeysNotifier.value));
|
|
|
|
expect(volumeKeysNotifier.value, VolumeKey.up);
|
|
|
|
|
|
|
|
volumeButtonsEvents.add(25);
|
|
|
|
volumeButtonsEvents.add(25);
|
|
|
|
volumeButtonsEvents.add(25);
|
|
|
|
volumeButtonsEvents.add(24);
|
|
|
|
volumeButtonsEvents.add(24);
|
|
|
|
volumeButtonsEvents.add(25);
|
|
|
|
await Future.delayed(Duration.zero);
|
|
|
|
verify(() => functions.onChanged(VolumeKey.up)).called(2);
|
|
|
|
verify(() => functions.onChanged(VolumeKey.down)).called(4);
|
|
|
|
|
|
|
|
volumeKeysNotifier.removeListener(() => functions.onChanged(volumeKeysNotifier.value));
|
|
|
|
await volumeKeysNotifier.dispose();
|
|
|
|
await volumeButtonsEvents.close();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|