From 70fd4a5c88b8a55cd9f42a6549de3d70e595e31d Mon Sep 17 00:00:00 2001 From: JzoNg Date: Tue, 28 Apr 2026 16:26:39 +0800 Subject: [PATCH] feat(web): support snippet nav --- .../header/app-nav/__tests__/index.spec.tsx | 216 ++++++++++++++++- web/app/components/header/app-nav/index.tsx | 217 +++++++++++++----- web/app/components/header/nav/index.tsx | 3 +- .../snippets/components/snippet-card.tsx | 2 +- 4 files changed, 375 insertions(+), 63 deletions(-) diff --git a/web/app/components/header/app-nav/__tests__/index.spec.tsx b/web/app/components/header/app-nav/__tests__/index.spec.tsx index 03f8edfacf..e7b546a589 100644 --- a/web/app/components/header/app-nav/__tests__/index.spec.tsx +++ b/web/app/components/header/app-nav/__tests__/index.spec.tsx @@ -2,13 +2,16 @@ import { render, screen, waitFor } from '@testing-library/react' import userEvent from '@testing-library/user-event' import { useStore as useAppStore } from '@/app/components/app/store' import { useAppContext } from '@/context/app-context' -import { useParams } from '@/next/navigation' +import { useParams, usePathname, useRouter } from '@/next/navigation' import { useInfiniteAppList } from '@/service/use-apps' +import { useCreateSnippetMutation, useInfiniteSnippetList, useSnippetApiDetail } from '@/service/use-snippets' import { AppModeEnum } from '@/types/app' import AppNav from '../index' vi.mock('@/next/navigation', () => ({ useParams: vi.fn(), + usePathname: vi.fn(), + useRouter: vi.fn(), })) vi.mock('react-i18next', () => ({ @@ -29,6 +32,19 @@ vi.mock('@/service/use-apps', () => ({ useInfiniteAppList: vi.fn(), })) +vi.mock('@/service/use-snippets', () => ({ + useCreateSnippetMutation: vi.fn(), + useInfiniteSnippetList: vi.fn(), + useSnippetApiDetail: vi.fn(), +})) + +vi.mock('@langgenius/dify-ui/toast', () => ({ + toast: { + error: vi.fn(), + success: vi.fn(), + }, +})) + vi.mock('@/app/components/app/create-app-dialog', () => ({ default: ({ show, onClose, onSuccess }: { show: boolean, onClose: () => void, onSuccess: () => void }) => show @@ -83,17 +99,67 @@ vi.mock('@/app/components/app/create-from-dsl-modal', () => ({ : null, })) +vi.mock('@/app/components/workflow/create-snippet-dialog', () => ({ + default: ({ + isOpen, + onClose, + onConfirm, + }: { + isOpen: boolean + onClose: () => void + onConfirm: (payload: { + name: string + description: string + icon: { type: 'emoji', icon: string, background: string } + }) => void + }) => + isOpen + ? ( + + ) + : null, +})) + vi.mock('../../nav', () => ({ default: ({ + createText, + curNav, + isApp, + link, onCreate, onLoadMore, navigationItems, }: { + createText: string + curNav?: { id: string, name: string } + isApp?: boolean + link: string onCreate: (state: string) => void onLoadMore?: () => void navigationItems?: Array<{ id: string, name: string, link: string }> }) => (
+
{link}
+
{String(isApp)}
+
{createText}
+
{curNav ? `${curNav.id}:${curNav.name}` : ''}