diet-guard/app/test/pickers/picker_call_sites_test.dart
Krzysztof kuhy Rudnicki 4eca59bac9
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint) (push) Waiting to run
Tests / test (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Icon-only date and time pickers
Replace showDatePicker, showDateRangePicker and showTimePicker with
numeral grid/wheel dialogs confirmed by check and close icons. Adds a
no-words picker guard and a repo invariant banning the framework pickers.

Todo: e09dac36

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 12:05:11 +01:00

74 lines
2.5 KiB
Dart

// The Body screen's two date controls apply what their picker confirms:
// the dated-value card's day, and the profile's birth date (whose picker
// opens with the year wheel focused).
import 'package:diet_guard_app/models/local_time.dart';
import 'package:diet_guard_app/widgets/body/dated_value_card.dart';
import 'package:diet_guard_app/widgets/body/profile_card.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import '../label_finders.dart';
import '../screens/body_screen_support.dart';
Future<void> _host(WidgetTester tester, Widget child) async {
tester.view.physicalSize = const Size(800, 1600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: child)));
await tester.pumpAndSettle();
}
Future<void> _pressAndSettle(
WidgetTester tester,
LogicalKeyboardKey key,
) async {
await tester.sendKeyEvent(key);
await tester.pumpAndSettle();
}
void main() {
testWidgets('the dated-value card shows the confirmed day', (tester) async {
await _host(
tester,
DatedValueCard(
semanticLabel: 'Weight',
fieldSemanticLabel: 'Weight (kg)',
icon: Icons.monitor_weight,
unit: 'kg',
min: 20,
max: 400,
latest: null,
series: const [],
onSave: (_, _) async {},
onDelete: (_) async {},
onChanged: () {},
),
);
final now = DateTime.now();
final yesterday = localDateKey(DateTime(now.year, now.month, now.day - 1));
await tester.tap(find.byIcon(Icons.event));
await tester.pumpAndSettle();
await _pressAndSettle(tester, LogicalKeyboardKey.arrowLeft);
await _pressAndSettle(tester, LogicalKeyboardKey.enter);
expect(find.byType(Dialog), findsNothing);
expect(find.text(' $yesterday'), findsOneWidget);
});
testWidgets('the birth date opens on the year wheel and applies', (
tester,
) async {
await setUpBodyServices(MemoryDocStore());
addTearDown(tearDownBodyServices);
await _host(tester, ProfileCard(onSaved: () {}));
final year = DateTime.now().year - 31;
await tester.tap(byIconLabel('Birth date'));
await tester.pumpAndSettle();
await _pressAndSettle(tester, LogicalKeyboardKey.arrowUp);
await _pressAndSettle(tester, LogicalKeyboardKey.enter);
expect(find.byType(Dialog), findsNothing);
expect(find.text(' $year-01-01'), findsOneWidget);
});
}