// @vitest-environment jsdom import { fireEvent, render, screen, waitFor } from '@testing-library/react'; import { beforeEach, describe, expect, test, vi } from 'vitest'; import { getHealth } from '../app/features/system/api'; import { useNotifications } from '../app/features/notifications/hooks'; import Sidebar from './Sidebar'; import Notifications from './Notifications'; vi.mock('../app/features/system/api', /* systemApiMockFactory 提供侧边栏健康检查的确定性 API 替身。 */ () => ({ getHealth: vi.fn() })); vi.mock('../app/features/notifications/hooks', /* notificationsHookMockFactory 提供通知页面状态替身。 */ () => ({ useNotifications: vi.fn() })); vi.mock('../app/features/notifications/components/NotificationChannelList', /* channelListMockFactory 隔离通知列表子组件。 */ () => ({ NotificationChannelList: /* channelListRenderer 渲染通知列表占位节点。 */ () =>
})); vi.mock('../app/features/notifications/components/NotificationChannelModal', /* channelModalMockFactory 隔离通知编辑子组件。 */ () => ({ NotificationChannelModal: /* channelModalRenderer 渲染通知编辑占位节点。 */ () => })); vi.mock('../app/features/notifications/components/NotificationSmtpSettings', /* smtpSettingsMockFactory 隔离SMTP子组件。 */ () => ({ NotificationSmtpSettings: /* smtpSettingsRenderer 渲染SMTP占位节点。 */ () => })); // healthMock 是侧边栏健康检查的可控替身。 const healthMock = vi.mocked(getHealth); // useNotificationsMock 是通知页面 Hook 的可控替身。 const useNotificationsMock = vi.mocked(useNotifications); describe('基础页面组件', /* 当前回调覆盖侧边栏和通知页面的结构分支。 */ () => { beforeEach(/* 当前回调重置页面组件 API 替身。 */ () => { vi.clearAllMocks(); healthMock.mockResolvedValue({ version: '1.2.3', commit: 'abc123' }); }); test('侧边栏展示管理员菜单并触发导航、折叠和注销', /* 当前回调验证侧边栏导航交互和版本信息。 */ async () => { // onNavigate 是侧边栏导航回调替身。 const onNavigate = vi.fn(); // onToggleCollapsed 是侧边栏折叠回调替身。 const onToggleCollapsed = vi.fn(); // onLogout 是侧边栏注销回调替身。 const onLogout = vi.fn(); render(