mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-24 08:20:40 +00:00
f3b08868be
- Fixed test coverage calculation - Removed `mockito` from the application mock - Implemented platform channel mocks to mimic incident light metering - Covered providers with unit tests - Covered metering screen pickers with widget tests - Laid foundation for integration tests
59 lines
1.6 KiB
Dart
59 lines
1.6 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:light_sensor/light_sensor.dart';
|
|
|
|
void setLightSensorAvilability({required bool hasSensor}) {
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
LightSensor.methodChannel,
|
|
(methodCall) async {
|
|
switch (methodCall.method) {
|
|
case "sensor":
|
|
return hasSensor;
|
|
default:
|
|
return null;
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
void resetLightSensorAvilability() {
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
LightSensor.methodChannel,
|
|
null,
|
|
);
|
|
}
|
|
|
|
Future<void> sendMockIncidentEv(double ev) => sendMockLux((2.5 * pow(2, ev)).toInt());
|
|
|
|
Future<void> sendMockLux([int lux = 100]) async {
|
|
await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
|
|
LightSensor.eventChannel.name,
|
|
const StandardMethodCodec().encodeSuccessEnvelope(lux),
|
|
(ByteData? data) {},
|
|
);
|
|
}
|
|
|
|
void setupLightSensorStreamHandler() {
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
MethodChannel(LightSensor.eventChannel.name),
|
|
(methodCall) async {
|
|
switch (methodCall.method) {
|
|
case "listen":
|
|
return;
|
|
case "cancel":
|
|
return;
|
|
default:
|
|
return null;
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
void resetLightSensorStreamHandler() {
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
MethodChannel(LightSensor.eventChannel.name),
|
|
null,
|
|
);
|
|
}
|