mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-10 19:07:15 +01:00
app tests: off-hour schedule round trips + real settings wiring
Pins that fm/lm survive both the sync wire and a disk reload, and that a quarter-hour pick in SettingsScreen goes through the real _applySchedule. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015npsYVB2PdtWkG7MPAi4tn
This commit is contained in:
parent
f83938bfe3
commit
a9aa379a13
@ -2,7 +2,7 @@ name: diet_guard_app
|
||||
description: "Companion phone app for diet_guard: log meals on the go."
|
||||
publish_to: 'none'
|
||||
|
||||
version: 1.0.107+1
|
||||
version: 1.0.108+1
|
||||
|
||||
environment:
|
||||
sdk: ^3.12.2
|
||||
|
||||
@ -85,6 +85,23 @@ void main() {
|
||||
expect(find.text('Meals per day'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
testWidgets('picking a quarter-hour first meal saves the schedule', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.runAsync(() async {
|
||||
await tester.pumpWidget(const MaterialApp(home: SettingsScreen()));
|
||||
await settle(tester);
|
||||
|
||||
await tester.tap(find.widgetWithText(InputDecorator, 'First meal'));
|
||||
await settle(tester);
|
||||
await tester.tap(find.text('07:45').last);
|
||||
await settle(tester);
|
||||
|
||||
// Through the real _applySchedule: normalised, recorded, persisted.
|
||||
expect(MealScheduleService.current.firstMinute, 465);
|
||||
expect(find.text('07:45 · 11:45 · 16:00 · 20:00'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
testWidgets('reflects a five-meal schedule as the user\'s example', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@ -143,5 +143,22 @@ void main() {
|
||||
expect(decoded['v'], 1);
|
||||
expect((decoded['e']! as Map).keys, contains('2026-08-16'));
|
||||
});
|
||||
|
||||
test('an off-the-hour schedule survives a reload', () async {
|
||||
const offHour = MealSchedule(firstMinute: 443, lastMinute: 1155, count: 5);
|
||||
await MealScheduleService.initForTesting(store);
|
||||
await MealScheduleService.instance.recordChange(offHour);
|
||||
|
||||
MealScheduleService.resetForTesting();
|
||||
await MealScheduleService.initForTesting(store);
|
||||
|
||||
expect(MealScheduleService.current, offHour);
|
||||
final decoded =
|
||||
jsonDecode(store.documents[MealScheduleService.documentName]!)
|
||||
as Map<String, Object?>;
|
||||
final today = (decoded['e']! as Map).values.last as Map;
|
||||
expect(today['fm'], 443);
|
||||
expect(today['lm'], 1155);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -93,6 +93,20 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('an off-the-hour schedule round trips through the wire', () {
|
||||
// Dropping fm/lm on either side would silently snap 07:15 to 07:00.
|
||||
const offHour = MealSchedule(firstMinute: 435, lastMinute: 1140, count: 5);
|
||||
final entry = _entry('2026-08-16', offHour, '2026-08-16T10:00:00+02:00');
|
||||
expect(scheduleFields([entry]).values.single.$1, {
|
||||
'f': 7,
|
||||
'l': 19,
|
||||
'n': 5,
|
||||
'fm': 435,
|
||||
});
|
||||
final back = logToScheduleHistory(budgetToLog(_record, const [], [entry]));
|
||||
expect(back.single.schedule, offHour);
|
||||
});
|
||||
|
||||
test("normalizes a peer's out-of-range schedule", () {
|
||||
final log = budgetToLog(_record);
|
||||
final record = log[budgetRecordId]!;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user