mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-20 20:52:23 +01:00
The chip was the only control that logged a meal against no slot at all (`slot: null`). Removing it leaves the row with just the four hour chips, so every logged meal now satisfies a real slot. Storage keeps its null-slot support on purpose. Entries already on disk and arriving over sync carry no `slot` key, and the `slot != null` filters in log_storage_service.loggedSlotsToday / _state.logged_slots_today are what stop them from retroactively satisfying meal slots -- so both are documented as load-bearing rather than deleted as dead code. Also corrects the MCP tool's docstring, which claimed its slot argument "may be None early in the day"; it falls back to slot_for_log, which clamps to a real hour and never returns None. Adds the widget test the chip row never had -- being untested is why the chip read as unused. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MPheLM86xUN9TGf34Ygtfz
91 lines
2.4 KiB
Dart
91 lines
2.4 KiB
Dart
import 'package:diet_guard_app/models/slot.dart';
|
|
import 'package:diet_guard_app/widgets/slot_selector_row.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
Future<void> _pump(
|
|
WidgetTester tester, {
|
|
required DateTime now,
|
|
Set<int> loggedSlots = const <int>{},
|
|
int? selectedSlot,
|
|
ValueChanged<int?>? onSlotSelected,
|
|
}) => tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: SlotSelectorRow(
|
|
now: now,
|
|
loggedSlots: loggedSlots,
|
|
selectedSlot: selectedSlot,
|
|
onSlotSelected: onSlotSelected ?? (_) {},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
void main() {
|
|
group('SlotSelectorRow', () {
|
|
testWidgets('renders exactly one chip per day slot', (tester) async {
|
|
await _pump(tester, now: DateTime(2026, 8, 14, 13));
|
|
|
|
expect(find.byType(ChoiceChip), findsNWidgets(daySlots().length));
|
|
for (final slot in daySlots()) {
|
|
expect(find.text(slotLabel(slot)), findsOneWidget);
|
|
}
|
|
});
|
|
|
|
// The "Snack" chip was removed on 2026-08-14; it was the only control
|
|
// that logged a meal against no slot at all.
|
|
testWidgets('has no Snack chip', (tester) async {
|
|
await _pump(tester, now: DateTime(2026, 8, 14, 13));
|
|
|
|
expect(find.text('Snack'), findsNothing);
|
|
expect(find.byIcon(Icons.fastfood), findsNothing);
|
|
});
|
|
|
|
testWidgets('tapping a chip reports that slot, never null', (
|
|
tester,
|
|
) async {
|
|
final selected = <int?>[];
|
|
await _pump(
|
|
tester,
|
|
now: DateTime(2026, 8, 14, 13),
|
|
onSlotSelected: selected.add,
|
|
);
|
|
|
|
for (final slot in daySlots()) {
|
|
await tester.tap(find.text(slotLabel(slot)));
|
|
}
|
|
|
|
expect(selected, daySlots());
|
|
expect(selected, isNot(contains(null)));
|
|
});
|
|
|
|
testWidgets('a logged slot gets a check avatar', (tester) async {
|
|
await _pump(
|
|
tester,
|
|
now: DateTime(2026, 8, 14, 13),
|
|
loggedSlots: {daySlots().first},
|
|
);
|
|
|
|
expect(find.byIcon(Icons.check), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('marks the selected slot', (tester) async {
|
|
final slot = daySlots().first;
|
|
await _pump(
|
|
tester,
|
|
now: DateTime(2026, 8, 14, 13),
|
|
selectedSlot: slot,
|
|
);
|
|
|
|
final chip = tester.widget<ChoiceChip>(
|
|
find.ancestor(
|
|
of: find.text(slotLabel(slot)),
|
|
matching: find.byType(ChoiceChip),
|
|
),
|
|
);
|
|
expect(chip.selected, isTrue);
|
|
});
|
|
});
|
|
}
|