mirror of
https://github.com/langgenius/dify.git
synced 2026-07-30 08:49:31 +08:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: fatelei <fatelei@gmail.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: 盐粒 Yanli <yanli@dify.ai> Co-authored-by: Charles Yao <chongbinyao33@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: yunlu.wen <yunlu.wen@dify.ai> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com> Co-authored-by: Jingyi <jingyi.qi@dify.ai> Co-authored-by: yyh <yuanyouhuilyz@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: hjlarry <hjlarry@163.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com> Co-authored-by: gigglewang <gigglewang@dify.ai> Co-authored-by: chariri <w@chariri.moe> Co-authored-by: Evan <2869018789@qq.com> Co-authored-by: zyssyz123 <916125788@qq.com>
88 lines
2.2 KiB
TypeScript
88 lines
2.2 KiB
TypeScript
import type { ReactNode } from 'react'
|
|
import type { App } from '@/models/explore'
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
import { renderHook, waitFor } from '@testing-library/react'
|
|
import { AppModeEnum } from '@/types/app'
|
|
import { fetchAppList } from '../explore'
|
|
import { useExploreAppList } from '../use-explore'
|
|
|
|
vi.mock('@/context/i18n', () => ({
|
|
useLocale: () => 'en-US',
|
|
}))
|
|
|
|
vi.mock('../explore', () => ({
|
|
fetchAppList: vi.fn(),
|
|
}))
|
|
|
|
const createWrapper = () => {
|
|
const queryClient = new QueryClient({
|
|
defaultOptions: {
|
|
queries: { retry: false },
|
|
},
|
|
})
|
|
|
|
return ({ children }: { children: ReactNode }) => (
|
|
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
)
|
|
}
|
|
|
|
const createApp = (appId: string, position: number): App => ({
|
|
app: {
|
|
id: appId,
|
|
mode: AppModeEnum.CHAT,
|
|
icon_type: 'emoji',
|
|
icon: 'robot',
|
|
icon_background: '#fff',
|
|
icon_url: '',
|
|
name: appId,
|
|
description: '',
|
|
use_icon_as_answer_icon: false,
|
|
},
|
|
app_id: appId,
|
|
description: '',
|
|
copyright: '',
|
|
privacy_policy: null,
|
|
custom_disclaimer: null,
|
|
categories: [],
|
|
position,
|
|
is_listed: true,
|
|
install_count: 0,
|
|
installed: false,
|
|
editable: false,
|
|
is_agent: false,
|
|
can_trial: false,
|
|
})
|
|
|
|
describe('useExploreAppList', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
vi.mocked(fetchAppList).mockResolvedValue({
|
|
categories: [],
|
|
recommended_apps: [
|
|
createApp('app-2', 2),
|
|
createApp('app-1', 1),
|
|
],
|
|
})
|
|
})
|
|
|
|
// Explore app list can now be disabled by callers.
|
|
describe('Queries', () => {
|
|
it('should not fetch app list when disabled', () => {
|
|
renderHook(() => useExploreAppList({ enabled: false }), { wrapper: createWrapper() })
|
|
|
|
expect(fetchAppList).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('should fetch localized app list and sort recommended apps by position', async () => {
|
|
const { result } = renderHook(() => useExploreAppList({ enabled: true }), { wrapper: createWrapper() })
|
|
|
|
await waitFor(() => {
|
|
expect(fetchAppList).toHaveBeenCalledWith('en-US')
|
|
})
|
|
await waitFor(() => {
|
|
expect(result.current.data?.allList.map(app => app.app_id)).toEqual(['app-1', 'app-2'])
|
|
})
|
|
})
|
|
})
|
|
})
|