import { describe, it, expect, vi } from 'vitest';
import { waitFor } from '@testing-library/react';
import { createListPageTests } from '../../test/factories/listPageTests';
import { createFixtureList, createAlertRuleFixture } from '../../test/fixtures';
import { renderWithProviders } from '../../test/utils/renderWithProviders';
import AlertRuleList from './AlertRuleList';

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

const mockRules = createFixtureList(createAlertRuleFixture, 5, [
  { id: 'rule-1', name: '血压偏高告警' },
  { id: 'rule-2', name: '心率异常告警' },
]);

createListPageTests({
  Component: AlertRuleList,
  apiPath: '/api/v1/health/alert-rules',
  columns: ['规则名称', '指标类型', '条件类型', '严重程度'],
  firstRowTexts: ['血压偏高告警'],
  totalItems: 5,
  hasCreateButton: true,
  createButtonText: '新建规则',
  hasSearch: false,
  hasPagination: false,
  mockItems: mockRules as Record<string, unknown>[],
});

describe('AlertRuleList extra tests', () => {
  it('renders severity tags in the table', async () => {
    vi.setConfig({ testTimeout: 15000 });
    renderWithProviders(<AlertRuleList />);
    await waitFor(() => {
      const tags = document.querySelectorAll('.ant-tag');
      expect(tags.length).toBeGreaterThan(0);
    });
  });
});
