diff --git a/web/app/components/snippets/hooks/__tests__/use-create-snippet.spec.tsx b/web/app/components/snippets/hooks/__tests__/use-create-snippet.spec.tsx index 1bcaf75226..64e9f361f6 100644 --- a/web/app/components/snippets/hooks/__tests__/use-create-snippet.spec.tsx +++ b/web/app/components/snippets/hooks/__tests__/use-create-snippet.spec.tsx @@ -6,7 +6,6 @@ const mockPush = vi.fn() const mockMutateAsync = vi.fn() const mockToastSuccess = vi.fn() const mockToastError = vi.fn() -const mockSyncDraftWorkflow = vi.fn() vi.mock('@/next/navigation', () => ({ useRouter: () => ({ push: mockPush }), @@ -19,14 +18,6 @@ vi.mock('@/service/use-snippets', () => ({ }), })) -vi.mock('@/service/client', () => ({ - consoleClient: { - snippets: { - syncDraftWorkflow: (...args: unknown[]) => mockSyncDraftWorkflow(...args), - }, - }, -})) - vi.mock('@langgenius/dify-ui/toast', () => ({ toast: { success: (...args: unknown[]) => mockToastSuccess(...args), @@ -56,9 +47,13 @@ describe('useCreateSnippet', () => { }) describe('Create Flow', () => { - it('should create snippet, sync draft workflow, and navigate on success', async () => { + it('should create snippet with graph and navigate on success', async () => { mockMutateAsync.mockResolvedValue({ id: 'snippet-123' }) - mockSyncDraftWorkflow.mockResolvedValue(undefined) + const graph = { + nodes: [], + edges: [], + viewport: { x: 0, y: 0, zoom: 1 }, + } const { result } = renderHook(() => useCreateSnippet()) @@ -78,11 +73,7 @@ describe('useCreateSnippet', () => { required: true, }, ], - graph: { - nodes: [], - edges: [], - viewport: { x: 0, y: 0, zoom: 1 }, - }, + graph, }) }) @@ -90,6 +81,7 @@ describe('useCreateSnippet', () => { body: { name: 'My snippet', description: 'desc', + graph, input_fields: [ { label: 'topic', @@ -100,24 +92,6 @@ describe('useCreateSnippet', () => { ], }, }) - expect(mockSyncDraftWorkflow).toHaveBeenCalledWith({ - params: { snippetId: 'snippet-123' }, - body: { - input_fields: [ - { - label: 'topic', - variable: 'topic', - type: PipelineInputVarType.textInput, - required: true, - }, - ], - graph: { - nodes: [], - edges: [], - viewport: { x: 0, y: 0, zoom: 1 }, - }, - }, - }) expect(mockToastSuccess).toHaveBeenCalledWith('workflow.snippet.createSuccess') expect(mockPush).toHaveBeenCalledWith('/snippets/snippet-123/orchestrate') expect(result.current.isCreateSnippetDialogOpen).toBe(false) diff --git a/web/app/components/snippets/hooks/use-create-snippet.ts b/web/app/components/snippets/hooks/use-create-snippet.ts index dee4de9388..62b2ff60e0 100644 --- a/web/app/components/snippets/hooks/use-create-snippet.ts +++ b/web/app/components/snippets/hooks/use-create-snippet.ts @@ -3,7 +3,6 @@ import { toast } from '@langgenius/dify-ui/toast' import { useState } from 'react' import { useTranslation } from 'react-i18next' import { useRouter } from '@/next/navigation' -import { consoleClient } from '@/service/client' import { useCreateSnippetMutation } from '@/service/use-snippets' export const useCreateSnippet = () => { @@ -34,15 +33,11 @@ export const useCreateSnippet = () => { body: { name, description: description || undefined, + graph, input_fields, }, }) - await consoleClient.snippets.syncDraftWorkflow({ - params: { snippetId: snippet.id }, - body: { graph, input_fields }, - }) - toast.success(t('snippet.createSuccess', { ns: 'workflow' })) handleCloseCreateSnippetDialog() push(`/snippets/${snippet.id}/orchestrate`) diff --git a/web/types/snippet.ts b/web/types/snippet.ts index 8e022d4227..d96fab5eac 100644 --- a/web/types/snippet.ts +++ b/web/types/snippet.ts @@ -34,6 +34,7 @@ export type CreateSnippetPayload = { name: string description?: string type?: SnippetType + graph?: Record input_fields?: SnippetInputField[] }