2023-07-03 08:47:01 +00:00
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:lightmeter/data/volume_events_service.dart';
|
2023-07-05 14:29:33 +00:00
|
|
|
import 'package:mocktail/mocktail.dart';
|
|
|
|
import 'package:platform/platform.dart';
|
|
|
|
|
|
|
|
class _MockLocalPlatform extends Mock implements LocalPlatform {}
|
2023-07-03 08:47:01 +00:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
2023-07-05 14:29:33 +00:00
|
|
|
late _MockLocalPlatform localPlatform;
|
2023-07-03 08:47:01 +00:00
|
|
|
late VolumeEventsService service;
|
2023-07-05 14:29:33 +00:00
|
|
|
|
2023-07-03 08:47:01 +00:00
|
|
|
Future<Object?>? methodCallSuccessHandler(MethodCall methodCall) async {
|
|
|
|
switch (methodCall.method) {
|
|
|
|
case "setVolumeHandling":
|
|
|
|
return methodCall.arguments as bool;
|
|
|
|
default:
|
|
|
|
throw UnimplementedError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setUp(() {
|
2023-07-05 14:29:33 +00:00
|
|
|
localPlatform = _MockLocalPlatform();
|
|
|
|
service = VolumeEventsService(localPlatform);
|
2023-07-03 08:47:01 +00:00
|
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
|
|
VolumeEventsService.volumeHandlingChannel,
|
|
|
|
methodCallSuccessHandler,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() {
|
|
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
|
|
VolumeEventsService.volumeHandlingChannel,
|
|
|
|
null,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
group('setVolumeHandling', () {
|
2023-07-05 14:29:33 +00:00
|
|
|
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));
|
|
|
|
});
|
2023-07-03 08:47:01 +00:00
|
|
|
|
2023-07-05 14:29:33 +00:00
|
|
|
test('false - iOS', () async {
|
|
|
|
when(() => localPlatform.isAndroid).thenReturn(false);
|
|
|
|
expectLater(service.setVolumeHandling(false), completion(false));
|
|
|
|
});
|
2023-07-03 08:47:01 +00:00
|
|
|
});
|
|
|
|
}
|