import { render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { WorkspaceMetricRail } from './WorkspaceMetricRail';

describe('WorkspaceMetricRail', () => {
  it('renders one primary outcome and supporting facts as accessible Semi cards', () => {
    const view = render(<WorkspaceMetricRail
      ariaLabel="查询统计"
      className="test-rail"
      cardClassName="test-card"
      secondaryClassName="test-secondary"
      primaryValueClassName="test-primary-value"
      primary={{ label: '结果行数', value: '1,024', note: '来自 20 辆车辆' }}
      secondary={[
        { label: '车辆数', value: '20', note: '当前授权范围', className: 'is-vehicles' },
        { label: '数据来源', value: 'GB32960', note: '全部协议来源', className: 'is-sources' }
      ]}
    />);

    expect(view.container.querySelector('.test-rail.semi-card')).toHaveAttribute('aria-label', '查询统计');
    expect(view.container.querySelector('.test-card.is-primary .test-primary-value')).toHaveTextContent('1,024');
    expect(view.container.querySelector('.test-secondary.semi-card-group')).toBeInTheDocument();
    expect(view.container.querySelectorAll('.test-card.semi-card')).toHaveLength(3);
    expect(screen.getByLabelText('车辆数：20；当前授权范围')).toHaveClass('is-vehicles');
  });
});
