Implementiert den kompletten Kern-Flow der Emergency App gemäß docs/plan.md: - Notrufnummern-Datenbasis für 199 Länder + Modelle/Repository (AP1) - DialerService für tel:-Notrufe ohne Auto-Dial (AP2) - Statisches UI mit Panik-Button-Fallback (AP3) - Priorisierte Ländererkennung: SIM/Netz -> GPS/Geocoding -> Cache (AP4) - EmergencyProvider verdrahtet Repository/LocationService mit der UI (AP5) - Manuelle Länderauswahl als Fallback samt eigener Priorität (AP6) - UI-Lokalisierung (de/en/fr/es), an erkanntes Land gekoppelt (AP7) Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
63 lines
2.0 KiB
Dart
63 lines
2.0 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
||
import 'package:url_launcher_platform_interface/link.dart';
|
||
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
|
||
|
||
import 'package:emergency/services/dialer_service.dart';
|
||
|
||
/// Fake-Implementierung der `url_launcher`-Plattformschnittstelle.
|
||
///
|
||
/// Vermeidet Mocking auf `MethodChannel`-Ebene: `url_launcher` erlaubt es,
|
||
/// [UrlLauncherPlatform.instance] durch eine eigene Implementierung zu
|
||
/// ersetzen – das ist der offiziell vorgesehene Weg, das Package in reinen
|
||
/// Unit-Tests ohne echte Plattform-Kanäle zu testen.
|
||
class _FakeUrlLauncherPlatform extends UrlLauncherPlatform {
|
||
_FakeUrlLauncherPlatform({required this.canLaunchResult});
|
||
|
||
final bool canLaunchResult;
|
||
|
||
String? launchedUrl;
|
||
int launchCallCount = 0;
|
||
|
||
@override
|
||
LinkDelegate? get linkDelegate => null;
|
||
|
||
@override
|
||
Future<bool> canLaunch(String url) async => canLaunchResult;
|
||
|
||
@override
|
||
Future<bool> launchUrl(String url, LaunchOptions options) async {
|
||
launchCallCount++;
|
||
launchedUrl = url;
|
||
return true;
|
||
}
|
||
}
|
||
|
||
void main() {
|
||
TestWidgetsFlutterBinding.ensureInitialized();
|
||
|
||
group('DialerService', () {
|
||
const dialerService = DialerService();
|
||
|
||
test('call() öffnet den Wähler mit tel:-URI und liefert true, wenn canLaunch true ist', () async {
|
||
final fakePlatform = _FakeUrlLauncherPlatform(canLaunchResult: true);
|
||
UrlLauncherPlatform.instance = fakePlatform;
|
||
|
||
final result = await dialerService.call('112');
|
||
|
||
expect(result, isTrue);
|
||
expect(fakePlatform.launchCallCount, 1);
|
||
expect(fakePlatform.launchedUrl, 'tel:112');
|
||
});
|
||
|
||
test('call() liefert false ohne launch(), wenn canLaunch false ist', () async {
|
||
final fakePlatform = _FakeUrlLauncherPlatform(canLaunchResult: false);
|
||
UrlLauncherPlatform.instance = fakePlatform;
|
||
|
||
final result = await dialerService.call('911');
|
||
|
||
expect(result, isFalse);
|
||
expect(fakePlatform.launchCallCount, 0);
|
||
});
|
||
});
|
||
}
|