From 802088c8ebc06b5a4caff59de372f05343e6fae5 Mon Sep 17 00:00:00 2001 From: yyh Date: Wed, 4 Mar 2026 17:51:20 +0800 Subject: [PATCH] test(web): fix trivial assertion and add useInvalidateDefaultModel tests Replace the no-provider test assertion from checking a nonexistent i18n key to verifying actual warning keys are absent. Add unit tests for useInvalidateDefaultModel following the useUpdateModelList pattern. --- .../model-provider-page/hooks.spec.ts | 33 +++++++++++++++++++ .../model-provider-page/index.spec.tsx | 3 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/web/app/components/header/account-setting/model-provider-page/hooks.spec.ts b/web/app/components/header/account-setting/model-provider-page/hooks.spec.ts index 4908ef52bb..51d70a2218 100644 --- a/web/app/components/header/account-setting/model-provider-page/hooks.spec.ts +++ b/web/app/components/header/account-setting/model-provider-page/hooks.spec.ts @@ -23,6 +23,7 @@ import { useAnthropicBuyQuota, useCurrentProviderAndModel, useDefaultModel, + useInvalidateDefaultModel, useLanguage, useMarketplaceAllPlugins, useModelList, @@ -864,6 +865,38 @@ describe('hooks', () => { }) }) + describe('useInvalidateDefaultModel', () => { + it('should invalidate default model queries', () => { + const invalidateQueries = vi.fn() + ; (useQueryClient as Mock).mockReturnValue({ invalidateQueries }) + + const { result } = renderHook(() => useInvalidateDefaultModel()) + + act(() => { + result.current(ModelTypeEnum.textGeneration) + }) + + expect(invalidateQueries).toHaveBeenCalledWith({ + queryKey: ['default-model', ModelTypeEnum.textGeneration], + }) + }) + + it('should handle multiple model types', () => { + const invalidateQueries = vi.fn() + ; (useQueryClient as Mock).mockReturnValue({ invalidateQueries }) + + const { result } = renderHook(() => useInvalidateDefaultModel()) + + act(() => { + result.current(ModelTypeEnum.textGeneration) + result.current(ModelTypeEnum.textEmbedding) + result.current(ModelTypeEnum.rerank) + }) + + expect(invalidateQueries).toHaveBeenCalledTimes(3) + }) + }) + describe('useAnthropicBuyQuota', () => { beforeEach(() => { Object.defineProperty(window, 'location', { diff --git a/web/app/components/header/account-setting/model-provider-page/index.spec.tsx b/web/app/components/header/account-setting/model-provider-page/index.spec.tsx index 7f1ab81290..feb0a40069 100644 --- a/web/app/components/header/account-setting/model-provider-page/index.spec.tsx +++ b/web/app/components/header/account-setting/model-provider-page/index.spec.tsx @@ -174,7 +174,8 @@ describe('ModelProviderPage', () => { }) render() - expect(screen.queryByText('common.modelProvider.noProviderInstalled')).not.toBeInTheDocument() + expect(screen.queryByText('common.modelProvider.noneConfigured')).not.toBeInTheDocument() + expect(screen.queryByText('common.modelProvider.notConfigured')).not.toBeInTheDocument() expect(screen.getByText('common.modelProvider.emptyProviderTitle')).toBeInTheDocument() })