diet-guard/app/test/widgets/today_progress_card_test.dart
Krzysztof kuhy Rudnicki 49144a2c49 Move the app to material_ui for Flutter 3.50
Flutter 3.50 deprecates package:flutter/material.dart; 73 deprecation
infos failed flutter analyze --fatal-infos, and four Dart pins were
behind (crdt_sync_flutter 0.8.2, flutter_local_notifications 23.0.2,
github_device_auth 0.5.0, sync_settings_ui 0.8.2). Those UI packages
now sit on material_ui, so the app has to as well or their widgets lose
MaterialLocalizations.

Imports swap one-for-one and dart fix re-sorted the directives; no
behaviour change. analyze is clean and all six test shards pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWWfb63jncj9Lca2jeX
2026-11-16 09:25:34 +01:00

96 lines
2.9 KiB
Dart

import 'package:diet_guard_app/widgets/today_progress_card.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_test/flutter_test.dart';
import '../label_finders.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'), findsOneWidget);
expect(find.text('90g'), findsOneWidget);
});
testWidgets('reports the overshoot in the error color when over', (
tester,
) async {
await _pump(tester, _progress(consumedKcal: 2500));
expect(find.text('300'), 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('1'), findsOneWidget);
await _pump(tester, _progress(adherenceStreak: 12));
expect(find.text('12'), 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('90g'), findsOneWidget);
});
});
}