diet-guard/app/test/no_words_body_test.dart
Krzysztof kuhy Rudnicki 2dc502bbb6
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
Speak formula names, fit sheet value
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 18:11:23 +01:00

91 lines
2.8 KiB
Dart

// Guard: the Body screen, every tile sheet and the activity-method chooser
// paint no words (only numbers, unit symbols, MET and workout labels).
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'label_finders.dart';
import 'no_words_support.dart';
import 'screens/body_screen_support.dart';
/// Workout labels the PC published (content, see `seedPerson`), plus the
/// proper names of the BMI / ideal-weight / BMR formulas that label their
/// figures (DOUBT rows in keep.md: kept from the first pilot, outside the
/// activity sheet). Activity formulas (ACSM, Per-km) are NOT here: that sheet
/// and its chooser show glyphs only.
const Set<String> _workouts = {
'Evening run',
'StrongLifts A',
'Harris-Benedict (revised 1984)',
'Peterson (BMI 22)',
'Mifflin-St Jeor',
'Katch-McArdle',
'Cunningham',
'BMI Prime',
'Trefethen',
'Devine',
'Robinson',
'Miller',
};
void main() {
late MemoryDocStore store;
setUp(() async {
store = MemoryDocStore();
await setUpBodyServices(store);
});
tearDown(tearDownBodyServices);
test('the checker flags an injected word (canary)', () {
expect(wordsIn('70.0 kg'), isEmpty);
expect(wordsIn('265 MET'), isEmpty);
expect(wordsIn('Measured (ACSM)'), isNotEmpty);
expect(wordsIn('Evening run 4 km', content: _workouts), ['km']);
expect(wordsIn('Evening run', content: _workouts), isEmpty);
});
testWidgets('canary: a painted word fails the guard', (tester) async {
await tester.pumpWidget(const MaterialApp(home: Text('Activity')));
expect(() => expectNoWords(tester), throwsA(isA<TestFailure>()));
});
for (final seeded in [false, true]) {
testWidgets('body tiles and sheets paint no words (seeded: $seeded)', (
tester,
) async {
if (seeded) await seedPerson(store);
await pumpBody(tester);
final found = wordyStrings(
tester,
content: _workouts,
minStrings: 5,
where: 'tiles',
);
for (final title in tileTitles(tester)) {
await openTile(tester, title);
found.addAll(wordyStrings(tester, content: _workouts, where: title));
await closeSheet(tester);
}
expect(found, isEmpty);
});
}
testWidgets('the activity-method chooser paints no words', (tester) async {
await seedPerson(store);
await pumpBody(tester);
await openTile(tester, 'Daily calorie target');
await tester.tap(bySemLabel('Moderate').first);
await tester.pumpAndSettle();
expectNoWords(
tester,
content: _workouts,
minStrings: 8,
where: 'activity chooser',
);
await tester.tap(bySemLabel('Measured (ACSM)').last);
await tester.pumpAndSettle();
expectNoWords(tester, content: _workouts, where: 'measured goal');
});
}