mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
refactor(frontend): extract navigation helpers and improve settings back navigation (#210)
* feat: add persistent model state storage with database backend - Create opencode_model_state table for storing user model preferences - Implement database-backed model state management (recent, favorite, variant) - Add atomic JSON file utilities with file locking for concurrent safety - Migrate providers routes from file-based to database storage - Add backfill migration to preserve existing model.json data - Include comprehensive tests for model-state and atomic-json modules - Refactor useSessionAgent hook to simplify agent/model resolution logic - Update getFileApiUrl to use consistent query parameter approach * fix: include workspace dependencies in Docker image * fix: overlay workspace node_modules after source to prevent layer overwrite * fix: ensure model state table exists for existing databases * feat: add model state persistence and improve model selection sync - Add setActiveModel to modelStore and useModelSelection for direct model updates - Sync session agent model/variant to store when messages load - Include model, agent, and variant in optimistic user messages - Fix useSessionAgent to check isFetching during message loading - Update env.ts to use getter for BASE_PATH for dynamic resolution - Fix test environment variable from OPENCODE_WORKSPACE_PATH to WORKSPACE_PATH * refactor(frontend): extract navigation helpers and improve settings back navigation - Move swipe-back route logic into shared navigation.ts module - Add getSessionListPath helper for consistent session list navigation - Add section history tracking to settings dialog for proper back navigation - Fix voice status overlay loading text visibility during starting state - Update env and vite config for production domain
This commit is contained in:
1 parent
549e0ac7b2
commit
e959cc409f
10 files changed
+361
-66
No files matched your search
@@ -0,0 +1,118 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import { MemoryRouter, useLocation, useNavigate } from 'react-router-dom'
|
||||
import { SettingsDialog } from './SettingsDialog'
|
||||
|
||||
vi.mock('@/components/settings/GeneralSettings', () => ({
|
||||
GeneralSettings: () => <div data-testid="general-settings">General Settings Content</div>,
|
||||
}))
|
||||
|
||||
vi.mock('@/components/settings/GitSettings', () => ({
|
||||
GitSettings: () => <div data-testid="git-settings">Git Settings Content</div>,
|
||||
}))
|
||||
|
||||
vi.mock('@/components/settings/KeyboardShortcuts', () => ({
|
||||
KeyboardShortcuts: () => <div data-testid="shortcuts-settings">Keyboard Shortcuts Content</div>,
|
||||
}))
|
||||
|
||||
vi.mock('@/components/settings/OpenCodeConfigManager', () => ({
|
||||
OpenCodeConfigManager: () => <div data-testid="opencode-settings">OpenCode Config Content</div>,
|
||||
}))
|
||||
|
||||
vi.mock('@/components/settings/ProviderSettings', () => ({
|
||||
ProviderSettings: () => <div data-testid="providers-settings">Provider Settings Content</div>,
|
||||
}))
|
||||
|
||||
vi.mock('@/components/settings/AccountSettings', () => ({
|
||||
AccountSettings: () => <div data-testid="account-settings">Account Settings Content</div>,
|
||||
}))
|
||||
|
||||
vi.mock('@/components/settings/VoiceSettings', () => ({
|
||||
VoiceSettings: () => <div data-testid="voice-settings">Voice Settings Content</div>,
|
||||
}))
|
||||
|
||||
vi.mock('@/components/settings/NotificationSettings', () => ({
|
||||
NotificationSettings: () => <div data-testid="notification-settings">Notification Settings Content</div>,
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useMobile', () => ({
|
||||
useSwipeBack: vi.fn(() => ({
|
||||
bind: vi.fn(),
|
||||
swipeProgress: 0,
|
||||
swipeStyles: {},
|
||||
})),
|
||||
}))
|
||||
|
||||
describe('SettingsDialog', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('resets to menu state when dialog closes and reopens', () => {
|
||||
function TestWrapper() {
|
||||
const location = useLocation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const searchParams = new URLSearchParams(location.search)
|
||||
const isOpen = searchParams.get('settings') === 'open'
|
||||
|
||||
return (
|
||||
<>
|
||||
<button onClick={() => navigate('?settings=open&tab=general')}>Open Settings</button>
|
||||
<button onClick={() => navigate('/')}>Close Settings</button>
|
||||
{isOpen && <span data-testid="dialog-open">Dialog Open</span>}
|
||||
<SettingsDialog />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/']}>
|
||||
<TestWrapper />
|
||||
</MemoryRouter>
|
||||
)
|
||||
|
||||
fireEvent.click(screen.getByText('Open Settings'))
|
||||
expect(screen.getByTestId('dialog-open')).toBeInTheDocument()
|
||||
|
||||
fireEvent.click(screen.getByText('Close Settings'))
|
||||
expect(screen.queryByTestId('dialog-open')).not.toBeInTheDocument()
|
||||
|
||||
fireEvent.click(screen.getByText('Open Settings'))
|
||||
expect(screen.getByTestId('dialog-open')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('displays menu items in mobile view', () => {
|
||||
function TestWrapper() {
|
||||
const location = useLocation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const searchParams = new URLSearchParams(location.search)
|
||||
const isOpen = searchParams.get('settings') === 'open'
|
||||
|
||||
return (
|
||||
<>
|
||||
<button onClick={() => navigate('?settings=open')}>Open Settings</button>
|
||||
{isOpen && <span data-testid="dialog-open">Dialog Open</span>}
|
||||
<SettingsDialog />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/']}>
|
||||
<TestWrapper />
|
||||
</MemoryRouter>
|
||||
)
|
||||
|
||||
fireEvent.click(screen.getByText('Open Settings'))
|
||||
expect(screen.getByTestId('dialog-open')).toBeInTheDocument()
|
||||
|
||||
expect(screen.getAllByText('Account').length).toBeGreaterThanOrEqual(1)
|
||||
expect(screen.getAllByText('General').length).toBeGreaterThanOrEqual(1)
|
||||
expect(screen.getAllByText('Git').length).toBeGreaterThanOrEqual(1)
|
||||
expect(screen.getAllByText('Shortcuts').length).toBeGreaterThanOrEqual(1)
|
||||
expect(screen.getAllByText('OpenCode').length).toBeGreaterThanOrEqual(1)
|
||||
expect(screen.getAllByText('Providers').length).toBeGreaterThanOrEqual(1)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user