mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
section 4: Phase 4: Permission mode toggle in the composer and default
This commit is contained in:
1 parent
f85531f2d3
commit
dd4db97c0b
14 files changed
+379
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import { describe, it, expect, vi, beforeAll, beforeEach } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { SessionAutomationSettings } from './SessionAutomationSettings'
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
import type { UserPreferences } from '@/api/types/settings'
|
||||
import { createUseSettingsMock } from '@/test/test-utils'
|
||||
|
||||
vi.mock('@/hooks/useSettings')
|
||||
|
||||
const basePreferences: UserPreferences = {
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
autoScroll: true,
|
||||
expandDiffs: true,
|
||||
expandToolCalls: false,
|
||||
showReasoning: false,
|
||||
simpleChatMode: false,
|
||||
keyboardShortcuts: {},
|
||||
customCommands: [],
|
||||
}
|
||||
|
||||
function mockUseSettings(overrides: Partial<ReturnType<typeof useSettings>> = {}) {
|
||||
vi.mocked(useSettings).mockReturnValue(createUseSettingsMock({ preferences: basePreferences, ...overrides }))
|
||||
}
|
||||
|
||||
describe('SessionAutomationSettings', () => {
|
||||
beforeAll(() => {
|
||||
Element.prototype.hasPointerCapture ??= () => false
|
||||
Element.prototype.setPointerCapture ??= () => {}
|
||||
Element.prototype.releasePointerCapture ??= () => {}
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('defaults the select to ask every time', () => {
|
||||
mockUseSettings()
|
||||
render(<SessionAutomationSettings />)
|
||||
|
||||
expect(screen.getByRole('heading', { name: 'Sessions' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('combobox', { name: 'Default permission mode for new sessions' })).toHaveTextContent('Ask every time')
|
||||
})
|
||||
|
||||
it('persists the chosen default permission mode', async () => {
|
||||
const user = userEvent.setup()
|
||||
const updateSettings = vi.fn()
|
||||
mockUseSettings({
|
||||
preferences: { ...basePreferences, sessionDefaults: { permissionMode: 'ask' } },
|
||||
updateSettings,
|
||||
})
|
||||
render(<SessionAutomationSettings />)
|
||||
|
||||
await user.click(screen.getByRole('combobox', { name: 'Default permission mode for new sessions' }))
|
||||
await user.click(screen.getByRole('option', { name: 'Accept everything' }))
|
||||
|
||||
expect(updateSettings).toHaveBeenCalledWith({ sessionDefaults: { permissionMode: 'auto' } })
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user