From 74e5ac4153f27d8d6815fac5af67b7ca8defa243 Mon Sep 17 00:00:00 2001 From: CodingOnStar Date: Wed, 25 Mar 2026 13:59:52 +0800 Subject: [PATCH] refactor(tests): update toast mock implementation to use new UI toast structure --- .../components/__tests__/user-action.spec.tsx | 9 ++++++--- .../workflow/nodes/start/__tests__/use-config.spec.ts | 11 +++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/web/app/components/workflow/nodes/human-input/components/__tests__/user-action.spec.tsx b/web/app/components/workflow/nodes/human-input/components/__tests__/user-action.spec.tsx index a4111c88ca..af488af817 100644 --- a/web/app/components/workflow/nodes/human-input/components/__tests__/user-action.spec.tsx +++ b/web/app/components/workflow/nodes/human-input/components/__tests__/user-action.spec.tsx @@ -39,10 +39,13 @@ vi.mock('@/app/components/base/button', () => ({ ), })) -vi.mock('@/app/components/base/toast', () => ({ +vi.mock('@/app/components/base/ui/toast', () => ({ __esModule: true, - default: { - notify: (...args: unknown[]) => mockNotify(...args), + toast: { + success: (message: string) => mockNotify({ type: 'success', message }), + error: (message: string) => mockNotify({ type: 'error', message }), + warning: (message: string) => mockNotify({ type: 'warning', message }), + info: (message: string) => mockNotify({ type: 'info', message }), }, })) diff --git a/web/app/components/workflow/nodes/start/__tests__/use-config.spec.ts b/web/app/components/workflow/nodes/start/__tests__/use-config.spec.ts index 6ced0f3511..330b1ac776 100644 --- a/web/app/components/workflow/nodes/start/__tests__/use-config.spec.ts +++ b/web/app/components/workflow/nodes/start/__tests__/use-config.spec.ts @@ -1,7 +1,6 @@ import type { StartNodeType } from '../types' import type { InputVar, ValueSelector } from '@/app/components/workflow/types' import { act, renderHook } from '@testing-library/react' -import Toast from '@/app/components/base/toast' import { BlockEnum, ChangeType, InputVarType } from '@/app/components/workflow/types' import useConfig from '../use-config' @@ -11,6 +10,7 @@ const mockUseWorkflow = vi.hoisted(() => vi.fn()) const mockUseIsChatMode = vi.hoisted(() => vi.fn()) const mockUseNodeCrud = vi.hoisted(() => vi.fn()) const mockUseInspectVarsCrud = vi.hoisted(() => vi.fn()) +const mockNotify = vi.hoisted(() => vi.fn()) vi.mock('react-i18next', () => ({ useTranslation: () => mockUseTranslation(), @@ -32,6 +32,13 @@ vi.mock('@/app/components/workflow/hooks/use-inspect-vars-crud', () => ({ default: (...args: unknown[]) => mockUseInspectVarsCrud(...args), })) +vi.mock('@/app/components/base/ui/toast', () => ({ + __esModule: true, + toast: { + error: (message: string) => mockNotify({ type: 'error', message }), + }, +})) + const createInputVar = (overrides: Partial = {}): InputVar => ({ label: 'Question', variable: 'query', @@ -64,7 +71,7 @@ describe('start/use-config', () => { const mockDeleteNodeInspectorVars = vi.fn() const mockRenameInspectVarName = vi.fn() const mockDeleteInspectVar = vi.fn() - const toastSpy = vi.spyOn(Toast, 'notify').mockImplementation(() => ({})) + const toastSpy = mockNotify let currentInputs: StartNodeType beforeEach(() => {