// app/location.dart against a stand-in for MainActivity's "dash/location": a fix, or why there's none. import 'package:dash_app/app/location.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); const ch = MethodChannel('dash/location'); Future<(({double lat, double lon})?, String)> run(Map answers) async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler(ch, (c) async => answers[c.method]); var why = ''; final at = await whereAmI(none: (w) => why = w); return (at, why); } test('not allowed, refused again', () async { expect(await run({'status': {'allowed': false, 'enabled': true}, 'ask': false}), (null, 'location not allowed')); }); test('switched off', () async { expect(await run({'status': {'allowed': true, 'enabled': false}}), (null, 'location off')); }); test('the last fix', () async { final (at, _) = await run({'status': {'allowed': true, 'enabled': true}, 'last': {'lat': 47.17, 'lon': 24.06}}); expect((at!.lat, at.lon), (47.17, 24.06)); }); test('allowed now, a new fix', () async { final (at, _) = await run({'status': {'allowed': false, 'enabled': true}, 'ask': true, 'last': null, 'current': {'lat': 46.77, 'lon': 23.6}}); expect(at!.lat, 46.77); }); test('nothing found', () async { expect(await run({'status': {'allowed': true, 'enabled': true}, 'last': null, 'current': null}), (null, 'no location found')); }); }