import { describe, it, expect, vi } from 'vitest';
import { screen, waitFor } from '@testing-library/react';
import { renderWithProviders } from '../../test/utils/renderWithProviders';

// Mock useThemeMode
vi.mock('../../hooks/useThemeMode', () => ({
  useThemeMode: () => false,
}));

import PointsRuleList from './PointsRuleList';

describe('PointsRuleList', () => {
  it('renders page title and table', async () => {
    vi.setConfig({ testTimeout: 15000 });
    renderWithProviders(<PointsRuleList />);

    await waitFor(() => {
      expect(screen.getByText('积分规则')).toBeInTheDocument();
    });
  });

  it('shows create button', async () => {
    renderWithProviders(<PointsRuleList />);
    await waitFor(() => {
      expect(screen.getByRole('button', { name: /新建规则/ })).toBeInTheDocument();
    });
  });

  it('renders table with column headers', async () => {
    renderWithProviders(<PointsRuleList />);
    await waitFor(() => {
      const table = document.querySelector('.ant-table');
      expect(table).toBeInTheDocument();
    });
    const headers = document.querySelectorAll('th');
    const headerTexts = Array.from(headers).map((h) => h.textContent?.trim());
    expect(headerTexts.some((t) => t?.includes('规则名称'))).toBe(true);
    expect(headerTexts.some((t) => t?.includes('事件类型'))).toBe(true);
    expect(headerTexts.some((t) => t?.includes('积分值'))).toBe(true);
  });

  it('shows filter controls', async () => {
    renderWithProviders(<PointsRuleList />);
    await waitFor(() => {
      const selects = document.querySelectorAll('.ant-select');
      expect(selects.length).toBeGreaterThanOrEqual(2);
    });
  });
});
