fix: day modal bar chart shows experiment-wide session stats per subject

Shows Total / Success / Failure bars across ALL sessions for each animal
that has at least one valid (non-empty) value for the chosen field.
Animals with zero valid field entries are excluded from the chart.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Experiments DB Dev
2026-04-23 12:21:52 -04:00
parent 9b51250d8e
commit 7439a1a101
2 changed files with 32 additions and 21 deletions
+9 -6
View File
@@ -248,7 +248,7 @@ describe('day click modal', () => {
// ── Bar chart (inside day modal) ──────────────────────────────────────────────
describe('bar chart inside day modal', () => {
it('renders bar chart for numeric field values on that day', async () => {
it('renders session stats bar chart when animals have valid field data', async () => {
const dateStr = todayStr();
const statuses = [
makeStatus('a1000000-0000-0000-0000-000000000001', dateStr, { 'ww000000-0000-0000-0000-000000000099': '325' }),
@@ -263,16 +263,19 @@ describe('bar chart inside day modal', () => {
});
});
it('does not render bar chart when selected field is non-numeric', async () => {
it('excludes animals with no valid field data from bar chart', async () => {
const dateStr = todayStr();
// vitals is a text field — not numeric, so no bar chart
const statuses = [makeStatus('a1000000-0000-0000-0000-000000000001', dateStr, {}, 'HR 72')];
// Rat A has weight data; Rat B has only empty custom_fieldsshould be excluded from chart
const statuses = [
makeStatus('a1000000-0000-0000-0000-000000000001', dateStr, { 'ww000000-0000-0000-0000-000000000099': '325' }),
makeStatus('a2000000-0000-0000-0000-000000000002', dateStr, {}),
];
render(
<ExperimentCalendar experimentId={EXP_ID} template={TEMPLATE} allStatuses={statuses} animals={ANIMALS} />,
);
fireEvent.change(screen.getByTestId('field-select'), { target: { value: 'vitals' } });
fireEvent.click(screen.getByTestId(`day-${dateStr}`));
await waitFor(() => screen.getByRole('dialog'));
expect(screen.queryByTestId('bar-chart')).not.toBeInTheDocument();
// Both animals are in the day view (both have records), but bar chart only has Rat A
expect(screen.getByTestId('bar-chart')).toBeInTheDocument();
});
});