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

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

  test('renders a compact Semi retry action for map errors', () => {
    const onRetry = vi.fn();
    render(<MapRetryAction onRetry={onRetry} />);
    const action = screen.getByRole('button', { name: '重新加载地图' });
    expect(action).toHaveClass('semi-button', 'v2-map-retry-action');
    fireEvent.click(action);
    expect(onRetry).toHaveBeenCalledOnce();
  });

  test('renders primary and secondary recovery hierarchy with Semi buttons', () => {
    const onPrimary = vi.fn();
    const onSecondary = vi.fn();
    render(<RecoveryActions primaryLabel="重试加载模块" onPrimary={onPrimary} secondaryLabel="刷新当前页面" onSecondary={onSecondary} showHome={false} />);

    const primary = screen.getByRole('button', { name: '重试加载模块' });
    const secondary = screen.getByRole('button', { name: '刷新当前页面' });
    expect(primary).toHaveClass('semi-button-primary');
    expect(secondary).toHaveClass('semi-button-light');
    fireEvent.click(primary);
    fireEvent.click(secondary);
    expect(onPrimary).toHaveBeenCalledOnce();
    expect(onSecondary).toHaveBeenCalledOnce();
  });
});
