mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-20 21:52:23 +01:00
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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
127 lines
4.1 KiB
Dart
127 lines
4.1 KiB
Dart
// Shared setup for the Body screen test files (split for the 250-line cap).
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:diet_guard_app/models/local_time.dart';
|
|
import 'package:diet_guard_app/screens/body_screen.dart';
|
|
import 'package:diet_guard_app/services/app_settings_service.dart';
|
|
import 'package:diet_guard_app/services/body_service.dart';
|
|
import 'package:diet_guard_app/services/log_storage_service.dart';
|
|
import 'package:diet_guard_app/widgets/body/body_tile_grid.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import '../label_finders.dart';
|
|
import '../services/body_test_support.dart';
|
|
|
|
export '../services/body_test_support.dart';
|
|
|
|
/// Points every service the screen reads at [store]; returns a teardown.
|
|
Future<void> setUpBodyServices(MemoryDocStore store) async {
|
|
LogStorageService.resetForTesting(store: store);
|
|
AppSettingsService.resetForTesting(store: store);
|
|
await BodyService.initForTesting(store);
|
|
}
|
|
|
|
/// Undoes [setUpBodyServices].
|
|
void tearDownBodyServices() {
|
|
BodyService.resetForTesting();
|
|
LogStorageService.resetForTesting();
|
|
AppSettingsService.resetForTesting();
|
|
}
|
|
|
|
/// Pumps the Body screen on a view tall enough to lay out every card.
|
|
Future<void> pumpBody(WidgetTester tester) async {
|
|
tester.view.physicalSize = const Size(1200, 12000);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
await tester.pumpWidget(const MaterialApp(home: BodyScreen()));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
/// Yesterday's local date key.
|
|
String yesterdayKey() =>
|
|
localDateKey(DateTime.now().subtract(const Duration(days: 1)));
|
|
|
|
/// An 80 kg, 180 cm, 30-year-old man with a run, a lift and 9000 steps
|
|
/// yesterday; optionally a saved [goal].
|
|
Future<void> seedPerson(MemoryDocStore store, {Object? goal}) async {
|
|
final today = DateTime.now();
|
|
const t = '2026-09-01T10:00:00+02:00';
|
|
store.documents[BodyService.documentName] = jsonEncode({
|
|
'profile': {
|
|
'birth': {'v': localDateKey(DateTime(today.year - 30, 1, 1)), 't': t},
|
|
'height_cm': {'v': 180, 't': t},
|
|
'sex': {'v': 'm', 't': t},
|
|
if (goal != null) 'goal': {'v': goal, 't': t},
|
|
},
|
|
'weights': {
|
|
'2026-09-20': {'kg': 81, 'src': 'phone', 't': '2026-09-20T07:00:00Z'},
|
|
yesterdayKey(): {'kg': 80, 'src': 'manual', 't': '2026-09-20T07:00:00Z'},
|
|
},
|
|
'steps': {
|
|
yesterdayKey(): {'n': 9000, 't': t},
|
|
},
|
|
'activity': {
|
|
't': t,
|
|
'sessions': [
|
|
{
|
|
'day': yesterdayKey(),
|
|
'kind': 'run',
|
|
'min': 60,
|
|
'km': 10,
|
|
'label': 'Running 10.0 km',
|
|
'src': 'runnerup',
|
|
},
|
|
{
|
|
'day': yesterdayKey(),
|
|
'kind': 'strength',
|
|
'min': 80,
|
|
'label': 'StrongLifts workout A (80 min, all succeeded)',
|
|
'src': 'screen-locker',
|
|
},
|
|
{
|
|
'day': yesterdayKey(),
|
|
'kind': 'walk',
|
|
'min': 30,
|
|
'km': 2,
|
|
'label': 'walk to the shop',
|
|
'src': 'manual',
|
|
},
|
|
],
|
|
},
|
|
});
|
|
await BodyService.initForTesting(store);
|
|
}
|
|
|
|
/// The top edge of [finder]'s first match.
|
|
double topOf(WidgetTester tester, Finder finder) =>
|
|
tester.getTopLeft(finder.first).dy;
|
|
|
|
/// The overview tile spoken as [title].
|
|
Finder tile(String title) =>
|
|
find.descendant(of: find.byType(BodyTileGrid), matching: bySemLabel(title));
|
|
|
|
/// Opens the sheet behind the tile spoken as [title].
|
|
Future<void> openTile(WidgetTester tester, String title) async {
|
|
await tester.tap(tile(title));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
/// Dismisses the open sheet by tapping its scrim.
|
|
Future<void> closeSheet(WidgetTester tester) async {
|
|
await tester.tapAt(const Offset(5, 5));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
/// [finder] restricted to the open sheet (the tiles stay mounted behind it).
|
|
Finder inSheet(Finder finder) =>
|
|
find.descendant(of: find.byType(BottomSheet), matching: finder);
|
|
|
|
/// Spoken names of the overview tiles, in display order.
|
|
List<String> tileTitles(WidgetTester tester) => tester
|
|
.widget<BodyTileGrid>(find.byType(BodyTileGrid))
|
|
.tiles
|
|
.map((t) => t.semanticLabel)
|
|
.toList();
|