import { describe, expect, test, vi } from 'vitest';
import { detailTriggerRow } from './detailTriggerRow';

describe('detailTriggerRow', () => {
  test('opens from pointer, Enter, and Space with consistent expanded semantics', () => {
    const onOpen = vi.fn();
    const props = detailTriggerRow({
      className: 'is-selected',
      expanded: true,
      label: '查看车辆详情',
      testId: 'vehicle-row',
      onOpen
    });

    expect(props).toMatchObject({
      className: 'is-selected',
      role: 'button',
      tabIndex: 0,
      'aria-expanded': true,
      'aria-label': '查看车辆详情',
      'data-testid': 'vehicle-row'
    });

    props.onClick?.({} as never);
    const enter = { key: 'Enter', preventDefault: vi.fn() };
    props.onKeyDown?.(enter as never);
    const space = { key: ' ', preventDefault: vi.fn() };
    props.onKeyDown?.(space as never);
    props.onKeyDown?.({ key: 'Escape', preventDefault: vi.fn() } as never);

    expect(onOpen).toHaveBeenCalledTimes(3);
    expect(enter.preventDefault).toHaveBeenCalledOnce();
    expect(space.preventDefault).toHaveBeenCalledOnce();
  });
});
