Adjust android process
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import 'package:fl_clash/common/constant.dart';
|
||||
import 'package:fl_clash/plugins/app.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
const channel = MethodChannel('$packageName/app');
|
||||
|
||||
tearDown(() {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, null);
|
||||
});
|
||||
|
||||
test('reads previous execution crash state from Android', () async {
|
||||
MethodCall? receivedCall;
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (call) async {
|
||||
receivedCall = call;
|
||||
return true;
|
||||
});
|
||||
|
||||
final didCrash = await App().didCrashOnPreviousExecution();
|
||||
|
||||
expect(didCrash, isTrue);
|
||||
expect(receivedCall, isNotNull);
|
||||
expect(receivedCall!.method, 'didCrashOnPreviousExecution');
|
||||
});
|
||||
|
||||
test('uses false when Android returns no crash state', () async {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (_) async => null);
|
||||
|
||||
expect(await App().didCrashOnPreviousExecution(), isFalse);
|
||||
});
|
||||
|
||||
test('uses false when crash detection is unavailable', () async {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (_) async {
|
||||
throw PlatformException(code: 'unavailable');
|
||||
});
|
||||
|
||||
expect(await App().didCrashOnPreviousExecution(), isFalse);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import 'package:fl_clash/common/permission.dart';
|
||||
import 'package:fl_clash/providers/app.dart';
|
||||
import 'package:fl_clash/providers/config.dart';
|
||||
import 'package:fl_clash/state.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:riverpod/riverpod.dart';
|
||||
import 'package:wifi_ssid/wifi_ssid.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
const channel = MethodChannel('wifi_ssid');
|
||||
late ProviderContainer container;
|
||||
|
||||
setUp(() {
|
||||
container = ProviderContainer(
|
||||
overrides: [
|
||||
excludeSSIDsProvider.overrideWithValue(const ['Office Wi-Fi']),
|
||||
],
|
||||
);
|
||||
globalState.container = container;
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, null);
|
||||
container.dispose();
|
||||
});
|
||||
|
||||
test('maps permission results to the correct UI follow-up', () {
|
||||
expect(
|
||||
getLocationPermissionFollowUp(WifiSsidPermission.granted),
|
||||
LocationPermissionFollowUp.none,
|
||||
);
|
||||
expect(
|
||||
getLocationPermissionFollowUp(WifiSsidPermission.denied),
|
||||
LocationPermissionFollowUp.showDeniedMessage,
|
||||
);
|
||||
expect(
|
||||
getLocationPermissionFollowUp(WifiSsidPermission.permanentlyDenied),
|
||||
LocationPermissionFollowUp.openSettings,
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'refreshes current SSID immediately after permission is granted',
|
||||
() async {
|
||||
final calls = <String>[];
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (call) async {
|
||||
calls.add(call.method);
|
||||
return switch (call.method) {
|
||||
'checkPermission' => 1,
|
||||
'requestPermission' => 0,
|
||||
'getSsid' => 'Office Wi-Fi',
|
||||
_ => null,
|
||||
};
|
||||
});
|
||||
|
||||
await Permissions.test(
|
||||
supportsLocationPermissions: true,
|
||||
).checkLocationPermissions();
|
||||
|
||||
expect(calls, ['checkPermission', 'requestPermission', 'getSsid']);
|
||||
expect(
|
||||
container.read(locationPermissionsProvider),
|
||||
WifiSsidPermission.granted,
|
||||
);
|
||||
expect(container.read(currentSSIDProvider), 'Office Wi-Fi');
|
||||
},
|
||||
);
|
||||
|
||||
test('does not read SSID when permission remains denied', () async {
|
||||
final calls = <String>[];
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (call) async {
|
||||
calls.add(call.method);
|
||||
return 1;
|
||||
});
|
||||
|
||||
await Permissions.test(
|
||||
supportsLocationPermissions: true,
|
||||
).checkLocationPermissions();
|
||||
|
||||
expect(calls, ['checkPermission', 'requestPermission']);
|
||||
expect(
|
||||
container.read(locationPermissionsProvider),
|
||||
WifiSsidPermission.denied,
|
||||
);
|
||||
expect(container.read(currentSSIDProvider), isNull);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user