diet-guard/app/test/widgets/average_summary_row_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

65 lines
1.9 KiB
Dart

import 'package:diet_guard_app/models/period_average.dart';
import 'package:diet_guard_app/widgets/average_summary_row.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_test/flutter_test.dart';
import '../label_finders.dart';
PeriodAverage period({double? avgKcal, AverageBand? band}) => PeriodAverage(
start: '2026-01-05',
end: '2026-01-11',
loggedDays: 7,
elapsedDays: 7,
avgKcal: avgKcal,
avgBudget: 2000,
band: band,
);
Future<void> pump(WidgetTester tester, Widget child) =>
tester.pumpWidget(MaterialApp(home: Scaffold(body: child)));
void main() {
testWidgets('renders both averages and their bands', (tester) async {
await pump(
tester,
AverageSummaryRow(
week: period(avgKcal: 2100, band: AverageBand.slightlyOver),
month: period(avgKcal: 1900, band: AverageBand.under),
),
);
expect(find.text('2100'), findsOneWidget);
expect(find.text('1900'), findsOneWidget);
expect(byIconLabel('slightly over'), findsOneWidget);
expect(byIconLabel('under'), findsOneWidget);
});
testWidgets('rounds the average to whole kcal', (tester) async {
await pump(
tester,
AverageSummaryRow(
week: period(avgKcal: 2100.6, band: AverageBand.slightlyOver),
month: period(avgKcal: 1900, band: AverageBand.under),
),
);
expect(find.text('2101'), findsOneWidget);
});
testWidgets('an empty period shows the no-data glyph, never 0', (
tester,
) async {
await pump(tester, AverageSummaryRow(week: period(), month: period()));
expect(find.text('0'), findsNothing);
expect(byIconLabel('no data'), findsNWidgets(2));
});
testWidgets('the placeholder empty period renders safely', (tester) async {
await pump(
tester,
const AverageSummaryRow(
week: PeriodAverage.empty,
month: PeriodAverage.empty,
),
);
expect(byIconLabel('no data'), findsNWidgets(2));
});
}