mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-11 13:07:40 +01:00
Three independent cleanups ahead of the configurable meal schedule.
Pills: the row was a `Wrap`, so pills dropped onto a second line as soon as
they outgrew the width -- which they do even at four. Measured: a logged chip
is ~124px at Material defaults, so four need 522px against ~330px of phone
width. Now a `FittedBox(scaleDown)` over a `Row`, which scales the row down
uniformly, plus compact chip density so there is less to scale away.
A `Row` of `Expanded` children was the obvious alternative and is wrong: it
imposes a tight width, and a Chip narrower than avatar+padding+label clips its
label rather than shrinking -- measured at 10px per label, about one character,
while throwing no overflow error. The new regression test therefore asserts
both a shared baseline and a legible label width; it was confirmed to fail on
the old `Wrap` ("chip wrapped to a second line at 320.0") rather than passing
vacuously.
Card: the `Logged "<meal>".` line restated the description the user had just
typed. Removed, along with `TodayProgress.justLogged`, which nothing else read.
The kcal position, macros and streak stay.
refactor_claude_todo.md: the 250-line file-splitting refactor it tracked is
done -- `scripts/check_file_length.sh --all` exits 0 and an independent sweep
finds nothing over the cap. DESIGN_AUDIT_TODO.md is a separate, still-open
effort and stays.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0159b4E5hh512jYUeaJVNxfM
94 lines
2.9 KiB
Dart
94 lines
2.9 KiB
Dart
import 'package:diet_guard_app/widgets/today_progress_card.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
TodayProgress _progress({
|
|
double consumedKcal = 1450,
|
|
int budgetKcal = 2200,
|
|
double proteinG = 90,
|
|
double carbsG = 120,
|
|
double fatG = 40,
|
|
int adherenceStreak = 3,
|
|
}) => TodayProgress(
|
|
consumedKcal: consumedKcal,
|
|
budgetKcal: budgetKcal,
|
|
proteinG: proteinG,
|
|
carbsG: carbsG,
|
|
fatG: fatG,
|
|
adherenceStreak: adherenceStreak,
|
|
);
|
|
|
|
Future<void> _pump(WidgetTester tester, TodayProgress progress) =>
|
|
tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(body: TodayProgressCard(progress: progress)),
|
|
),
|
|
);
|
|
|
|
void main() {
|
|
group('TodayProgress', () {
|
|
test('remaining is budget minus consumed', () {
|
|
expect(_progress().remainingKcal, 750);
|
|
expect(_progress().isOverBudget, isFalse);
|
|
});
|
|
|
|
test('remaining goes negative once past the budget', () {
|
|
final over = _progress(consumedKcal: 2500);
|
|
expect(over.remainingKcal, -300);
|
|
expect(over.isOverBudget, isTrue);
|
|
});
|
|
|
|
test('exactly on the budget is not over', () {
|
|
final exact = _progress(consumedKcal: 2200);
|
|
expect(exact.remainingKcal, 0);
|
|
expect(exact.isOverBudget, isFalse);
|
|
});
|
|
});
|
|
|
|
group('TodayProgressCard', () {
|
|
testWidgets('shows the kcal position and macros, but not the meal', (
|
|
tester,
|
|
) async {
|
|
await _pump(tester, _progress());
|
|
|
|
// The `Logged "<meal>".` line was removed 2026-08-16 -- it restated
|
|
// what the user had just typed. Pinned so it does not creep back.
|
|
expect(find.textContaining('Logged'), findsNothing);
|
|
expect(find.text('1450 / 2200'), findsOneWidget);
|
|
expect(find.text('750 left'), findsOneWidget);
|
|
expect(find.text('P 90g · C 120g · F 40g'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('reports the overshoot in the error color when over', (
|
|
tester,
|
|
) async {
|
|
await _pump(tester, _progress(consumedKcal: 2500));
|
|
|
|
expect(find.text('300 over'), findsOneWidget);
|
|
final total = tester.widget<Text>(find.text('2500 / 2200'));
|
|
final context = tester.element(find.text('2500 / 2200'));
|
|
expect(total.style?.color, Theme.of(context).colorScheme.error);
|
|
});
|
|
|
|
testWidgets('pluralises the adherence streak', (tester) async {
|
|
await _pump(tester, _progress(adherenceStreak: 1));
|
|
expect(find.text('Adherence streak: 1 day'), findsOneWidget);
|
|
|
|
await _pump(tester, _progress(adherenceStreak: 12));
|
|
expect(find.text('Adherence streak: 12 days'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('rounds fractional kcal and macros for display', (
|
|
tester,
|
|
) async {
|
|
await _pump(
|
|
tester,
|
|
_progress(consumedKcal: 1450.6, proteinG: 90.4, carbsG: 0, fatG: 0),
|
|
);
|
|
|
|
expect(find.text('1451 / 2200'), findsOneWidget);
|
|
expect(find.text('P 90g · C 0g · F 0g'), findsOneWidget);
|
|
});
|
|
});
|
|
}
|