diff --git a/src/web/components/SiteCreatedModal.test.tsx b/src/web/components/SiteCreatedModal.test.tsx index 77c9fa6..875bdc3 100644 --- a/src/web/components/SiteCreatedModal.test.tsx +++ b/src/web/components/SiteCreatedModal.test.tsx @@ -1,7 +1,14 @@ import { describe, expect, it, vi } from 'vitest'; -import { act, create } from 'react-test-renderer'; +import { act, create, type ReactTestInstance } from 'react-test-renderer'; import SiteCreatedModal from './SiteCreatedModal.js'; +function collectText(node: ReactTestInstance): string { + return (node.children || []).map((child) => { + if (typeof child === 'string') return child; + return collectText(child); + }).join(''); +} + describe('SiteCreatedModal', () => { it('routes native dialog cancel events through onClose cleanup', async () => { const onChoice = vi.fn(); @@ -26,4 +33,35 @@ describe('SiteCreatedModal', () => { expect(onClose).toHaveBeenCalledTimes(1); expect(onChoice).not.toHaveBeenCalled(); }); + + it('keeps both next-step actions visible while promoting API key flow for api-key-first presets', async () => { + const onChoice = vi.fn(); + const onClose = vi.fn(); + const root = create( + , + ); + + const choiceButtons = root.root.findAll((node) => ( + node.type === 'button' + && typeof node.props.onClick === 'function' + && collectText(node) !== '稍后配置' + )); + + expect(choiceButtons.map((button) => collectText(button))).toEqual([ + '添加 API Key(推荐)', + '添加账号(用户名密码登录)', + ]); + + await act(async () => { + choiceButtons[1]!.props.onClick(); + }); + + expect(onChoice).toHaveBeenCalledWith('session'); + }); }); diff --git a/src/web/components/SiteCreatedModal.tsx b/src/web/components/SiteCreatedModal.tsx index 76cbc3b..0714b60 100644 --- a/src/web/components/SiteCreatedModal.tsx +++ b/src/web/components/SiteCreatedModal.tsx @@ -25,6 +25,31 @@ export default function SiteCreatedModal({ || (apiKeyFirst ? '该平台更适合直接通过 Base URL + API Key 接入,后续再补模型初始化。' : '接下来您可以继续补充登录连接或 API Key。'); + const actionButtons = apiKeyFirst + ? [ + { + choice: 'apikey' as const, + className: 'btn btn-primary btn-block', + label: '添加 API Key(推荐)', + }, + { + choice: 'session' as const, + className: 'btn btn-outline btn-block', + label: '添加账号(用户名密码登录)', + }, + ] + : [ + { + choice: 'session' as const, + className: 'btn btn-primary btn-block', + label: '添加账号(用户名密码登录)', + }, + { + choice: 'apikey' as const, + className: 'btn btn-outline btn-block', + label: '添加 API Key', + }, + ]; useEffect(() => { const dialog = dialogRef.current; @@ -85,29 +110,15 @@ export default function SiteCreatedModal({ )}
- {apiKeyFirst ? ( + {actionButtons.map((action) => ( - ) : ( - - )} - {!apiKeyFirst && ( - - )} + ))}