The Mini-Altitude-Profile terrain data only ever lived in TerrainNotifier's in-memory state (one slot, keyed by route). Every app restart, or every switch away from and back to a mission, forced a full re-fetch of all AWS Terrarium elevation tiles for the route - the noticeably slow load the user reported for some missions was this happening on every visit, not just once. Adds a nullable terrainProfileJson column to the missions table (schema v6->v7) and a saveTerrainProfile() repository method, kept separate from the regular waypoint upsert() so an ordinary autosave never clobbers an already-cached profile. TerrainNotifier persists a profile right after a successful fetch (fire-and-forget) and gains restore(), called from CurrentMissionMetaNotifier whenever a mission is loaded/ started so a previously fetched profile is available immediately - ensureFor() still validates its routeKey before use, so a stale restored profile is never shown for a route that has since changed. Also included in mission export/import (MissionExportData/ ParsedMissionImport) so sharing a mission carries its terrain cache along instead of forcing the recipient to refetch it. Sample-count/resolution stays as-is for now (still fixed 30m spacing, 10-2000 samples) - adapting the sampling density to terrain variance (e.g. coarser sampling over flat ground) is a separate follow-up. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
157 lines
4.9 KiB
Dart
157 lines
4.9 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:dmc_app/domain/mission/terrain_math.dart';
|
|
import 'package:dmc_app/domain/waypoint/flat_waypoint_list.dart';
|
|
import 'package:dmc_app/services/sharing/mission_share_codec.dart';
|
|
|
|
void main() {
|
|
const waypoints = [
|
|
Waypoint(
|
|
lat: 48.1351,
|
|
lon: 11.5820,
|
|
altitudeM: 60,
|
|
speedMs: 15,
|
|
catchRadiusM: 60,
|
|
windSpeedMs: 4,
|
|
windDirFromDeg: 270,
|
|
windElevationM: 520,
|
|
),
|
|
Waypoint(
|
|
lat: 48.1360,
|
|
lon: 11.5830,
|
|
altitudeM: 120,
|
|
speedMs: 20,
|
|
catchRadiusM: 60,
|
|
action: WaypointAction.loiter,
|
|
),
|
|
];
|
|
|
|
group('buildMissionExportJson / parseMissionImportJson', () {
|
|
test('round-trip erhaelt Name, Ort und alle Wegpunktfelder', () {
|
|
final json = buildMissionExportJson(MissionExportData(
|
|
name: 'Munich Loop',
|
|
placeName: 'Munich',
|
|
createdAt: DateTime.utc(2026, 1, 1),
|
|
waypoints: waypoints,
|
|
));
|
|
|
|
final parsed = parseMissionImportJson(json);
|
|
|
|
expect(parsed.name, 'Munich Loop');
|
|
expect(parsed.placeName, 'Munich');
|
|
expect(parsed.versionMismatch, isNull);
|
|
expect(parsed.waypoints, hasLength(2));
|
|
expect(parsed.waypoints[0].lat, waypoints[0].lat);
|
|
expect(parsed.waypoints[0].windSpeedMs, 4);
|
|
expect(parsed.waypoints[1].action, WaypointAction.loiter);
|
|
});
|
|
|
|
test('fehlende appVersion-Uebereinstimmung wird als Mismatch erkannt', () {
|
|
final json = buildMissionExportJson(MissionExportData(
|
|
name: 'Old export',
|
|
placeName: null,
|
|
createdAt: DateTime.utc(2020, 1, 1),
|
|
waypoints: waypoints,
|
|
)).replaceFirst('"1.0.0"', '"2.4.1"');
|
|
|
|
final parsed = parseMissionImportJson(json);
|
|
|
|
expect(parsed.versionMismatch, '2.4.1');
|
|
});
|
|
|
|
test('Datei ohne "appVersion"-Umschlag (nur das rohe mission-Objekt) wird akzeptiert', () {
|
|
final rawMission = {
|
|
'name': 'Bare mission',
|
|
'waypoints': [
|
|
{
|
|
'lat': 1.0,
|
|
'lon': 2.0,
|
|
'altitudeM': 60.0,
|
|
'speedMs': 15.0,
|
|
'catchRadiusM': 60.0,
|
|
'action': 'none',
|
|
},
|
|
],
|
|
};
|
|
final parsed = parseMissionImportJson(jsonEncode(rawMission));
|
|
expect(parsed.name, 'Bare mission');
|
|
expect(parsed.waypoints, hasLength(1));
|
|
});
|
|
|
|
test('wirft FormatException bei ungueltigem JSON', () {
|
|
expect(() => parseMissionImportJson('not json'), throwsFormatException);
|
|
});
|
|
|
|
test('wirft FormatException wenn Wegpunkte fehlen', () {
|
|
expect(
|
|
() => parseMissionImportJson('{"mission": {"name": "Empty"}}'),
|
|
throwsFormatException,
|
|
);
|
|
});
|
|
|
|
test('fehlender Name faellt auf placeName, dann auf Standardtext zurueck', () {
|
|
final withPlaceOnly = parseMissionImportJson(
|
|
'{"mission": {"placeName": "Somewhere", "waypoints": [{"lat":1,"lon":1,'
|
|
'"altitudeM":60,"speedMs":15,"catchRadiusM":60,"action":"none"}]}}',
|
|
);
|
|
expect(withPlaceOnly.name, 'Somewhere');
|
|
|
|
final withNeither = parseMissionImportJson(
|
|
'{"mission": {"waypoints": [{"lat":1,"lon":1,'
|
|
'"altitudeM":60,"speedMs":15,"catchRadiusM":60,"action":"none"}]}}',
|
|
);
|
|
expect(withNeither.name, 'Imported mission');
|
|
});
|
|
});
|
|
|
|
group('Bodenhoehenprofil im Export', () {
|
|
const profile = TerrainProfile(
|
|
routeKey: '48.13510,11.58200|48.13600,11.58300',
|
|
points: [
|
|
TerrainSamplePoint(distanceM: 0, elevationRelM: 0),
|
|
TerrainSamplePoint(distanceM: 50, elevationRelM: -3.2),
|
|
TerrainSamplePoint(distanceM: 100, elevationRelM: null),
|
|
],
|
|
);
|
|
|
|
test('wird mitexportiert und beim Import wiederhergestellt', () {
|
|
final json = buildMissionExportJson(MissionExportData(
|
|
name: 'Munich Loop',
|
|
placeName: 'Munich',
|
|
createdAt: DateTime.utc(2026, 1, 1),
|
|
waypoints: waypoints,
|
|
terrainProfile: profile,
|
|
));
|
|
|
|
final parsed = parseMissionImportJson(json);
|
|
|
|
expect(parsed.terrainProfile, isNotNull);
|
|
expect(parsed.terrainProfile!.routeKey, profile.routeKey);
|
|
expect(parsed.terrainProfile!.points, hasLength(3));
|
|
expect(parsed.terrainProfile!.points[1].elevationRelM, -3.2);
|
|
expect(parsed.terrainProfile!.points[2].elevationRelM, isNull);
|
|
});
|
|
|
|
test('fehlt in der Datei, bleibt terrainProfile beim Import null', () {
|
|
final json = buildMissionExportJson(MissionExportData(
|
|
name: 'No terrain',
|
|
createdAt: DateTime.utc(2026, 1, 1),
|
|
waypoints: waypoints,
|
|
));
|
|
|
|
final parsed = parseMissionImportJson(json);
|
|
|
|
expect(parsed.terrainProfile, isNull);
|
|
});
|
|
});
|
|
|
|
group('missionExportFilename', () {
|
|
test('ersetzt Sonderzeichen durch Unterstriche', () {
|
|
expect(missionExportFilename('Sankt Pölten / Nord'),
|
|
'mission-Sankt_P_lten___Nord.json');
|
|
});
|
|
});
|
|
}
|