diff --git a/test/services/radio_preset_live_test.dart b/test/services/radio_preset_live_test.dart new file mode 100644 index 00000000..9f9cc730 --- /dev/null +++ b/test/services/radio_preset_live_test.dart @@ -0,0 +1,51 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:meshcore_open/models/radio_preset.dart'; +import 'package:meshcore_open/services/config_source_service.dart'; +import 'package:meshcore_open/services/radio_preset_service.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +// Fetches the real preset files from config-profiles (#748). Every other +// preset test fakes the network, so a 404 on main passed them all and the +// owner saw "Couldn't update presets" on a test build twice. This one fails +// whenever the app's own refresh would. +void main() { + test( + 'refresh from config-profiles succeeds with no error', + () async { + SharedPreferences.setMockInitialValues({}); + final service = RadioPresetService( + prefs: await SharedPreferences.getInstance(), + loadAsset: (_) async => throw StateError('bundled copies not used'), + ); + addTearDown(service.dispose); + + final ok = await service.refresh(); + + expect(service.refreshError, isNull, reason: 'refresh reported an error'); + expect(ok, isTrue); + expect(service.skipped, 0); + final sources = service.presets.map((p) => p.source).toSet(); + expect(sources, {RadioPresetSource.meshcore, RadioPresetSource.offband}); + }, + timeout: const Timeout(Duration(seconds: 60)), + ); + + test( + 'a missing file on config-profiles is reported, not ignored', + () async { + final source = ConfigSourceService(); + addTearDown(source.dispose); + await expectLater( + source.fetchText('${kRadioPresetBaseUrl}missing-748.json'), + throwsA( + isA().having( + (e) => '$e', + 'message', + contains('HTTP 404'), + ), + ), + ); + }, + timeout: const Timeout(Duration(seconds: 60)), + ); +} diff --git a/test/widgets/radio_preset_picker_test.dart b/test/widgets/radio_preset_picker_test.dart index 5e6a4331..a6d3caab 100644 --- a/test/widgets/radio_preset_picker_test.dart +++ b/test/widgets/radio_preset_picker_test.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:meshcore_open/l10n/app_localizations.dart'; @@ -125,6 +127,27 @@ void main() { expect(field.initialValue, isNull); }); + testWidgets('a good refresh shows no error (#748)', (tester) async { + final files = { + for (final f in [kUpstreamPresetFile, kOverlayPresetFile]) + f: File('$kRadioPresetAssetDir$f').readAsStringSync(), + }; + service = RadioPresetService( + prefs: await SharedPreferences.getInstance(), + loadAsset: (_) async => throw StateError('no assets in this test'), + fetch: (url) async => files[url.split('/').last]!, + ); + await pump(tester); + await tester.tap(find.byIcon(Icons.refresh)); + await tester.pumpAndSettle(); + expect(service.refreshError, isNull); + expect(find.textContaining('Presets updated'), findsOneWidget); + expect( + find.text("Couldn't update presets. Showing the saved list."), + findsNothing, + ); + }); + testWidgets('a failed refresh stays on screen as an error', (tester) async { await pump(tester); expect(