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

85 lines
2.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:diet_guard_app/models/food_bank_record.dart';
import 'package:diet_guard_app/widgets/food_bank/fb_tile_grid.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_test/flutter_test.dart';
List<FoodBankRecord> _foods(int n, {double count = 0}) => [
for (var i = 0; i < n; i++)
FoodBankRecord(
desc: 'Food $i',
kcal: 100,
proteinG: 1,
carbsG: 2,
fatG: 3,
grams: 100,
count: count,
),
];
Future<void> _pump(
WidgetTester tester,
List<FoodBankRecord> records, {
ValueChanged<FoodBankRecord>? onOpen,
}) => tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: FbTileGrid(records: records, onOpen: onOpen ?? (_) {}),
),
),
);
void main() {
test('rows never drop below one, even in a tiny box', () {
expect(fbRowsFor(10), 1);
expect(fbRowsFor(600), greaterThan(3));
});
testWidgets('a short list is one page: partial row, no dots, no count', (
tester,
) async {
FoodBankRecord? opened;
await _pump(tester, _foods(4), onOpen: (r) => opened = r);
expect(find.text('Food 3'), findsOneWidget);
expect(find.textContaining('×'), findsNothing);
expect(find.byType(PageView), findsOneWidget);
await tester.tap(find.text('Food 3'));
expect(opened?.desc, 'Food 3');
});
testWidgets('used foods show their count', (tester) async {
await _pump(tester, _foods(2, count: 7));
expect(find.text('×7'), findsNWidgets(2));
});
testWidgets('many pages show a sliding window of dots', (tester) async {
await _pump(tester, _foods(400));
final dots = find.descendant(
of: find.byType(ExcludeSemantics),
matching: find.byType(Container),
);
expect(dots, findsNWidgets(7));
await tester.fling(find.byType(PageView), const Offset(-600, 0), 3000);
await tester.pumpAndSettle();
await tester.fling(find.byType(PageView), const Offset(-600, 0), 3000);
await tester.pumpAndSettle();
await tester.fling(find.byType(PageView), const Offset(-600, 0), 3000);
await tester.pumpAndSettle();
await tester.fling(find.byType(PageView), const Offset(-600, 0), 3000);
await tester.pumpAndSettle();
expect(dots, findsNWidgets(7));
});
testWidgets('shrinking the list while on a late page stays in range', (
tester,
) async {
await _pump(tester, _foods(400));
for (var i = 0; i < 3; i++) {
await tester.fling(find.byType(PageView), const Offset(-600, 0), 3000);
await tester.pumpAndSettle();
}
await _pump(tester, _foods(5));
await tester.pumpAndSettle();
expect(find.text('Food 0'), findsOneWidget);
});
}