2023-10-17 09:58:48 +00:00
|
|
|
import 'dart:math';
|
|
|
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
2023-10-19 20:23:05 +00:00
|
|
|
import 'package:light_sensor/light_sensor.dart';
|
2023-10-18 21:58:57 +00:00
|
|
|
|
2023-10-18 13:18:59 +00:00
|
|
|
void setLightSensorAvilability({required bool hasSensor}) {
|
|
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
2023-10-19 20:23:05 +00:00
|
|
|
LightSensor.methodChannel,
|
2023-10-18 13:18:59 +00:00
|
|
|
(methodCall) async {
|
|
|
|
switch (methodCall.method) {
|
|
|
|
case "sensor":
|
|
|
|
return hasSensor;
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
2023-10-17 09:58:48 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-10-18 13:18:59 +00:00
|
|
|
void resetLightSensorAvilability() {
|
|
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
2023-10-19 20:23:05 +00:00
|
|
|
LightSensor.methodChannel,
|
2023-10-18 13:18:59 +00:00
|
|
|
null,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> sendMockIncidentEv(double ev) => sendMockLux((2.5 * pow(2, ev)).toInt());
|
|
|
|
|
|
|
|
Future<void> sendMockLux([int lux = 100]) async {
|
2023-10-17 09:58:48 +00:00
|
|
|
await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
|
2023-10-19 20:23:05 +00:00
|
|
|
LightSensor.eventChannel.name,
|
2023-10-18 13:18:59 +00:00
|
|
|
const StandardMethodCodec().encodeSuccessEnvelope(lux),
|
2023-10-17 09:58:48 +00:00
|
|
|
(ByteData? data) {},
|
|
|
|
);
|
|
|
|
}
|
2023-10-17 15:01:11 +00:00
|
|
|
|
2023-10-18 13:18:59 +00:00
|
|
|
void setupLightSensorStreamHandler() {
|
2023-10-17 15:01:11 +00:00
|
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
2023-10-19 20:23:05 +00:00
|
|
|
MethodChannel(LightSensor.eventChannel.name),
|
2023-10-17 15:01:11 +00:00
|
|
|
(methodCall) async {
|
|
|
|
switch (methodCall.method) {
|
2023-10-18 13:18:59 +00:00
|
|
|
case "listen":
|
|
|
|
return;
|
|
|
|
case "cancel":
|
|
|
|
return;
|
2023-10-17 15:01:11 +00:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2023-10-18 13:18:59 +00:00
|
|
|
|
|
|
|
void resetLightSensorStreamHandler() {
|
|
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
2023-10-19 20:23:05 +00:00
|
|
|
MethodChannel(LightSensor.eventChannel.name),
|
2023-10-18 13:18:59 +00:00
|
|
|
null,
|
|
|
|
);
|
|
|
|
}
|