diet-guard/app/test/services/app_settings_sound_test.dart
Krzysztof kuhy Rudnicki 97af520fdd
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
Add log sound cue and progress card motion
- lightImpact + 160 ms confirm cue on a validated log (audioplayers,
  no audio focus); device-local opt-out switch in Settings, on by default
- post-log card: confirmation line (slot + the meal's kcal), entrance and
  kcal/streak count-up on motion tokens transcribed into ui/theme.dart;
  durations collapse to zero under disableAnimations
- test/flutter_test_config.dart mutes the cue suite-wide

Todo: 8e66c1b9
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWVHMLzeojNP4AaPoEj
2026-11-02 21:12:46 +01:00

66 lines
2.1 KiB
Dart

import 'dart:io';
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:flutter_test/flutter_test.dart';
void main() {
late Directory dir;
setUp(() async {
dir = await Directory.systemTemp.createTemp('diet_guard_sound_');
BudgetHistoryService.resetForTesting(store: FileDocumentStore(dir));
});
tearDown(() async {
AppSettingsService.resetForTesting();
BudgetHistoryService.resetForTesting();
await dir.delete(recursive: true);
});
Future<AppSettingsService> reload() {
AppSettingsService.resetForTesting();
return AppSettingsService.initForTesting(FileDocumentStore(dir));
}
test('sound on log ships on, even uninitialised', () async {
AppSettingsService.resetForTesting();
expect(AppSettingsService.soundOnLog, isTrue);
await reload();
expect(AppSettingsService.soundOnLog, isTrue);
});
test('turning it off survives a restart', () async {
final svc = await reload();
await svc.setSoundOnLog(on: false);
await reload();
expect(AppSettingsService.soundOnLog, isFalse);
});
test('a kcal goal save keeps the sound setting', () async {
final svc = await reload();
await svc.setSoundOnLog(on: false);
await svc.saveDailyKcalGoal(1900);
await reload();
expect(AppSettingsService.soundOnLog, isFalse);
expect(AppSettingsService.dailyKcalGoal, 1900);
});
test('toggling sound does not restamp the synced budget', () async {
final svc = await reload();
await svc.applySyncedBudget(2000, updatedAt: DateTime.utc(2026));
await svc.setSoundOnLog(on: false);
await reload();
expect(AppSettingsService.dailyKcalGoalUpdatedAt, DateTime.utc(2026));
});
test('a non-bool stored value falls back to on', () async {
await FileDocumentStore(
dir,
).write(AppSettingsService.documentName, '{"sound_on_log": "no"}');
await reload();
expect(AppSettingsService.soundOnLog, isTrue);
});
}