diet-guard/app/test/screens/body_screen_goal_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

110 lines
3.8 KiB
Dart

import 'package:diet_guard_app/models/body_document.dart';
import 'package:diet_guard_app/services/body_energy.dart';
import 'package:diet_guard_app/services/body_prefs.dart';
import 'package:diet_guard_app/services/body_service.dart';
import 'package:diet_guard_app/ui/cues.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_test/flutter_test.dart';
import '../label_finders.dart';
import 'body_screen_support.dart';
void main() {
late MemoryDocStore store;
setUp(() async {
store = MemoryDocStore();
await setUpBodyServices(store);
});
tearDown(tearDownBodyServices);
testWidgets('each word of the goal is a picker, saved at once', (
tester,
) async {
await seedPerson(store);
await pumpBody(tester);
await openTile(tester, 'Daily calorie target');
// Each mark of the goal row is spoken as its value; so is its picker
// option, hence `.last` for the option (the row stays mounted behind).
Future<void> choose(String word, String option) async {
await tester.tap(bySemLabel(word).first);
await tester.pumpAndSettle();
await tester.tap(bySemLabel(option).last);
await tester.pumpAndSettle();
}
await choose('lose', 'gain');
await choose('kg', 'lb');
await choose('week', 'month');
await choose('Moderate', 'Measured (ACSM)');
await tester.tap(find.text('0.5'));
await tester.pumpAndSettle();
await tester.tap(find.widgetWithText(ChoiceChip, '1'));
await tester.pumpAndSettle();
expect(goalToJson(savedGoal(BodyService.instance)), {
'dir': 'gain',
'amt': 1.0,
'wu': 'lb',
'tu': 'month',
'act': 'measured:ACSM',
});
expect(
BodyService.instance.document.profile[profileBirth]!.t,
'2026-09-01T10:00:00+02:00',
);
// A typed amount; junk is refused and the dialog stays open.
final other = fieldByLabel('Other amount');
await tester.tap(find.text('1'));
await tester.pumpAndSettle();
await tester.enterText(other, '');
await tester.tap(byIconLabel('OK'));
await tester.pumpAndSettle();
expect(byIconLabel('OK'), findsOneWidget);
expect(cueOfKind(CueKind.error), findsOneWidget);
await tester.enterText(other, '2,5');
await tester.tap(byIconLabel('OK'));
await tester.pumpAndSettle();
expect(savedGoal(BodyService.instance).amount, 2.5);
// Cancel changes nothing; neither does dismissing a sheet.
await tester.tap(find.text('2.5'));
await tester.pumpAndSettle();
await tester.tap(byIconLabel('Cancel'));
await tester.pumpAndSettle();
await tester.tap(bySemLabel('gain').first);
await tester.pumpAndSettle();
await tester.tapAt(const Offset(5, 5));
await tester.pumpAndSettle();
expect(savedGoal(BodyService.instance).amount, 2.5);
await choose('gain', 'maintain');
expect(find.text('lb'), findsNothing);
});
testWidgets('measured without data, and a goal below the floor', (
tester,
) async {
final body = BodyService.instance;
await body.setProfile(birth: '1990-01-01', heightCm: 180, sex: 'm');
await body.setWeight('2026-09-20', 80);
await setGoal(body, const Goal('lose', 1, 'kg', 'week', 'measured:MET'));
await pumpBody(tester);
await openTile(tester, 'Daily calorie target');
expect(
cueLabelled('no workouts published yet (the PC publishes them).'),
findsOneWidget,
);
await tester.tap(bySemLabel('Measured (MET)').first);
await tester.pumpAndSettle();
await tester.tap(bySemLabel('Sedentary').last);
await tester.pumpAndSettle();
await tester.tap(find.text('1'));
await tester.pumpAndSettle();
await tester.enterText(fieldByLabel('Other amount'), '3');
await tester.tap(byIconLabel('OK'));
await tester.pumpAndSettle();
expect(cueLabelled('That is below the 1200 kcal floor.'), findsOneWidget);
});
}