| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import { fireEvent, render, screen, waitFor } from '@testing-library/react';
- import { beforeEach, expect, it, vi } from 'vitest';
- import { history } from '@umijs/max';
- import ChatsPage from '@/pages/Chats';
- import { apiRequest } from '@/services/api';
- vi.mock('@/services/api', () => ({ apiRequest: vi.fn() }));
- beforeEach(() => vi.clearAllMocks());
- it('加载群列表并进入管理页', async () => {
- vi.mocked(apiRequest).mockResolvedValue({
- items: [
- {
- chat_id: '-100123',
- title: '测试运营群',
- username: 'ops_test',
- type: 'supergroup',
- accessible: true,
- member_count: 42,
- bot_status: 'administrator',
- },
- {
- chat_id: '-100456',
- title: '机器人已退出的群',
- type: 'supergroup',
- accessible: false,
- member_count: 8,
- bot_status: 'left',
- },
- ],
- total: 2,
- page: 1,
- page_size: 20,
- });
- render(<ChatsPage />);
- expect(await screen.findByText('测试运营群')).toBeInTheDocument();
- const manageButtons = screen.getAllByRole('button', { name: '管理' });
- fireEvent.click(manageButtons[0]);
- expect(history.push).toHaveBeenCalledWith('/chats/-100123');
- expect(manageButtons[1]).toBeDisabled();
- await waitFor(() => expect(apiRequest).toHaveBeenCalledTimes(1));
- });
|