|
| 1 | +import { act, render, screen } from '@testing-library/react'; |
| 2 | +import { beforeEach, describe, expect, it, vi } from 'vitest'; |
| 3 | +import { useUIStore } from '@/stores'; |
| 4 | +import { SettingsPage } from '../SettingsPage'; |
| 5 | + |
| 6 | +vi.mock('antd', () => ({ |
| 7 | + theme: { |
| 8 | + useToken: () => ({ |
| 9 | + token: { |
| 10 | + colorBgContainer: '#ffffff', |
| 11 | + colorBgElevated: '#f8f8f8', |
| 12 | + }, |
| 13 | + }), |
| 14 | + }, |
| 15 | +})); |
| 16 | + |
| 17 | +vi.mock('@/components/settings', () => ({ |
| 18 | + SettingsSidebar: () => <nav>settings-sidebar</nav>, |
| 19 | + ProviderSettings: () => <div>providers-content</div>, |
| 20 | + GeneralSettings: () => <div>general-content</div>, |
| 21 | + DisplaySettings: () => <div>display-content</div>, |
| 22 | + ProxySettings: () => <div>proxy-content</div>, |
| 23 | + ShortcutSettings: () => <div>shortcuts-content</div>, |
| 24 | + DataManager: () => <div>data-content</div>, |
| 25 | + AboutPage: () => <div>about-content</div>, |
| 26 | + SearchProviderSettings: () => <div>search-providers-content</div>, |
| 27 | + McpServerSettings: () => <div>mcp-servers-content</div>, |
| 28 | + BackupCenter: () => <div>backup-content</div>, |
| 29 | + StorageSpaceManager: () => <div>storage-content</div>, |
| 30 | +})); |
| 31 | + |
| 32 | +vi.mock('@/components/settings/DefaultModelSettings', () => ({ |
| 33 | + DefaultModelSettings: () => <div>default-model-content</div>, |
| 34 | +})); |
| 35 | + |
| 36 | +vi.mock('@/components/settings/ConversationSettings', () => ({ |
| 37 | + ConversationSettings: () => <div>conversation-settings-content</div>, |
| 38 | +})); |
| 39 | + |
| 40 | +describe('SettingsPage', () => { |
| 41 | + beforeEach(() => { |
| 42 | + act(() => { |
| 43 | + useUIStore.setState({ |
| 44 | + activePage: 'settings', |
| 45 | + previousPage: 'chat', |
| 46 | + settingsSection: 'general', |
| 47 | + selectedProviderId: null, |
| 48 | + }); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + it('resets the content scroll position when switching settings sections', () => { |
| 53 | + render(<SettingsPage />); |
| 54 | + |
| 55 | + const contentScroller = screen.getByText('general-content').parentElement as HTMLElement; |
| 56 | + contentScroller.scrollTop = 480; |
| 57 | + |
| 58 | + act(() => { |
| 59 | + useUIStore.getState().setSettingsSection('display'); |
| 60 | + }); |
| 61 | + |
| 62 | + expect(screen.getByText('display-content')).toBeInTheDocument(); |
| 63 | + expect(contentScroller.scrollTop).toBe(0); |
| 64 | + }); |
| 65 | +}); |
0 commit comments