mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 23:40:41 +00:00
LightSensorService
tests (wip)
This commit is contained in:
parent
d1e440c9ea
commit
ed09fadd07
1 changed files with 71 additions and 0 deletions
71
test/data/light_sensor_service_test.dart
Normal file
71
test/data/light_sensor_service_test.dart
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:lightmeter/data/light_sensor_service.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
late LightSensorService service;
|
||||||
|
|
||||||
|
const methodChannel = MethodChannel('system_feature');
|
||||||
|
// TODO: add event channel mock
|
||||||
|
//const eventChannel = EventChannel('light.eventChannel');
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
service = const LightSensorService();
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() {
|
||||||
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||||
|
.setMockMethodCallHandler(methodChannel, null);
|
||||||
|
});
|
||||||
|
|
||||||
|
group(
|
||||||
|
'hasSensor()',
|
||||||
|
() {
|
||||||
|
test('true', () async {
|
||||||
|
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', () async {
|
||||||
|
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', () async {
|
||||||
|
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));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in a new issue