test(web): add comprehensive unit and integration tests for plugins and tools modules (#32220)

Co-authored-by: CodingOnStar <hanxujiang@dify.com>
This commit is contained in:
Coding On Star
2026-02-12 10:04:56 +08:00
committed by GitHub
parent 10f85074e8
commit d6b025e91e
195 changed files with 12219 additions and 7840 deletions

View File

@@ -31,20 +31,31 @@ export function createTFunction(translations: TranslationMap, defaultNs?: string
/**
* Create useTranslation mock with optional custom translations
*
* Caches t functions by defaultNs so the same reference is returned
* across renders, preventing infinite re-render loops when components
* include t in useEffect/useMemo dependency arrays.
*
* @example
* vi.mock('react-i18next', () => createUseTranslationMock({
* 'operation.confirm': 'Confirm',
* }))
*/
export function createUseTranslationMock(translations: TranslationMap = {}) {
const tCache = new Map<string, ReturnType<typeof createTFunction>>()
const i18n = {
language: 'en',
changeLanguage: vi.fn(),
}
return {
useTranslation: (defaultNs?: string) => ({
t: createTFunction(translations, defaultNs),
i18n: {
language: 'en',
changeLanguage: vi.fn(),
},
}),
useTranslation: (defaultNs?: string) => {
const cacheKey = defaultNs ?? ''
if (!tCache.has(cacheKey))
tCache.set(cacheKey, createTFunction(translations, defaultNs))
return {
t: tCache.get(cacheKey)!,
i18n,
}
},
}
}