Files
dmc/app/test/ui/providers/mission_meta_provider_test.dart
T
Constantin LeueandClaude Sonnet 5 b68c16d8e6 Log mission name on send, log mission/drone-profile changes, auto-send on mission switch
Include the mission name in the "Mission sent"/"Mission upload failed"
System Messages (was just the waypoint count before).

Add MissionMeta.switchSeq, bumped only by an actual mission switch
(startNew/startNewFromPlace/loadMission) - not by the id a brand-new
mission gets from its first autosave, and not by restoreLastSession() on
app start. FlyScreen compares it to detect a genuine switch and reacts
two ways: logs "Mission changed to ..." and automatically re-uploads the
new route to the flight controller, reusing the same send path as the
manual send button (same _sending guard, same success/failure snackbar
and log entry).

Mission-change and drone-profile-change logging intentionally live in
FlyScreen's ref.listen callbacks, not in mission_meta_provider.dart /
active_drone_profile_provider.dart themselves - those providers have no
notion of the app mode (Plan vs Fly, tracked separately by AppModeCubit),
and logging there would record a change regardless of mode. Since
FlyScreen only exists while Fly mode is active, scoping the listeners
there means switching missions or drone profiles from Plan mode produces
no System Messages entries, and only a mission switch (not a drone
profile switch) triggers the automatic re-upload, matching what was
asked for.

Also splits systemMessageLogProvider (the plain message list + log(), no
telemetry dependency) from the new systemMessageAutoLogProvider (the
Connected/lost/battery/failsafe/connection-type auto-detection, which
does watch telemetryProvider) - discovered while wiring the mission-change
logging that logging a plain message from Plan-mode code was forcing the
entire telemetry/transport stack to spin up as a side effect, which broke
an unrelated Plan-mode test (UdpTransport threw on a double-disconnect
during teardown). Keeping the two concerns apart means calling log() for
a one-off message never has that side effect.

Verified end to end on the Pixel_10a emulator: switching to an empty
mission while in Fly mode correctly showed "No waypoints to send" and
logged "Mission changed to ..." automatically, without touching the send
button.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-06 12:04:35 +02:00

64 lines
2.9 KiB
Dart

import 'package:drift/native.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:dmc_app/domain/waypoint/flat_waypoint_list.dart';
import 'package:dmc_app/services/database/app_database.dart';
import 'package:dmc_app/ui/providers/current_mission_provider.dart';
import 'package:dmc_app/ui/providers/database_provider.dart';
import 'package:dmc_app/ui/providers/mission_meta_provider.dart';
ProviderContainer _container() => ProviderContainer(overrides: [
appDatabaseProvider
.overrideWithValue(AppDatabase.forTesting(NativeDatabase.memory())),
]);
/// MissionMeta.switchSeq ist das Signal, mit dem FlyScreen einen echten
/// Missionswechsel erkennt (System-Messages-Log + automatischer Upload,
/// beides bewusst nur im Fly-Modus - siehe FlyScreen-Doku). Das Loggen
/// selbst passiert dort, nicht hier: dieser Provider kennt den App-Modus
/// nicht und darf deshalb ausserhalb des Fly-Modus (z.B. beim Planen) nicht
/// unbedingt in den System-Messages-Log schreiben oder gar telemetryProvider
/// mit hochziehen.
void main() {
test('startNewFromPlace() erhoeht switchSeq', () async {
final container = _container();
addTearDown(container.dispose);
await container.read(currentMissionMetaProvider.notifier).startNewFromPlace('Rotterdam');
expect(container.read(currentMissionMetaProvider).switchSeq, 1);
expect(container.read(currentMissionMetaProvider).name, 'Rotterdam');
});
// loadMission() ruft zusaetzlich _fitMapToWaypoints() auf, das eine
// tatsaechlich gerenderte FlutterMap braucht (MapController.fitCamera) -
// in einem reinen Notifier-Test ohne Widget-Baum nicht moeglich. Wird
// stattdessen vom widget_test.dart-Test "Missionswechsel im Fly-Modus
// sendet die neue Route automatisch an den Flightcontroller" abgedeckt,
// der loadMission() innerhalb einer echten AppShell/MissionMap aufruft.
test(
'der erste Autosave einer neuen Mission erhoeht switchSeq NICHT '
'(id-Vergabe durch Autosave ist kein Wechsel)',
() async {
final container = _container();
addTearDown(container.dispose);
await container.read(currentMissionMetaProvider.notifier).startNewFromPlace('Berlin');
final switchSeqAfterStart = container.read(currentMissionMetaProvider).switchSeq;
container.read(currentMissionProvider.notifier).addWaypoint(
const Waypoint(lat: 1, lon: 1, altitudeM: 60, speedMs: 15, catchRadiusM: 60),
);
// Autosave debounced ueber 800ms (Doku 7.5) - echt abwarten statt zu
// mocken, damit tatsaechlich der reale _flushNow()-Pfad getestet wird.
await Future<void>.delayed(const Duration(milliseconds: 900));
final meta = container.read(currentMissionMetaProvider);
expect(meta.id, isNotNull, reason: 'Autosave sollte trotzdem eine id vergeben haben');
expect(meta.switchSeq, switchSeqAfterStart);
},
timeout: const Timeout(Duration(seconds: 5)),
);
}