mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(ui): dock repo and session tools in a desktop side panel
Add a docked desktop tool panel with an icon rail, driven by the shared panel URL param, and keep the mobile dialogs and drawers. Extract dialog bodies into reusable content components, rename the walkthrough dialog to a sheet, and make walkthrough generation asynchronous with client polling.
This commit is contained in:
1 parent
bdbcc60716
commit
485ab940aa
49 files changed
+2631
-1753
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
||||
import { renderHook, act } from '@testing-library/react'
|
||||
import { useSidebarCollapsed, useSidebarSections } from './useSidebarCollapsed'
|
||||
import { useSidebarCollapsed } from './useSidebarCollapsed'
|
||||
|
||||
const localStorageMock = {
|
||||
getItem: vi.fn(),
|
||||
@@ -74,120 +74,4 @@ describe('sidebar collapse hooks', () => {
|
||||
expect(result.current[0]).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('useSidebarSections', () => {
|
||||
const sections = ['sessions', 'menu'] as const
|
||||
|
||||
it('opens every section by default when no stored value', () => {
|
||||
localStorageMock.getItem.mockReturnValue(null)
|
||||
|
||||
const { result } = renderHook(() => useSidebarSections(sections))
|
||||
|
||||
expect(result.current.isSectionOpen('sessions')).toBe(true)
|
||||
expect(result.current.isSectionOpen('menu')).toBe(true)
|
||||
})
|
||||
|
||||
it('restores closed sections from storage', () => {
|
||||
localStorageMock.getItem.mockReturnValue(JSON.stringify(['sessions']))
|
||||
|
||||
const { result } = renderHook(() => useSidebarSections(sections))
|
||||
|
||||
expect(localStorageMock.getItem).toHaveBeenCalledWith('oc:sidebar:collapsed:closed-sections')
|
||||
expect(result.current.isSectionOpen('sessions')).toBe(false)
|
||||
expect(result.current.isSectionOpen('menu')).toBe(true)
|
||||
})
|
||||
|
||||
it('ignores unknown sections from storage', () => {
|
||||
localStorageMock.getItem.mockReturnValue(JSON.stringify(['sessions', 'other']))
|
||||
|
||||
const { result } = renderHook(() => useSidebarSections(sections))
|
||||
|
||||
expect(result.current.isSectionOpen('sessions')).toBe(false)
|
||||
expect(result.current.isSectionOpen('menu')).toBe(true)
|
||||
})
|
||||
|
||||
it('opens every section when the stored value is malformed JSON', () => {
|
||||
localStorageMock.getItem.mockReturnValue('not-json{{')
|
||||
|
||||
const { result } = renderHook(() => useSidebarSections(sections))
|
||||
|
||||
expect(result.current.isSectionOpen('sessions')).toBe(true)
|
||||
expect(result.current.isSectionOpen('menu')).toBe(true)
|
||||
})
|
||||
|
||||
it('opens every section when the stored value is not an array', () => {
|
||||
localStorageMock.getItem.mockReturnValue(JSON.stringify('menu'))
|
||||
|
||||
const { result } = renderHook(() => useSidebarSections(sections))
|
||||
|
||||
expect(result.current.isSectionOpen('sessions')).toBe(true)
|
||||
expect(result.current.isSectionOpen('menu')).toBe(true)
|
||||
})
|
||||
|
||||
it('closes a section and persists it without affecting the others', () => {
|
||||
localStorageMock.getItem.mockReturnValue(null)
|
||||
|
||||
const { result } = renderHook(() => useSidebarSections(sections))
|
||||
|
||||
act(() => {
|
||||
result.current.toggleSection('sessions')
|
||||
})
|
||||
|
||||
expect(result.current.isSectionOpen('sessions')).toBe(false)
|
||||
expect(result.current.isSectionOpen('menu')).toBe(true)
|
||||
expect(localStorageMock.setItem).toHaveBeenCalledWith(
|
||||
'oc:sidebar:collapsed:closed-sections',
|
||||
JSON.stringify(['sessions']),
|
||||
)
|
||||
})
|
||||
|
||||
it('reopens a closed section when toggled again', () => {
|
||||
localStorageMock.getItem.mockReturnValue(JSON.stringify(['sessions']))
|
||||
|
||||
const { result } = renderHook(() => useSidebarSections(sections))
|
||||
|
||||
act(() => {
|
||||
result.current.toggleSection('sessions')
|
||||
})
|
||||
|
||||
expect(result.current.isSectionOpen('sessions')).toBe(true)
|
||||
expect(localStorageMock.setItem).toHaveBeenCalledWith(
|
||||
'oc:sidebar:collapsed:closed-sections',
|
||||
JSON.stringify([]),
|
||||
)
|
||||
})
|
||||
|
||||
it('defaults open and keeps toggling in memory when storage throws', () => {
|
||||
localStorageMock.getItem.mockImplementationOnce(() => {
|
||||
throw new Error('SecurityError')
|
||||
})
|
||||
localStorageMock.setItem.mockImplementationOnce(() => {
|
||||
throw new Error('QuotaExceededError')
|
||||
})
|
||||
|
||||
const { result } = renderHook(() => useSidebarSections(sections))
|
||||
|
||||
expect(result.current.isSectionOpen('sessions')).toBe(true)
|
||||
|
||||
act(() => {
|
||||
result.current.toggleSection('sessions')
|
||||
})
|
||||
|
||||
expect(result.current.isSectionOpen('sessions')).toBe(false)
|
||||
})
|
||||
|
||||
it('tracks each section independently', () => {
|
||||
localStorageMock.getItem.mockReturnValue(null)
|
||||
|
||||
const { result } = renderHook(() => useSidebarSections(sections))
|
||||
|
||||
act(() => {
|
||||
result.current.toggleSection('sessions')
|
||||
result.current.toggleSection('menu')
|
||||
})
|
||||
|
||||
expect(result.current.isSectionOpen('sessions')).toBe(false)
|
||||
expect(result.current.isSectionOpen('menu')).toBe(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user