Replace geofence polling with native Android geofence

This commit is contained in:
Artem Kokos
2026-05-12 11:23:44 +07:00
parent 0a5ef9af17
commit 1963488479
38 changed files with 1099 additions and 1931 deletions

View File

@@ -0,0 +1,95 @@
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:ignis_app/features/homes/services/geofence_automation_service.dart';
import 'package:ignis_app/models/home_config.dart';
import 'package:ignis_app/services/settings_service.dart';
import 'test_support.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
const channel = MethodChannel('ignis/geofence_automation');
final calls = <MethodCall>[];
setUp(() {
calls.clear();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (call) async {
calls.add(call);
return null;
});
});
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, null);
});
test('disarms native geofence when active home is null', () async {
final service = GeofenceAutomationService(
settingsService: SettingsService(
credentialsStorage: InMemoryCredentialsStorage(),
),
);
await service.syncActiveHome(null);
expect(calls, hasLength(1));
expect(calls.single.method, 'disarmGeofence');
expect(calls.single.arguments, isNull);
});
test('disarms native geofence when home is not geofence-ready', () async {
final service = GeofenceAutomationService(
settingsService: SettingsService(
credentialsStorage: InMemoryCredentialsStorage(),
),
);
await service.syncActiveHome(
HomeConfig(
id: 'home-1',
name: 'Home 1',
url: 'https://one.example',
latitude: 55.75,
longitude: 37.61,
geofenceEnabled: false,
),
);
expect(calls, hasLength(1));
expect(calls.single.method, 'disarmGeofence');
});
test('arms native geofence with stored api key and radius', () async {
final settingsService = SettingsService(
credentialsStorage: InMemoryCredentialsStorage(),
);
await settingsService.setHomeApiKey('home-1', 'secret-key');
final service = GeofenceAutomationService(settingsService: settingsService);
await service.syncActiveHome(
HomeConfig(
id: 'home-1',
name: 'Home 1',
url: 'https://one.example',
latitude: 55.75,
longitude: 37.61,
geofenceEnabled: true,
geofenceRadiusMeters: 750,
),
);
expect(calls, hasLength(1));
expect(calls.single.method, 'armGeofence');
expect(calls.single.arguments, <String, Object?>{
'homeId': 'home-1',
'baseUrl': 'https://one.example',
'apiKey': 'secret-key',
'latitude': 55.75,
'longitude': 37.61,
'radiusMeters': 750,
});
});
}