mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-24 08:20:40 +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
98 lines
3.2 KiB
Dart
98 lines
3.2 KiB
Dart
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:lightmeter/data/light_sensor_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 LightSensorService service;
|
|
|
|
const methodChannel = MethodChannel('system_feature');
|
|
// TODO: add event channel mock
|
|
//const eventChannel = EventChannel('light.eventChannel');
|
|
|
|
setUp(() {
|
|
localPlatform = _MockLocalPlatform();
|
|
service = LightSensorService(localPlatform);
|
|
});
|
|
|
|
tearDown(() {
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(methodChannel, null);
|
|
});
|
|
|
|
group(
|
|
'hasSensor()',
|
|
() {
|
|
test('true - Android', () async {
|
|
when(() => localPlatform.isAndroid).thenReturn(true);
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(methodChannel, null);
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(methodChannel, (methodCall) async {
|
|
switch (methodCall.method) {
|
|
case "sensor":
|
|
return true;
|
|
default:
|
|
return null;
|
|
}
|
|
});
|
|
expectLater(service.hasSensor(), completion(true));
|
|
});
|
|
|
|
test('false - Android', () async {
|
|
when(() => localPlatform.isAndroid).thenReturn(true);
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(methodChannel, null);
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(methodChannel, (methodCall) async {
|
|
switch (methodCall.method) {
|
|
case "sensor":
|
|
return false;
|
|
default:
|
|
return null;
|
|
}
|
|
});
|
|
expectLater(service.hasSensor(), completion(false));
|
|
});
|
|
|
|
test('null - Android', () async {
|
|
when(() => localPlatform.isAndroid).thenReturn(true);
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(methodChannel, null);
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(methodChannel, (methodCall) async {
|
|
switch (methodCall.method) {
|
|
case "sensor":
|
|
return null;
|
|
default:
|
|
return null;
|
|
}
|
|
});
|
|
expectLater(service.hasSensor(), completion(false));
|
|
});
|
|
|
|
test('false - iOS', () async {
|
|
when(() => localPlatform.isAndroid).thenReturn(false);
|
|
expectLater(service.hasSensor(), completion(false));
|
|
});
|
|
},
|
|
);
|
|
|
|
group('luxStream', () {
|
|
// test('Android', () async {
|
|
// when(() => localPlatform.isAndroid).thenReturn(true);
|
|
// expect(service.luxStream(), const Stream.empty());
|
|
// });
|
|
|
|
test('iOS', () async {
|
|
when(() => localPlatform.isAndroid).thenReturn(false);
|
|
expect(service.luxStream(), const Stream<int>.empty());
|
|
});
|
|
});
|
|
}
|