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('');
  });
});
