mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 15:30:59 +00:00
e001c153fb
* [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
73 lines
2.3 KiB
Dart
73 lines
2.3 KiB
Dart
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:lightmeter/data/volume_events_service.dart';
|
|
import 'package:mocktail/mocktail.dart';
|
|
import 'package:platform/platform.dart';
|
|
|
|
class _MockLocalPlatform extends Mock implements LocalPlatform {}
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
late _MockLocalPlatform localPlatform;
|
|
late VolumeEventsService service;
|
|
|
|
Future<Object?>? methodCallSuccessHandler(MethodCall methodCall) async {
|
|
switch (methodCall.method) {
|
|
case "setVolumeHandling":
|
|
return methodCall.arguments as bool;
|
|
default:
|
|
throw UnimplementedError();
|
|
}
|
|
}
|
|
|
|
setUp(() {
|
|
localPlatform = _MockLocalPlatform();
|
|
service = VolumeEventsService(localPlatform);
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
VolumeEventsService.volumeHandlingChannel,
|
|
methodCallSuccessHandler,
|
|
);
|
|
});
|
|
|
|
tearDown(() {
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
VolumeEventsService.volumeHandlingChannel,
|
|
null,
|
|
);
|
|
});
|
|
|
|
group('setVolumeHandling', () {
|
|
test('true - Android', () async {
|
|
when(() => localPlatform.isAndroid).thenReturn(true);
|
|
expectLater(service.setVolumeHandling(true), completion(true));
|
|
});
|
|
|
|
test('true - iOS', () async {
|
|
when(() => localPlatform.isAndroid).thenReturn(false);
|
|
expectLater(service.setVolumeHandling(true), completion(false));
|
|
});
|
|
|
|
test('false - Android', () async {
|
|
when(() => localPlatform.isAndroid).thenReturn(true);
|
|
expectLater(service.setVolumeHandling(false), completion(false));
|
|
});
|
|
|
|
test('false - iOS', () async {
|
|
when(() => localPlatform.isAndroid).thenReturn(false);
|
|
expectLater(service.setVolumeHandling(false), completion(false));
|
|
});
|
|
});
|
|
|
|
group('volumeButtonsEventStream', () {
|
|
// test('Android', () async {
|
|
// when(() => localPlatform.isAndroid).thenReturn(true);
|
|
// expect(service.volumeButtonsEventStream(), const Stream.empty());
|
|
// });
|
|
|
|
test('iOS', () async {
|
|
when(() => localPlatform.isAndroid).thenReturn(false);
|
|
expect(service.volumeButtonsEventStream(), const Stream<int>.empty());
|
|
});
|
|
});
|
|
}
|