42 lines
1.5 KiB
Dart
42 lines
1.5 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:geolocator/geolocator.dart';
|
|
import 'package:ignis_app/features/homes/geofence_logic.dart';
|
|
import 'package:ignis_app/features/homes/providers/location_providers.dart';
|
|
|
|
void main() {
|
|
test('distance formatting stays readable across ranges', () {
|
|
expect(formatDistance(0.42), '420 м');
|
|
expect(formatDistance(2.34), '2.3 км');
|
|
expect(formatDistance(12.8), '13 км');
|
|
expect(formatDistanceMeters(450), '450 м');
|
|
expect(formatDistanceMeters(1450), '1.4 км');
|
|
});
|
|
|
|
test('distance calculation stays in realistic range', () {
|
|
final distanceKm = calculateDistanceKm(55.75, 37.61, 55.76, 37.61);
|
|
expect(distanceKm, closeTo(1.11, 0.15));
|
|
});
|
|
|
|
test('background location access requires always permission', () {
|
|
expect(hasForegroundLocationAccess(LocationPermission.whileInUse), isTrue);
|
|
expect(hasBackgroundLocationAccess(LocationPermission.whileInUse), isFalse);
|
|
expect(hasBackgroundLocationAccess(LocationPermission.always), isTrue);
|
|
});
|
|
|
|
test('retry remaining expires after cooldown window', () {
|
|
final now = DateTime(2026, 5, 1, 12, 0, 0);
|
|
final lastFailure = now.subtract(const Duration(minutes: 10));
|
|
final retryRemaining = geofenceRetryRemaining(lastFailure, now: now);
|
|
|
|
expect(retryRemaining, isNotNull);
|
|
expect(retryRemaining!.inMinutes, 20);
|
|
expect(
|
|
geofenceRetryRemaining(
|
|
now.subtract(const Duration(minutes: 31)),
|
|
now: now,
|
|
),
|
|
isNull,
|
|
);
|
|
});
|
|
}
|