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>
154 lines
4.8 KiB
Dart
154 lines
4.8 KiB
Dart
import 'package:drift/native.dart';
|
|
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/database/app_database.dart';
|
|
import 'package:dmc_app/services/database/mission_repository.dart';
|
|
|
|
void main() {
|
|
late AppDatabase db;
|
|
late MissionRepository repository;
|
|
|
|
setUp(() {
|
|
db = AppDatabase.forTesting(NativeDatabase.memory());
|
|
repository = MissionRepository(db);
|
|
});
|
|
|
|
tearDown(() => db.close());
|
|
|
|
const waypoints = [
|
|
Waypoint(lat: 52.0, lon: 4.0, altitudeM: 60, speedMs: 15, catchRadiusM: 60),
|
|
Waypoint(
|
|
lat: 52.01,
|
|
lon: 4.01,
|
|
altitudeM: 80,
|
|
speedMs: 18,
|
|
catchRadiusM: 60,
|
|
action: WaypointAction.loiter,
|
|
),
|
|
];
|
|
|
|
test('upsert ohne id legt eine neue Mission an', () async {
|
|
final id = await repository.upsert(
|
|
name: 'Amsterdam',
|
|
placeName: 'Amsterdam',
|
|
waypoints: waypoints,
|
|
);
|
|
|
|
final loaded = await repository.load(id);
|
|
expect(loaded, isNotNull);
|
|
expect(loaded!.name, 'Amsterdam');
|
|
expect(loaded.placeName, 'Amsterdam');
|
|
expect(loaded.waypoints, hasLength(2));
|
|
expect(loaded.waypoints[1].action, WaypointAction.loiter);
|
|
expect(loaded.waypoints[1].speedMs, 18);
|
|
});
|
|
|
|
test('upsert mit bestehender id ueberschreibt statt zu duplizieren', () async {
|
|
final id = await repository.upsert(name: 'Draft', waypoints: waypoints);
|
|
|
|
await repository.upsert(
|
|
id: id,
|
|
name: 'Draft',
|
|
waypoints: [waypoints.first],
|
|
);
|
|
|
|
final summaries = await repository.watchSummaries().first;
|
|
expect(summaries, hasLength(1));
|
|
expect(summaries.single.waypointCount, 1);
|
|
});
|
|
|
|
test('rename aendert nur den Namen, nicht die Wegpunkte', () async {
|
|
final id = await repository.upsert(name: 'Old name', waypoints: waypoints);
|
|
|
|
await repository.rename(id, 'New name');
|
|
|
|
final loaded = await repository.load(id);
|
|
expect(loaded!.name, 'New name');
|
|
expect(loaded.waypoints, hasLength(2));
|
|
});
|
|
|
|
test('delete entfernt die Mission aus der Liste', () async {
|
|
final id = await repository.upsert(name: 'To delete', waypoints: waypoints);
|
|
|
|
await repository.delete(id);
|
|
|
|
final loaded = await repository.load(id);
|
|
expect(loaded, isNull);
|
|
expect(await repository.watchSummaries().first, isEmpty);
|
|
});
|
|
|
|
test('load fuer unbekannte id liefert null', () async {
|
|
expect(await repository.load(999), isNull);
|
|
});
|
|
|
|
test('Windfelder werden mitgespeichert und wiederhergestellt', () async {
|
|
const withWind = Waypoint(
|
|
lat: 52.0,
|
|
lon: 4.0,
|
|
altitudeM: 60,
|
|
speedMs: 15,
|
|
catchRadiusM: 60,
|
|
windSpeedMs: 5.5,
|
|
windDirFromDeg: 210,
|
|
windElevationM: 2,
|
|
);
|
|
final id = await repository.upsert(name: 'Windy', waypoints: [withWind]);
|
|
|
|
final loaded = await repository.load(id);
|
|
|
|
expect(loaded!.waypoints.single.windSpeedMs, 5.5);
|
|
expect(loaded.waypoints.single.windDirFromDeg, 210);
|
|
expect(loaded.waypoints.single.windElevationM, 2);
|
|
});
|
|
|
|
group('Bodenhoehenprofil', () {
|
|
const profile = TerrainProfile(
|
|
routeKey: '52.00000,4.00000|52.01000,4.01000',
|
|
points: [
|
|
TerrainSamplePoint(distanceM: 0, elevationRelM: 0),
|
|
TerrainSamplePoint(distanceM: 30, elevationRelM: 2.5),
|
|
TerrainSamplePoint(distanceM: 60, elevationRelM: null),
|
|
],
|
|
);
|
|
|
|
test('frisch angelegte Mission hat noch kein Profil', () async {
|
|
final id = await repository.upsert(name: 'No terrain', waypoints: waypoints);
|
|
|
|
final loaded = await repository.load(id);
|
|
|
|
expect(loaded!.terrainProfile, isNull);
|
|
});
|
|
|
|
test('saveTerrainProfile persistiert das Profil, load() gibt es zurueck', () async {
|
|
final id = await repository.upsert(name: 'With terrain', waypoints: waypoints);
|
|
|
|
await repository.saveTerrainProfile(id, profile);
|
|
final loaded = await repository.load(id);
|
|
|
|
expect(loaded!.terrainProfile, isNotNull);
|
|
expect(loaded.terrainProfile!.routeKey, profile.routeKey);
|
|
expect(loaded.terrainProfile!.points, hasLength(3));
|
|
expect(loaded.terrainProfile!.points[1].elevationRelM, 2.5);
|
|
expect(loaded.terrainProfile!.points[2].elevationRelM, isNull);
|
|
});
|
|
|
|
test('ein gewoehnlicher upsert (Wegpunkt-Autosave) loescht ein bereits '
|
|
'gespeichertes Profil nicht', () async {
|
|
final id = await repository.upsert(name: 'Autosave', waypoints: waypoints);
|
|
await repository.saveTerrainProfile(id, profile);
|
|
|
|
await repository.upsert(
|
|
id: id,
|
|
name: 'Autosave',
|
|
waypoints: [waypoints.first],
|
|
);
|
|
|
|
final loaded = await repository.load(id);
|
|
expect(loaded!.terrainProfile, isNotNull);
|
|
expect(loaded.terrainProfile!.routeKey, profile.routeKey);
|
|
});
|
|
});
|
|
}
|