fix(design): preserve command outcome certainty
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { fireEvent, render, screen, within } from '@testing-library/react';
|
||||
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { ImageWorkspaceApiError } from '@/lib/image-workspace';
|
||||
import { ImageCanvas } from '@/pages/ImageCanvas';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { useImagePromptMuseumStore } from '@/stores/image-prompt-museum';
|
||||
@@ -11,6 +12,12 @@ import {
|
||||
designWorkspaceFixture,
|
||||
} from '../fixtures/design-workspace-v2';
|
||||
|
||||
const { toastErrorMock } = vi.hoisted(() => ({ toastErrorMock: vi.fn() }));
|
||||
|
||||
vi.mock('sonner', () => ({
|
||||
toast: { error: toastErrorMock, success: vi.fn() },
|
||||
}));
|
||||
|
||||
vi.mock('@/lib/image-workspace', async (importOriginal) => {
|
||||
const original = await importOriginal<typeof import('@/lib/image-workspace')>();
|
||||
return {
|
||||
@@ -138,6 +145,26 @@ describe('youth AI Design Canvas page', () => {
|
||||
expect(actions.sendChat).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('shows the safe reasoner failure instead of claiming the message was not sent', async () => {
|
||||
const { actions } = prepareWorkspace();
|
||||
actions.sendChat.mockRejectedValueOnce(new ImageWorkspaceApiError(
|
||||
502,
|
||||
'design_reasoner_invalid',
|
||||
'AI 没有整理好这次想法,请再试一次',
|
||||
));
|
||||
render(<ImageCanvas />);
|
||||
|
||||
fireEvent.change(screen.getByRole('textbox', { name: '告诉 AI 你想创作什么' }), {
|
||||
target: { value: '画一只会做饭的机器人' },
|
||||
});
|
||||
fireEvent.click(screen.getByRole('button', { name: '发送消息' }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(toastErrorMock).toHaveBeenCalledWith('AI 没有整理好这次想法,请再试一次');
|
||||
});
|
||||
expect(toastErrorMock).not.toHaveBeenCalledWith('消息没有发出去,请再试一次');
|
||||
});
|
||||
|
||||
it('explains an unknown accepted result without suggesting a second production', () => {
|
||||
const { actions } = prepareWorkspace();
|
||||
useImageWorkspaceStore.setState({
|
||||
|
||||
Reference in New Issue
Block a user