mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-10 19:27:14 +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
Fires on the tap before the write; rejected logs stay silent. The dopamine-ux TODO now lists only the remaining work. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWVUTaKFW8m7YrvWbzV
80 lines
3.0 KiB
Dart
80 lines
3.0 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:diet_guard_app/models/meal_schedule.dart';
|
|
import 'package:diet_guard_app/screens/log_meal_screen.dart';
|
|
import 'package:diet_guard_app/services/app_settings_service.dart';
|
|
import 'package:diet_guard_app/services/budget_history_service.dart';
|
|
import 'package:diet_guard_app/services/document_store_io.dart';
|
|
import 'package:diet_guard_app/services/foodbank_service.dart';
|
|
import 'package:diet_guard_app/services/log_storage_service.dart';
|
|
import 'package:diet_guard_app/services/meal_schedule_service.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
late Directory dir;
|
|
final haptics = <String>[];
|
|
|
|
setUp(() async {
|
|
haptics.clear();
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(SystemChannels.platform, (call) async {
|
|
if (call.method == 'HapticFeedback.vibrate') {
|
|
haptics.add(call.arguments as String);
|
|
}
|
|
return null;
|
|
});
|
|
dir = await Directory.systemTemp.createTemp('diet_guard_haptic_');
|
|
LogStorageService.resetForTesting(store: FileDocumentStore(dir));
|
|
FoodBankService.resetForTesting(store: FileDocumentStore(dir));
|
|
AppSettingsService.resetForTesting(store: FileDocumentStore(dir));
|
|
BudgetHistoryService.resetForTesting(store: FileDocumentStore(dir));
|
|
await MealScheduleService.initForTesting(FileDocumentStore(dir));
|
|
});
|
|
|
|
tearDown(() async {
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(SystemChannels.platform, null);
|
|
LogStorageService.resetForTesting();
|
|
FoodBankService.resetForTesting();
|
|
AppSettingsService.resetForTesting();
|
|
BudgetHistoryService.resetForTesting();
|
|
MealScheduleService.resetForTesting();
|
|
await dir.delete(recursive: true);
|
|
});
|
|
|
|
Future<void> settle(WidgetTester tester) async {
|
|
await Future<void>.delayed(const Duration(milliseconds: 200));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
testWidgets('logging a meal buzzes once, on the tap', (tester) async {
|
|
await tester.runAsync(() async {
|
|
await tester.pumpWidget(const MaterialApp(home: LogMealScreen()));
|
|
await settle(tester);
|
|
await tester.enterText(find.byType(TextField).at(0), 'toast');
|
|
await settle(tester);
|
|
await tester.tap(find.byTooltip('Log meal'));
|
|
// One frame, no I/O wait: the haptic must not wait for the write.
|
|
await tester.pump();
|
|
expect(haptics, ['HapticFeedbackType.mediumImpact']);
|
|
await settle(tester);
|
|
expect(haptics, hasLength(1));
|
|
});
|
|
});
|
|
|
|
testWidgets('a rejected log (empty description) does not buzz', (
|
|
tester,
|
|
) async {
|
|
await tester.runAsync(() async {
|
|
await tester.pumpWidget(const MaterialApp(home: LogMealScreen()));
|
|
await settle(tester);
|
|
await tester.tap(find.byTooltip('Log meal'));
|
|
await settle(tester);
|
|
expect(find.text('Type what you ate first.'), findsOneWidget);
|
|
expect(haptics, isEmpty);
|
|
});
|
|
});
|
|
}
|