1
0
forked from boos/BoosAPI

fix(web): preserve both site-created next steps (#357)

This commit is contained in:
Cita
2026-04-01 09:47:21 +08:00
committed by GitHub
parent 0de9c5e3f1
commit 6206c5bd77
2 changed files with 70 additions and 21 deletions
+39 -1
View File
@@ -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(
<SiteCreatedModal
siteName="CodingPlan"
initializationPresetId="codingplan-openai"
initialSegment="apikey"
onChoice={onChoice}
onClose={onClose}
/>,
);
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');
});
});
+31 -20
View File
@@ -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({
)}
<div className="modal-action" style={{ flexDirection: 'column', gap: 12 }}>
{apiKeyFirst ? (
{actionButtons.map((action) => (
<button
className="btn btn-primary btn-block"
onClick={() => onChoice('apikey')}
key={action.choice}
className={action.className}
onClick={() => onChoice(action.choice)}
>
添加 API Key(推荐)
{action.label}
</button>
) : (
<button
className="btn btn-primary btn-block"
onClick={() => onChoice('session')}
>
添加账号(用户名密码登录)
</button>
)}
{!apiKeyFirst && (
<button
className="btn btn-outline btn-block"
onClick={() => onChoice('apikey')}
>
添加 API Key
</button>
)}
))}
<button
className="btn btn-ghost btn-block"
onClick={() => onChoice('later')}