Merge branch 'feat/726-preset-catalog' into feat/733-remote-presets

pull/746/head
diffwireauto 2 months ago
commit f20568d46c

@ -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<ConfigSourceException>().having(
(e) => '$e',
'message',
contains('HTTP 404'),
),
),
);
},
timeout: const Timeout(Duration(seconds: 60)),
);
}

@ -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(

Loading…
Cancel
Save

Powered by TurnKey Linux.