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

109 lines
3.3 KiB
Dart

/// The log form's action row, and the delivery button the phone lacked.
///
/// The PC lock screen has had a "🍱 Today's delivery" button since the import
/// shipped; the phone had the queue but no visible control, so standing in
/// the kitchen there was nothing to tap. These tests pin the affordance and
/// the two ways it silently fails: a clipped label, and a dead control on the
/// web build.
library;
import 'package:diet_guard_app/widgets/log_meal_actions_row.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_test/flutter_test.dart';
import '../label_finders.dart';
void main() {
Future<void> pump(
WidgetTester tester, {
int queued = 0,
bool busy = false,
bool canFetch = true,
Future<void> Function()? onLoad,
VoidCallback? onLog,
double width = 360,
}) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SizedBox(
width: width,
child: LogMealActionsRow(
onLoadDelivery: onLoad ?? () async {},
onLog: onLog ?? () {},
deliveryBusy: busy,
dishesQueued: queued,
canFetchDelivery: canFetch,
),
),
),
),
);
}
testWidgets('the delivery button is there to tap', (tester) async {
var taps = 0;
await pump(tester, onLoad: () async => taps++);
await tester.tap(find.byIcon(Icons.restaurant));
await tester.pump();
expect(taps, 1);
});
testWidgets('the queue count is a numeral beside the icon', (tester) async {
await pump(tester, queued: 4);
expect(find.text('4'), findsOneWidget);
expect(byIconLabel("Load today's catering delivery"), findsOneWidget);
});
testWidgets('nothing queued shows no numeral and never overflows', (
tester,
) async {
await pump(tester, width: 300);
await tester.pumpAndSettle();
expect(find.text('0'), findsNothing);
expect(tester.takeException(), isNull);
});
testWidgets('a fetch in flight disables the button and spins', (
tester,
) async {
await pump(tester, busy: true);
final button = tester.widget<OutlinedButton>(find.byType(OutlinedButton));
expect(button.onPressed, isNull);
expect(find.byType(CircularProgressIndicator), findsOneWidget);
});
testWidgets('the button stays visible with nothing queued', (tester) async {
// Never hidden or disabled on an empty queue: the outcome arrives as a
// cue so a late delivery can still be retried.
await pump(tester);
expect(byIconLabel("Load today's catering delivery"), findsOneWidget);
final button = tester.widget<OutlinedButton>(find.byType(OutlinedButton));
expect(button.onPressed, isNotNull);
});
testWidgets('web gets no delivery button at all', (tester) async {
// The desktop target *is* the web build, and the caterer's panel blocks
// browser requests -- an unguarded button would ship a dead control.
await pump(tester, canFetch: false);
expect(find.byIcon(Icons.restaurant), findsNothing);
expect(find.byIcon(Icons.check_circle), findsOneWidget);
});
testWidgets('the log button still logs', (tester) async {
var logged = 0;
await pump(tester, onLog: () => logged++);
await tester.tap(find.byIcon(Icons.check_circle));
await tester.pump();
expect(logged, 1);
});
}