From 2d7aef7414e8671b1ac7db336bc170eeb7cc5e2b Mon Sep 17 00:00:00 2001 From: CaIon Date: Sat, 19 Sep 2026 13:15:00 +0800 Subject: [PATCH] fix(web): restore CC Switch model dropdown --- .../__tests__/cc-switch-dialog.test.tsx | 127 ++++++++++++++++++ .../components/dialogs/cc-switch-dialog.tsx | 27 ++-- 2 files changed, 141 insertions(+), 13 deletions(-) create mode 100644 web/src/features/keys/components/dialogs/__tests__/cc-switch-dialog.test.tsx diff --git a/web/src/features/keys/components/dialogs/__tests__/cc-switch-dialog.test.tsx b/web/src/features/keys/components/dialogs/__tests__/cc-switch-dialog.test.tsx new file mode 100644 index 0000000000..857ae90de4 --- /dev/null +++ b/web/src/features/keys/components/dialogs/__tests__/cc-switch-dialog.test.tsx @@ -0,0 +1,127 @@ +/* +Copyright (C) 2023-2026 QuantumNous + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . + +For commercial licensing, please contact support@quantumnous.com +*/ +import { QueryClient, QueryClientProvider } from '@tanstack/react-query' +import { act, render, screen, waitFor } from '@testing-library/react' +import userEvent from '@testing-library/user-event' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' + +import { CCSwitchDialog } from '../cc-switch-dialog' + +let queryClient: QueryClient + +beforeEach(() => { + queryClient = new QueryClient({ + defaultOptions: { queries: { retry: false, gcTime: Infinity } }, + }) +}) + +afterEach(() => { + queryClient.clear() +}) + +function renderDialog(models = ['gpt-5.4', 'claude-sonnet-4-6']) { + queryClient.setQueryData(['user-models-ccswitch'], { + success: true, + data: models, + }) + render( + + + + ) +} + +describe('CC Switch model selection', () => { + it.each(['Claude', 'Codex', 'Gemini'])( + 'opens %s models outside the clipping dialog and keeps the dialog open after selection', + async (app) => { + renderDialog() + const user = userEvent.setup() + await user.click(screen.getByRole('radio', { name: app })) + const input = screen.getByRole('combobox', { name: 'Primary Model' }) + + await user.click(input) + + expect(input).toHaveAttribute('aria-expanded', 'true') + const list = await screen.findByRole('listbox') + const dialog = screen.getByRole('dialog', { name: 'Import to CC Switch' }) + // The dialog is translated and clips overflow. Its popup must escape + // that containing block to remain aligned and fully visible. + expect(dialog).not.toContainElement(list) + await user.click(screen.getByRole('option', { name: 'gpt-5.4' })) + await waitFor(() => expect(input).toHaveValue('gpt-5.4')) + expect(input).toHaveAttribute('aria-expanded', 'false') + expect(dialog).toBeVisible() + } + ) + + it('filters model names and supports keyboard selection and Escape without closing the dialog', async () => { + renderDialog() + const user = userEvent.setup() + await user.click(screen.getByRole('radio', { name: 'Codex' })) + const input = screen.getByRole('combobox', { name: 'Primary Model' }) + await user.click(input) + await user.type(input, 'sonnet') + + expect( + screen.queryByRole('option', { name: 'gpt-5.4' }) + ).not.toBeInTheDocument() + expect( + screen.getByRole('option', { name: 'claude-sonnet-4-6' }) + ).toBeVisible() + await user.keyboard('{ArrowDown}{Enter}') + await waitFor(() => expect(input).toHaveValue('claude-sonnet-4-6')) + await user.click(input) + await user.keyboard('{Escape}') + + expect(input).toHaveValue('claude-sonnet-4-6') + expect(input).toHaveAttribute('aria-expanded', 'false') + expect(screen.getByRole('dialog')).toBeVisible() + }) + + it('shows an empty result when no models are available and updates an open dropdown when models arrive', async () => { + renderDialog([]) + const user = userEvent.setup() + await user.click(screen.getByRole('radio', { name: 'Codex' })) + const input = screen.getByRole('combobox', { name: 'Primary Model' }) + await user.click(screen.getByRole('button', { name: 'Primary Model' })) + + expect(await screen.findByText('No models found')).toBeVisible() + await act(async () => { + queryClient.setQueryData(['user-models-ccswitch'], { + success: true, + data: ['gpt-5.4'], + }) + }) + await user.click(await screen.findByRole('option', { name: 'gpt-5.4' })) + await waitFor(() => expect(input).toHaveValue('gpt-5.4')) + }) + + it('lets users edit the provider name without opening a model dropdown', async () => { + renderDialog() + const user = userEvent.setup() + const input = screen.getByRole('textbox', { name: 'Name' }) + + await user.clear(input) + await user.type(input, 'Development') + + expect(input).toHaveValue('Development') + expect(screen.queryByRole('listbox')).not.toBeInTheDocument() + }) +}) diff --git a/web/src/features/keys/components/dialogs/cc-switch-dialog.tsx b/web/src/features/keys/components/dialogs/cc-switch-dialog.tsx index 72f25eaaa8..d93f68e9d3 100644 --- a/web/src/features/keys/components/dialogs/cc-switch-dialog.tsx +++ b/web/src/features/keys/components/dialogs/cc-switch-dialog.tsx @@ -23,7 +23,8 @@ import { toast } from 'sonner' import { Dialog } from '@/components/dialog' import { Button } from '@/components/ui/button' -import { ComboboxInput } from '@/components/ui/combobox-input' +import { Combobox } from '@/components/ui/combobox' +import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group' import { getUserModels } from '@/lib/api' @@ -153,9 +154,7 @@ export function CCSwitchDialog(props: Props) { title={t('Import to CC Switch')} contentClassName='sm:max-w-md' contentHeight='auto' - bodyClassName={ - currentConfig.modelFields.length === 1 ? 'space-y-4 pb-52' : 'space-y-4' - } + bodyClassName='space-y-4' footer={ <>