Files
opencode-manager/frontend/src/components/repo/RepoSkillsDialog.test.tsx
T
Chris Scott 03bd3dac95 feat(frontend): improve model selection experience (#237)
* chore: remove dead code and unused exports

* fix: preserve model form during config refresh

Signed-off-by: mehmet turac <mehmetturac@gmail.com>

* loop: model-select-fix completed after 11 iterations

* fix(frontend): show provider prefix for duplicate models in quick select dropdown

When the same model exists under multiple providers, show the provider name
for both entries so users can distinguish them. Detects duplicates by modelID
across all favorites and recents.

* refactor(frontend): replace useTallScrollContent with scroll visibility hook

* fix: harden mirror push rollback

* Remove Load button from skill cards, clicking card loads skill

* feat(backend): add plugin installation support and schema updates

* refactor(frontend): remove unused useHeaderScrollVisibility hook

* refactor(frontend): replace model dropdown with bottom sheet selector

Replace DropdownMenu-based ModelQuickSelect with a bottom sheet
implementation featuring favorites, recents, provider browsing, and
search. Remove onShowModelsDialog prop from PromptInput and
SessionDetail, using data attribute trigger instead. Fix ZodIssueCode
deprecation, input text color, and portal rendering for bottom sheet.

* fix(frontend): simplify session model restore and fix mobile swipe reset

* loop: single-source-models completed after 10 iterations

* refactor(frontend): add desktop sidebar layout to model quick select

* refactor(frontend): improve model selector with connected providers, favorites, and recent management

* fix(frontend): constrain model name width to prevent overflow in prompt input

* fix(frontend): adjust padding and styling in model quick select

* fix(frontend): add optimistic removal with rollback for recent models

---------
2026-05-25 09:47:59 -04:00

271 lines
7.2 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import type { ReactNode } from 'react'
import { RepoSkillsDialog } from './RepoSkillsDialog'
import type { SkillFileInfo } from '@opencode-manager/shared'
const mocks = vi.hoisted(() => ({
listManagedSkills: vi.fn(),
sendCommand: vi.fn(),
}))
vi.mock('@/api/settings', () => ({
settingsApi: {
listManagedSkills: mocks.listManagedSkills,
},
}))
vi.mock('@/api/opencode', () => ({
OpenCodeClient: vi.fn(() => ({
sendCommand: mocks.sendCommand,
})),
}))
vi.mock('@/lib/toast', () => ({
showToast: {
error: vi.fn(),
success: vi.fn(),
},
}))
describe('RepoSkillsDialog', () => {
beforeEach(() => {
vi.clearAllMocks()
})
const createWrapper = () => {
const queryClient = new QueryClient({
defaultOptions: {
queries: { retry: false },
},
})
return ({ children }: { children: ReactNode }) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
)
}
const mockSkills: SkillFileInfo[] = [
{
name: 'test-skill',
description: 'A test skill for testing',
body: 'Test skill content',
location: '/repo/.opencode/skills/test-skill/SKILL.md',
scope: 'project',
},
{
name: 'global-skill',
description: 'A global skill',
body: 'Global skill content',
location: '/home/user/.config/opencode/skills/global-skill/SKILL.md',
scope: 'global',
},
]
describe('tabs and skill filtering', () => {
it('shows both tabs when skills exist', async () => {
mocks.listManagedSkills.mockResolvedValue(mockSkills)
render(
<RepoSkillsDialog
open
onOpenChange={vi.fn()}
repoId={1}
/>,
{ wrapper: createWrapper() }
)
expect(screen.getByText('Project')).toBeInTheDocument()
expect(screen.getByText('Global')).toBeInTheDocument()
})
it('shows project skills in project tab', async () => {
mocks.listManagedSkills.mockResolvedValue(mockSkills)
render(
<RepoSkillsDialog
open
onOpenChange={vi.fn()}
repoId={1}
/>,
{ wrapper: createWrapper() }
)
await waitFor(() => {
expect(screen.getByText('Test skill')).toBeInTheDocument()
})
})
it('shows global skills in global tab', async () => {
mocks.listManagedSkills.mockResolvedValue(mockSkills)
render(
<RepoSkillsDialog
open
onOpenChange={vi.fn()}
repoId={1}
/>,
{ wrapper: createWrapper() }
)
await waitFor(() => {
expect(screen.getByText('Project')).toBeInTheDocument()
})
const globalTab = screen.getByText('Global')
await userEvent.click(globalTab)
expect(screen.getByText('Global skill')).toBeInTheDocument()
})
it('shows empty state for project tab when no project skills', async () => {
mocks.listManagedSkills.mockResolvedValue([
{
name: 'global-skill',
description: 'A global skill',
body: 'Global skill content',
location: '/home/user/.config/opencode/skills/global-skill/SKILL.md',
scope: 'global',
},
])
render(
<RepoSkillsDialog
open
onOpenChange={vi.fn()}
repoId={1}
/>,
{ wrapper: createWrapper() }
)
const projectTab = screen.getByText('Project')
await userEvent.click(projectTab)
await waitFor(() => {
expect(screen.getByText('No local skills found')).toBeInTheDocument()
})
})
})
describe('load functionality', () => {
it('makes skill cards clickable when sessionId and opcodeUrl are provided', async () => {
mocks.listManagedSkills.mockResolvedValue(mockSkills)
mocks.sendCommand.mockResolvedValue(undefined)
const onSkillLoaded = vi.fn()
const onOpenChange = vi.fn()
render(
<RepoSkillsDialog
open
onOpenChange={onOpenChange}
repoId={1}
sessionId="test-session"
opcodeUrl="http://localhost:5551"
directory="/test/repo"
onSkillLoaded={onSkillLoaded}
/>,
{ wrapper: createWrapper() }
)
await waitFor(() => {
expect(screen.getByText('Test skill')).toBeInTheDocument()
})
const card = screen.getByText('Test skill').closest('[class*="cursor-pointer"]')
expect(card).toBeTruthy()
})
it('does not make skill cards clickable when sessionId is not provided', async () => {
mocks.listManagedSkills.mockResolvedValue(mockSkills)
render(
<RepoSkillsDialog
open
onOpenChange={vi.fn()}
repoId={1}
/>,
{ wrapper: createWrapper() }
)
await waitFor(() => {
expect(screen.getByText('Test skill')).toBeInTheDocument()
})
const card = screen.getByText('Test skill').closest('[class*="cursor-pointer"]')
expect(card).toBeNull()
})
it('calls sendCommand and closes dialog on card click', async () => {
mocks.listManagedSkills.mockResolvedValue(mockSkills)
mocks.sendCommand.mockReturnValue(new Promise(() => {}))
const onSkillLoaded = vi.fn()
const onOpenChange = vi.fn()
const user = userEvent.setup()
render(
<RepoSkillsDialog
open
onOpenChange={onOpenChange}
repoId={1}
sessionId="test-session"
opcodeUrl="http://localhost:5551"
directory="/test/repo"
onSkillLoaded={onSkillLoaded}
/>,
{ wrapper: createWrapper() }
)
await waitFor(() => {
expect(screen.getByText('Test skill')).toBeInTheDocument()
})
const card = screen.getByText('Test skill').closest('[class*="cursor-pointer"]')!
await user.click(card)
expect(onOpenChange).toHaveBeenCalledWith(false)
expect(onSkillLoaded).toHaveBeenCalledWith(mockSkills[0])
expect(mocks.sendCommand).toHaveBeenCalledWith('test-session', {
command: 'test-skill',
arguments: '',
})
})
it('shows toast error on sendCommand failure', async () => {
const { showToast } = await import('@/lib/toast')
mocks.listManagedSkills.mockResolvedValue(mockSkills)
mocks.sendCommand.mockRejectedValue(new Error('Failed to load'))
const onOpenChange = vi.fn()
const user = userEvent.setup()
render(
<RepoSkillsDialog
open
onOpenChange={onOpenChange}
repoId={1}
sessionId="test-session"
opcodeUrl="http://localhost:5551"
directory="/test/repo"
/>,
{ wrapper: createWrapper() }
)
await waitFor(() => {
expect(screen.getByText('Test skill')).toBeInTheDocument()
})
const card = screen.getByText('Test skill').closest('[class*="cursor-pointer"]')!
await user.click(card)
await waitFor(() => {
expect(showToast.error).toHaveBeenCalledWith('Failed to load')
})
expect(onOpenChange).toHaveBeenCalledWith(false)
})
})
})