mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-19 13:54:31 +01:00
The Log Meal tab did not fit this laptop, and had not for some time. Measured
under a real 1366x768 X server: it required 866px inside a 739px content pane
with every field EMPTY, and 938px with a day of meals logged.
Because the content frame was place()-centred it was sheared at BOTH edges at
once -- the "Diet Gate" title and the slot header (which meal you are being
asked to log) off the top, the calorie headline and the whole dashboard off the
bottom -- with no scrollbar anywhere in the package and nothing to indicate
content was missing. This is a hard lock: overrideredirect, a global grab, VT
switching disabled. Unreachable content is unrecoverable.
Two independent causes, both needed fixing:
- Every font size was handed to Tk as *points*. Tk encodes the unit in the
SIGN of the size, and _gatelock_typography carried a comment asserting the
opposite ("Tk has no separate px/pt distinction"). At ~100 DPI that made
every string ~30% oversized. Negative sizes now; the docstring records why.
- There was no scroll container. build_layout now uses gatelock's
ScrollableSurface, which top-anchors, scrolls by keyboard, and scrolls to
follow focus.
Font sizes alone were not enough: they take the layout to 702px, still over the
571px pane at 1024x600. Both fixes are load-bearing.
The grams/items selector was mouse-only. tk.OptionMenu's Menubutton defaults to
takefocus=0, so ::tk::FocusOK rejects it and it never entered the tab ring --
verified by walking the real ring, which ran Entry -> Text -> Listbox -> Button
-> TNotebook and skipped it entirely. Switching units rescales the whole entry,
so a pointerless user could not correct "250 grams" to "3 items" inside a lock
they cannot leave without logging a meal. It is now two Radiobuttons, which are
in the ring by default and take both Space and Return -- and which post nothing,
unlike a menu, whose grab-stealing is why screen-locker bans OptionMenu on lock
surfaces outright.
Also: the focus ring was invisible (Tk's default is 1px BLACK on #211D1B) and
_build_desc actively inverted it by setting highlightbackground, the UNfocused
ring, so the box outlined while idle and went black the moment it took focus.
Enter now activates buttons (X11 Tk binds only <space>). Text widgets no longer
trap Tab. notebook.enable_traversal() is called, so Ctrl+Tab and Ctrl+PageDown
work. wraplength drops 900 -> 640, the line-length cap, which also stops a
label forcing a 900px-wide layout onto a 1024px screen.
The Flutter app had two controls with no keyboard route at all. Its desktop
target is the web build in a Chrome --app window, so a touch gesture is not a
fallback there, it is the only interaction:
- Deleting a history entry was bound solely to onLongPress. Long-press has no
keyboard equivalent whatsoever. It now has a focusable IconButton; the
long-press stays as a redundant pointer shortcut.
- Calendar day cells were a bare GestureDetector, so navigating to
date-filtered history was pointer-only and invisible to a screen reader.
Now Semantics(button: true) over an InkWell.
Plus: the filter sheet built a TextEditingController inside build() with the
caret forced to end-of-text, so every keystroke discarded it and silently undid
mid-string Home/End/arrow editing. And nothing capped width, so on the 1366px
desktop window prose ran ~180 characters per line (twice the readable limit)
and a four-digit kcal field spanned ~1334px. AppWidth adds those caps.
Tests: the render check is a failing test, not a script -- ruff runs with
--unsafe-fixes, whose T201 fix DELETES print statements, which would silently
turn a diagnostic into a no-op. test_gate_layout_fits.py was verified red on
the pre-fix code ("content 866 in viewport 768 -> NO SCROLL VIEWPORT ->
UNREACHABLE CONTENT") and green after. The Flutter suite gains its first
keyboard-reachability assertions; it previously had ~109 tester.tap calls and
zero checks that anything was focusable.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
231 lines
8.0 KiB
Dart
231 lines
8.0 KiB
Dart
/// Pointer-free operability tests for controls that had no keyboard route.
|
|
///
|
|
/// The desktop build is this Dart running as Flutter **web** in a Chrome
|
|
/// `--app` window, so "mobile-only" gestures are not a fallback there — they
|
|
/// are the whole interaction. Each test below stands in for something that was
|
|
/// literally impossible without a pointer.
|
|
///
|
|
/// These are also the repo's first keyboard-reachability assertions: before
|
|
/// this file, `test/` had ~109 `tester.tap` calls and zero checks that anything
|
|
/// was focusable at all.
|
|
library;
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:diet_guard_app/models/food_entry.dart';
|
|
import 'package:diet_guard_app/screens/history_screen.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/log_storage_service.dart';
|
|
import 'package:diet_guard_app/ui/theme.dart';
|
|
import 'package:diet_guard_app/widgets/day_status_calendar.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/semantics.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
/// Landscape and *short* — the supported floor. Phone-portrait sizes, which is
|
|
/// all the existing suite pinned, exercise neither constraint.
|
|
const _desktopSize = Size(1366, 768);
|
|
|
|
void main() {
|
|
group('calendar day cells', () {
|
|
testWidgets('are focusable, so date navigation has a keyboard route', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: DayStatusCalendar(
|
|
statusByDate: const {},
|
|
month: DateTime(2026, 7),
|
|
today: DateTime(2026, 7, 30),
|
|
onPrevMonth: _noop,
|
|
onNextMonth: _noop,
|
|
onDaySelected: (_) {},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
// A bare GestureDetector — what this replaced — builds no InkWell and no
|
|
// focus node, so no day was reachable by Tab and the whole
|
|
// date-filtered-history route was pointer-only.
|
|
expect(
|
|
find.byType(InkWell),
|
|
findsWidgets,
|
|
reason: 'day cells must be focusable, not bare GestureDetectors',
|
|
);
|
|
});
|
|
|
|
testWidgets('expose a button semantic for screen readers', (tester) async {
|
|
final handle = tester.ensureSemantics();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: DayStatusCalendar(
|
|
statusByDate: const {},
|
|
month: DateTime(2026, 7),
|
|
today: DateTime(2026, 7, 30),
|
|
onPrevMonth: _noop,
|
|
onNextMonth: _noop,
|
|
onDaySelected: (_) {},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
final node = tester.getSemantics(find.byType(InkWell).first);
|
|
expect(node.hasFlag(SemanticsFlag.isButton), isTrue);
|
|
// Disposed inline, not via addTearDown: Flutter verifies outstanding
|
|
// handles at the end of the test body, before tearDowns run.
|
|
handle.dispose();
|
|
});
|
|
|
|
testWidgets('gain a tab stop per day only when selection is enabled', (
|
|
tester,
|
|
) async {
|
|
// Counts InkWells rather than matching a semantics label: the day cells
|
|
// merge their own label with the day-number Text inside them, so a label
|
|
// finder is brittle. The month-navigation chevrons are IconButtons and
|
|
// contribute a constant number of InkWells in both cases, so the
|
|
// *difference* is exactly the per-day tab stops -- which is the property
|
|
// under test.
|
|
Future<int> inkWells({required bool selectable}) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: DayStatusCalendar(
|
|
statusByDate: const {},
|
|
month: DateTime(2026, 7),
|
|
today: DateTime(2026, 7, 30),
|
|
onPrevMonth: _noop,
|
|
onNextMonth: _noop,
|
|
onDaySelected: selectable ? (_) {} : null,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
return tester.widgetList(find.byType(InkWell)).length;
|
|
}
|
|
|
|
final readOnlyCount = await inkWells(selectable: false);
|
|
final selectableCount = await inkWells(selectable: true);
|
|
|
|
// July 2026 has 31 days. Before the fix this difference was zero: the
|
|
// cells were bare GestureDetectors, so no day was ever a tab stop.
|
|
expect(selectableCount - readOnlyCount, 31);
|
|
});
|
|
});
|
|
|
|
group('width caps', () {
|
|
test('prose cap matches the design-system line-length rule', () {
|
|
// tokens.md rule 21: 40rem / ~65-70 characters. Without this the desktop
|
|
// window rendered prose at roughly 180 characters per line.
|
|
expect(AppWidth.prose, 640);
|
|
});
|
|
|
|
test('a single-purpose field is capped well below the prose width', () {
|
|
expect(AppWidth.field, lessThan(AppWidth.prose));
|
|
});
|
|
|
|
test('the short-viewport breakpoint trips before the 768px floor', () {
|
|
expect(AppWidth.shortViewport, lessThan(768));
|
|
});
|
|
});
|
|
|
|
group('history entry delete', () {
|
|
late Directory tempDir;
|
|
|
|
setUp(() async {
|
|
tempDir = await Directory.systemTemp.createTemp('diet_guard_kbd_');
|
|
LogStorageService.resetForTesting(store: FileDocumentStore(tempDir));
|
|
BudgetHistoryService.resetForTesting(store: FileDocumentStore(tempDir));
|
|
});
|
|
|
|
tearDown(() async {
|
|
LogStorageService.resetForTesting();
|
|
BudgetHistoryService.resetForTesting();
|
|
await tempDir.delete(recursive: true);
|
|
});
|
|
|
|
testWidgets('has a focusable control, not long-press only', (tester) async {
|
|
tester.view.physicalSize = _desktopSize;
|
|
tester.view.devicePixelRatio = 1.0;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
|
|
await LogStorageService.instance.writeLog({
|
|
'2026-07-30': [
|
|
const FoodEntry(
|
|
id: 'has-id',
|
|
time: '2026-07-30T08:00:00+02:00',
|
|
desc: 'oatmeal with raisins',
|
|
grams: 100,
|
|
kcal: 430,
|
|
proteinG: 12,
|
|
carbsG: 60,
|
|
fatG: 9,
|
|
source: 'food bank',
|
|
),
|
|
],
|
|
});
|
|
|
|
// HistoryScreen loads via a fire-and-forget Future in initState that the
|
|
// frame scheduler does not track, so settle inside runAsync.
|
|
await tester.runAsync(() async {
|
|
await tester.pumpWidget(const MaterialApp(home: HistoryScreen()));
|
|
await Future<void>.delayed(const Duration(milliseconds: 50));
|
|
await tester.pumpAndSettle();
|
|
});
|
|
|
|
// Delete used to be bound only to onLongPress, which has no keyboard
|
|
// equivalent whatsoever.
|
|
expect(
|
|
find.byTooltip('Delete entry'),
|
|
findsOneWidget,
|
|
reason: 'delete needs a tab-reachable control, not long-press only',
|
|
);
|
|
});
|
|
|
|
testWidgets('offers no delete control for an entry without an id', (
|
|
tester,
|
|
) async {
|
|
tester.view.physicalSize = _desktopSize;
|
|
tester.view.devicePixelRatio = 1.0;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
|
|
await LogStorageService.instance.writeLog({
|
|
'2026-07-30': [
|
|
const FoodEntry(
|
|
time: '2026-07-30T09:00:00+02:00',
|
|
desc: 'legacy entry',
|
|
grams: 100,
|
|
kcal: 100,
|
|
proteinG: 1,
|
|
carbsG: 2,
|
|
fatG: 3,
|
|
source: 'legacy',
|
|
),
|
|
],
|
|
});
|
|
|
|
await tester.runAsync(() async {
|
|
await tester.pumpWidget(const MaterialApp(home: HistoryScreen()));
|
|
await Future<void>.delayed(const Duration(milliseconds: 50));
|
|
await tester.pumpAndSettle();
|
|
});
|
|
|
|
// Delete stays id-only to avoid ambiguous time+desc matches, so the
|
|
// control must be absent rather than present-and-failing.
|
|
expect(find.byTooltip('Delete entry'), findsNothing);
|
|
});
|
|
});
|
|
}
|
|
|
|
/// A do-nothing month-navigation callback.
|
|
void _noop() {}
|