Fix AI workspace opening over PCB editor on entry

This commit is contained in:
2026-11-05 17:07:20 +08:00
parent 563d55187c
commit a6558811e3
2 changed files with 37 additions and 3 deletions
+13 -3
View File
@@ -92,7 +92,7 @@ export function PcbServiceDock({
}: {
onImport: (bytes: Uint8Array, task: Task) => Promise<void>;
}) {
const [open, setOpen] = useState(true),
const [open, setOpen] = useState(false),
[tasks, setTasks] = useState<Task[]>([]),
[id, setId] = useState<string | null>(() => stored(ACTIVE));
const [queued, setQueued] = useState<Queued | null>(queuedCommand);
@@ -381,11 +381,21 @@ export function PcbServiceDock({
busy = sending || !!pending || !!queued;
return createPortal(
<div className="ze-app pcb-service-root">
<button className="pcb-service-launch" onClick={() => setOpen((v) => !v)}>
<button
className="pcb-service-launch"
aria-expanded={open}
aria-controls="pcb-service-workspace"
onClick={() => setOpen((v) => !v)}
>
AI 自动绘板
</button>
{open && (
<section className="pcb-service-window" role="dialog" aria-label="AI PCB 设计工作台">
<section
id="pcb-service-workspace"
className="pcb-service-window"
role="dialog"
aria-label="AI PCB 设计工作台"
>
<header>
<div>
<strong>AI PCB 设计工作台</strong>
@@ -23,6 +23,7 @@ it('replays a submit interrupted before HTTP 202 using the same request identity
}),
);
const first = render(<PcbServiceDock onImport={async () => {}} />);
fireEvent.click(screen.getByRole('button', { name: 'AI 自动绘板' }));
await waitFor(() =>
expect((screen.getByRole('button', { name: '开始分析' }) as HTMLButtonElement).disabled).toBe(
true,
@@ -39,6 +40,7 @@ it('replays a submit interrupted before HTTP 202 using the same request identity
first.unmount();
render(<PcbServiceDock onImport={async () => {}} />);
await waitFor(() => expect(bodies).toHaveLength(2));
expect(screen.queryByRole('dialog', { name: 'AI PCB 设计工作台' })).toBeNull();
expect(bodies[0]?.request_id).toBeTruthy();
expect(bodies[1]).toEqual(bodies[0]);
});
@@ -60,6 +62,7 @@ it('forgets deleted task and operation references without replaying commands', a
});
vi.stubGlobal('fetch', fetchMock);
render(<PcbServiceDock onImport={async () => {}} />);
fireEvent.click(screen.getByRole('button', { name: 'AI 自动绘板' }));
await waitFor(() => {
expect(localStorage.getItem('vibemake.pcb-service.active')).toBeNull();
expect(localStorage.getItem('vibemake.pcb-service.operation')).toBeNull();
@@ -79,6 +82,7 @@ it('clears the previous requirements when starting a new design', async () => {
new Response(JSON.stringify(path.endsWith('/tasks') ? { items: [] } : {})),
));
render(<PcbServiceDock onImport={async () => {}} />);
fireEvent.click(screen.getByRole('button', { name: 'AI 自动绘板' }));
const input = screen.getByLabelText('PCB 设计需求') as HTMLTextAreaElement;
fireEvent.change(input, { target: { value: '上一次输入的分电板需求' } });
await waitFor(() => expect((screen.getByRole('button', { name: '开始分析' }) as HTMLButtonElement).disabled).toBe(false));
@@ -86,3 +90,23 @@ it('clears the previous requirements when starting a new design', async () => {
expect(input.value).toBe('');
expect((screen.getByRole('button', { name: '开始分析' }) as HTMLButtonElement).disabled).toBe(true);
});
it('starts collapsed and preserves requirements when the user opens, closes and reopens the workspace', async () => {
vi.stubGlobal('fetch', vi.fn(async (path: string) =>
new Response(JSON.stringify(path.endsWith('/tasks') ? { items: [] } : {})),
));
render(<PcbServiceDock onImport={async () => {}} />);
const launcher = screen.getByRole('button', { name: 'AI 自动绘板' });
expect(launcher.getAttribute('aria-expanded')).toBe('false');
expect(screen.queryByRole('dialog', { name: 'AI PCB 设计工作台' })).toBeNull();
fireEvent.click(launcher);
expect(launcher.getAttribute('aria-expanded')).toBe('true');
expect(screen.getByRole('dialog', { name: 'AI PCB 设计工作台' })).toBeTruthy();
fireEvent.change(screen.getByLabelText('PCB 设计需求'), { target: { value: '保留这份 PCB 需求' } });
fireEvent.click(screen.getByRole('button', { name: '关闭 PCB 工作台' }));
expect(screen.queryByRole('dialog', { name: 'AI PCB 设计工作台' })).toBeNull();
expect(launcher.getAttribute('aria-expanded')).toBe('false');
fireEvent.click(launcher);
expect((screen.getByLabelText('PCB 设计需求') as HTMLTextAreaElement).value).toBe('保留这份 PCB 需求');
await waitFor(() => expect((screen.getByRole('button', { name: '开始分析' }) as HTMLButtonElement).disabled).toBe(false));
});