import { cleanup, fireEvent, render, screen } from '@testing-library/react';
import { afterEach, describe, expect, test, vi } from 'vitest';
import { VehicleOptionError } from './VehicleOptionError';

describe('VehicleOptionError', () => {
  afterEach(cleanup);

  test('renders a shared Semi retry action without blurring the picker', () => {
    const onRetry = vi.fn();
    render(<VehicleOptionError message="车辆候选加载失败" onRetry={onRetry} />);

    const retry = screen.getByRole('button', { name: '重试' });
    const mouseDown = new MouseEvent('mousedown', { bubbles: true, cancelable: true });
    retry.dispatchEvent(mouseDown);
    expect(mouseDown.defaultPrevented).toBe(true);
    expect(retry).toHaveClass('semi-button');
    fireEvent.click(retry);
    expect(onRetry).toHaveBeenCalledOnce();
  });
});
