import { describe, expect, it } from 'vitest';
import { buildGanttOption } from './DashboardCharts';
import type { GanttOccupancy } from './Dashboard.types';

const ganttRoom = (occupancies: GanttOccupancy[]) => [
  { roomNumber: 'A101', occupancies },
];

describe('buildGanttOption 甘特图时间线', () => {
  it('未退宿的入住条在查看过去月份时截断到 periodEnd，而不是画到今天', () => {
    const option = buildGanttOption(
      ganttRoom([
        {
          studentName: '张三',
          checkInDate: '2026-05-01',
          checkOutDate: null,
        },
      ]),
      { periodEnd: '2026-06-30', today: '2026-08-07' },
    );

    const series = option.series as Array<{ data: Array<{ value: [string, string, string, boolean] }> }>;
    expect(series[0].data[0].value[2]).toBe('2026-06-30');
    expect(series[0].data[0].value[3]).toBe(true);
  });

  it('未退宿的入住条在查看当前月时截断到今天', () => {
    const option = buildGanttOption(
      ganttRoom([
        {
          studentName: '张三',
          checkInDate: '2026-07-01',
          checkOutDate: null,
        },
      ]),
      { periodEnd: '2026-08-31', today: '2026-08-07' },
    );

    const series = option.series as Array<{ data: Array<{ value: [string, string, string, boolean] }> }>;
    expect(series[0].data[0].value[2]).toBe('2026-08-07');
  });

  it('已退宿的入住条保留真实退宿日期', () => {
    const option = buildGanttOption(
      ganttRoom([
        {
          studentName: '李四',
          checkInDate: '2026-05-01',
          checkOutDate: '2026-06-15',
        },
      ]),
      { periodEnd: '2026-06-30', today: '2026-08-07' },
    );

    const series = option.series as Array<{ data: Array<{ value: [string, string, string, boolean] }> }>;
    expect(series[0].data[0].value[2]).toBe('2026-06-15');
    expect(series[0].data[0].value[3]).toBe(false);
  });
});
