MIN_SAMPLE goes back to the specified 10. The reason it had been lowered to 3 was real — a small clinic saw an empty report — but the fix was wrong: three samples do not make an average, and calling that "accurate" is worse than saying nothing. Rows below the threshold are now returned rather than dropped, with severity null and below_min_sample true. That refuses both mistakes: it claims no severity it cannot support, and it does not show a small clinic an empty page that implies everything is fine. They sort after the usable rows and render faded with a "small sample" badge. The utilization page gets its Recharts bar chart. The table stays underneath — six numeric columns are not something a chart answers — but the one question the table is bad at, "which resource is behind", is exactly what a chart is for. Colours come from the design tokens rather than hex, which is where a chart usually breaks in dark mode, and a resource with no calendar is left out entirely: null is not zero, and a zero bar would be a lie. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
||
import { render, screen } from '@testing-library/react';
|
||
import ResourceUtilizationChart from './ResourceUtilizationChart';
|
||
|
||
const row = (over: Record<string, unknown> = {}) => ({
|
||
resource_uuid: 'r-1',
|
||
resource_name: 'اتاق ۱',
|
||
role: 'room',
|
||
available_minutes: 600,
|
||
occupied_minutes: 300,
|
||
active_minutes: 200,
|
||
utilization: 0.5,
|
||
active_ratio: 0.66,
|
||
wasted_capacity: false,
|
||
...over,
|
||
}) as never;
|
||
|
||
describe('ResourceUtilizationChart', () => {
|
||
it('renders a bar per resource that has a calendar', () => {
|
||
const { container } = render(
|
||
<ResourceUtilizationChart rows={[row(), row({ resource_uuid: 'r-2', resource_name: 'اتاق ۲' })]} />,
|
||
);
|
||
|
||
expect(screen.getByText('بهرهوری منابع')).toBeInTheDocument();
|
||
expect(container.querySelector('.recharts-responsive-container')).not.toBeNull();
|
||
});
|
||
|
||
/** ⭐ `null` صفر نیست — ستون صفر برای منبعِ بیتقویم دروغ میگوید. */
|
||
it('leaves out resources with no calendar instead of drawing them at zero', () => {
|
||
const { container } = render(
|
||
<ResourceUtilizationChart rows={[row({ utilization: null }), row({ utilization: null, resource_uuid: 'r-2' })]} />,
|
||
);
|
||
|
||
expect(container.textContent).toBe('');
|
||
});
|
||
});
|