mirror of
https://github.com/langgenius/dify.git
synced 2026-02-20 18:04:48 +08:00
Some checks failed
autofix.ci / autofix (push) Has been cancelled
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Has been cancelled
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Has been cancelled
Main CI Pipeline / Check Changed Files (push) Has been cancelled
Main CI Pipeline / Style Check (push) Has been cancelled
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Has been cancelled
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Has been cancelled
Main CI Pipeline / API Tests (push) Has been cancelled
Main CI Pipeline / Web Tests (push) Has been cancelled
Main CI Pipeline / VDB Tests (push) Has been cancelled
Main CI Pipeline / DB Migration Test (push) Has been cancelled
93 lines
2.0 KiB
TypeScript
93 lines
2.0 KiB
TypeScript
import type { Mock } from 'vitest'
|
|
import { render, screen, waitFor } from '@testing-library/react'
|
|
import { useAppContext } from '@/context/app-context'
|
|
import { MediaType } from '@/hooks/use-breakpoints'
|
|
import Explore from '../index'
|
|
|
|
const mockReplace = vi.fn()
|
|
const mockPush = vi.fn()
|
|
const mockInstalledAppsData = { installed_apps: [] as const }
|
|
|
|
vi.mock('next/navigation', () => ({
|
|
useRouter: () => ({
|
|
replace: mockReplace,
|
|
push: mockPush,
|
|
}),
|
|
useSelectedLayoutSegments: () => ['apps'],
|
|
}))
|
|
|
|
vi.mock('@/hooks/use-breakpoints', () => ({
|
|
default: () => MediaType.pc,
|
|
MediaType: {
|
|
mobile: 'mobile',
|
|
tablet: 'tablet',
|
|
pc: 'pc',
|
|
},
|
|
}))
|
|
|
|
vi.mock('@/service/use-explore', () => ({
|
|
useGetInstalledApps: () => ({
|
|
isPending: false,
|
|
data: mockInstalledAppsData,
|
|
}),
|
|
useUninstallApp: () => ({
|
|
mutateAsync: vi.fn(),
|
|
}),
|
|
useUpdateAppPinStatus: () => ({
|
|
mutateAsync: vi.fn(),
|
|
}),
|
|
}))
|
|
|
|
vi.mock('@/context/app-context', () => ({
|
|
useAppContext: vi.fn(),
|
|
}))
|
|
|
|
describe('Explore', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
;(useAppContext as Mock).mockReturnValue({
|
|
isCurrentWorkspaceDatasetOperator: false,
|
|
})
|
|
})
|
|
|
|
describe('Rendering', () => {
|
|
it('should render children', () => {
|
|
render((
|
|
<Explore>
|
|
<div>child</div>
|
|
</Explore>
|
|
))
|
|
|
|
expect(screen.getByText('child')).toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('Effects', () => {
|
|
it('should not redirect dataset operators at component level', async () => {
|
|
;(useAppContext as Mock).mockReturnValue({
|
|
isCurrentWorkspaceDatasetOperator: true,
|
|
})
|
|
|
|
render((
|
|
<Explore>
|
|
<div>child</div>
|
|
</Explore>
|
|
))
|
|
|
|
await waitFor(() => {
|
|
expect(mockReplace).not.toHaveBeenCalled()
|
|
})
|
|
})
|
|
|
|
it('should not redirect non dataset operators', () => {
|
|
render((
|
|
<Explore>
|
|
<div>child</div>
|
|
</Explore>
|
|
))
|
|
|
|
expect(mockReplace).not.toHaveBeenCalled()
|
|
})
|
|
})
|
|
})
|