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

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

const mockProducts = createFixtureList(createPointsProductFixture, 5, [
  { id: 'product-1', name: '体检套餐兑换券', product_type: 'service', points_cost: 100 },
  { id: 'product-2', name: '健康手环', product_type: 'physical', points_cost: 200 },
]);

createListPageTests({
  Component: PointsProductList,
  apiPath: '/api/v1/health/points/products',
  columns: ['商品名称', '类型', '积分', '库存', '状态'],
  firstRowTexts: ['体检套餐兑换券'],
  totalItems: 5,
  hasCreateButton: true,
  createButtonText: '新建商品',
  hasSearch: true,
  hasPagination: true,
  mockItems: mockProducts as Record<string, unknown>[],
});

describe('PointsProductList extra tests', () => {
  it('renders the page title', async () => {
    vi.setConfig({ testTimeout: 15000 });
    renderWithProviders(<PointsProductList />);
    await waitFor(() => {
      expect(screen.getByText('积分商品')).toBeInTheDocument();
    });
  });
});
