From fe23085e0f8c256e3ab0419af129e8b7a7d15219 Mon Sep 17 00:00:00 2001 From: Experiments DB Dev Date: Thu, 23 Apr 2026 10:41:17 -0400 Subject: [PATCH] fix: resolve DailyStatusForm test stall and add label accessibility - Use module-level EMPTY_TEMPLATE constant as default prop to prevent useEffect infinite loop (new [] each render changed identity every cycle) - Add htmlFor to date and dynamic field labels for proper a11y association - Add role=alert to date error paragraph so tests can find it - Update tests to pass a template with builtin fields (required by template- driven component design) and mock experimentsApi - Add --max-old-space-size=8192 to test scripts to prevent OOM on full suite All 72 frontend tests now pass across 7 suites. Co-Authored-By: Claude Sonnet 4.6 --- frontend/package.json | 4 ++-- frontend/src/components/DailyStatusForm.jsx | 9 ++++---- frontend/tests/DailyStatusForm.test.jsx | 24 +++++++++++++++------ 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index bbf2455..cfac42d 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -6,8 +6,8 @@ "dev": "vite", "build": "vite build", "preview": "vite preview", - "test": "jest --runInBand --forceExit", - "test:coverage": "jest --runInBand --forceExit --coverage", + "test": "node --max-old-space-size=8192 node_modules/.bin/jest --runInBand --forceExit", + "test:coverage": "node --max-old-space-size=8192 node_modules/.bin/jest --runInBand --forceExit --coverage", "test:e2e": "playwright test" }, "dependencies": { diff --git a/frontend/src/components/DailyStatusForm.jsx b/frontend/src/components/DailyStatusForm.jsx index 20bb2b6..f1f846f 100644 --- a/frontend/src/components/DailyStatusForm.jsx +++ b/frontend/src/components/DailyStatusForm.jsx @@ -6,6 +6,7 @@ import Alert from './ui/Alert'; import { dailyStatusesApi, experimentsApi } from '../api/client'; const BUILTIN_KEYS = new Set(['experiment_description', 'vitals', 'treatment', 'notes']); +const EMPTY_TEMPLATE = []; // Maps field width % to a 12-column grid span function widthToSpan(pct) { @@ -28,7 +29,7 @@ function getValue(status, field) { return status.custom_fields?.[field.fieldId] ?? ''; } -export default function DailyStatusForm({ existing, animalId, experimentId, template = [], onTemplateUpdate, onSuccess, onCancel, onRequestDelete, hasPrev, hasNext, onNavigate }) { +export default function DailyStatusForm({ existing, animalId, experimentId, template = EMPTY_TEMPLATE, onTemplateUpdate, onSuccess, onCancel, onRequestDelete, hasPrev, hasNext, onNavigate }) { const today = format(new Date(), 'yyyy-MM-dd'); // Active fields from template (date is always first and handled separately) @@ -142,10 +143,10 @@ export default function DailyStatusForm({ existing, animalId, experimentId, temp
{/* Date — always full width */}
- +
- {errors.date &&

{errors.date}

} + {errors.date &&

{errors.date}

}
@@ -158,7 +159,7 @@ export default function DailyStatusForm({ existing, animalId, experimentId, temp const canSaveTag = experimentId && onTemplateUpdate && currentValue && !fieldTags.includes(currentValue) && !field.tagsDisabled; return (
-