mirror of https://github.com/langgenius/dify.git
test: update marketplace component tests to use updated translation function with namespace support
This commit is contained in:
parent
678a40d462
commit
3cf07334d1
|
|
@ -10,11 +10,13 @@ import Line from './line'
|
|||
// Mock useMixedTranslation hook
|
||||
vi.mock('../hooks', () => ({
|
||||
useMixedTranslation: (_locale?: string) => ({
|
||||
t: (key: string) => {
|
||||
t: (key: string, options?: { ns?: string }) => {
|
||||
// Build full key with namespace prefix if provided
|
||||
const fullKey = options?.ns ? `${options.ns}.${key}` : key
|
||||
const translations: Record<string, string> = {
|
||||
'plugin.marketplace.noPluginFound': 'No plugin found',
|
||||
}
|
||||
return translations[key] || key
|
||||
return translations[fullKey] || key
|
||||
},
|
||||
}),
|
||||
}))
|
||||
|
|
|
|||
|
|
@ -620,7 +620,7 @@ describe('hooks', () => {
|
|||
const { result } = renderHook(() => useMixedTranslation())
|
||||
|
||||
// The mock returns key as-is
|
||||
expect(result.current.t('plugin.category.all')).toBe('plugin.category.all')
|
||||
expect(result.current.t('category.all', { ns: 'plugin' })).toBe('category.all')
|
||||
})
|
||||
|
||||
it('should use locale from outer when provided', () => {
|
||||
|
|
@ -641,7 +641,7 @@ describe('hooks', () => {
|
|||
it('should use getFixedT when localeFromOuter is provided', () => {
|
||||
const { result } = renderHook(() => useMixedTranslation('fr-FR'))
|
||||
// Should still return a function
|
||||
expect(result.current.t('plugin.search')).toBe('plugin.search')
|
||||
expect(result.current.t('search', { ns: 'plugin' })).toBe('search')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
@ -2758,14 +2758,15 @@ describe('PluginTypeSwitch Component', () => {
|
|||
</MarketplaceContextProvider>,
|
||||
)
|
||||
|
||||
expect(screen.getByText('plugin.category.all')).toBeInTheDocument()
|
||||
expect(screen.getByText('plugin.category.models')).toBeInTheDocument()
|
||||
expect(screen.getByText('plugin.category.tools')).toBeInTheDocument()
|
||||
expect(screen.getByText('plugin.category.datasources')).toBeInTheDocument()
|
||||
expect(screen.getByText('plugin.category.triggers')).toBeInTheDocument()
|
||||
expect(screen.getByText('plugin.category.agents')).toBeInTheDocument()
|
||||
expect(screen.getByText('plugin.category.extensions')).toBeInTheDocument()
|
||||
expect(screen.getByText('plugin.category.bundles')).toBeInTheDocument()
|
||||
// Note: The mock returns the key without namespace prefix
|
||||
expect(screen.getByText('category.all')).toBeInTheDocument()
|
||||
expect(screen.getByText('category.models')).toBeInTheDocument()
|
||||
expect(screen.getByText('category.tools')).toBeInTheDocument()
|
||||
expect(screen.getByText('category.datasources')).toBeInTheDocument()
|
||||
expect(screen.getByText('category.triggers')).toBeInTheDocument()
|
||||
expect(screen.getByText('category.agents')).toBeInTheDocument()
|
||||
expect(screen.getByText('category.extensions')).toBeInTheDocument()
|
||||
expect(screen.getByText('category.bundles')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should apply className prop', () => {
|
||||
|
|
@ -2795,7 +2796,7 @@ describe('PluginTypeSwitch Component', () => {
|
|||
</MarketplaceContextProvider>,
|
||||
)
|
||||
|
||||
fireEvent.click(screen.getByText('plugin.category.tools'))
|
||||
fireEvent.click(screen.getByText('category.tools'))
|
||||
expect(screen.getByTestId('active-type-display')).toHaveTextContent('tool')
|
||||
})
|
||||
|
||||
|
|
@ -2817,7 +2818,7 @@ describe('PluginTypeSwitch Component', () => {
|
|||
)
|
||||
|
||||
fireEvent.click(screen.getByTestId('set-model'))
|
||||
const modelOption = screen.getByText('plugin.category.models').closest('div')
|
||||
const modelOption = screen.getByText('category.models').closest('div')
|
||||
expect(modelOption).toHaveClass('shadow-xs')
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -15,15 +15,17 @@ import ListWrapper from './list-wrapper'
|
|||
// Mock useMixedTranslation hook
|
||||
vi.mock('../hooks', () => ({
|
||||
useMixedTranslation: (_locale?: string) => ({
|
||||
t: (key: string, params?: Record<string, unknown>) => {
|
||||
t: (key: string, options?: { ns?: string, num?: number }) => {
|
||||
// Build full key with namespace prefix if provided
|
||||
const fullKey = options?.ns ? `${options.ns}.${key}` : key
|
||||
const translations: Record<string, string> = {
|
||||
'plugin.marketplace.viewMore': 'View More',
|
||||
'plugin.marketplace.pluginsResult': `${params?.num || 0} plugins found`,
|
||||
'plugin.marketplace.pluginsResult': `${options?.num || 0} plugins found`,
|
||||
'plugin.marketplace.noPluginFound': 'No plugins found',
|
||||
'plugin.detailPanel.operation.install': 'Install',
|
||||
'plugin.detailPanel.operation.detail': 'Detail',
|
||||
}
|
||||
return translations[key] || key
|
||||
return translations[fullKey] || key
|
||||
},
|
||||
}),
|
||||
}))
|
||||
|
|
|
|||
|
|
@ -13,13 +13,15 @@ import ToolSelectorTrigger from './trigger/tool-selector'
|
|||
// Mock useMixedTranslation hook
|
||||
vi.mock('../hooks', () => ({
|
||||
useMixedTranslation: (_locale?: string) => ({
|
||||
t: (key: string) => {
|
||||
t: (key: string, options?: { ns?: string }) => {
|
||||
// Build full key with namespace prefix if provided
|
||||
const fullKey = options?.ns ? `${options.ns}.${key}` : key
|
||||
const translations: Record<string, string> = {
|
||||
'pluginTags.allTags': 'All Tags',
|
||||
'pluginTags.searchTags': 'Search tags',
|
||||
'plugin.searchPlugins': 'Search plugins',
|
||||
}
|
||||
return translations[key] || key
|
||||
return translations[fullKey] || key
|
||||
},
|
||||
}),
|
||||
}))
|
||||
|
|
|
|||
|
|
@ -9,7 +9,9 @@ import SortDropdown from './index'
|
|||
// ================================
|
||||
|
||||
// Mock useMixedTranslation hook
|
||||
const mockTranslation = vi.fn((key: string) => {
|
||||
const mockTranslation = vi.fn((key: string, options?: { ns?: string }) => {
|
||||
// Build full key with namespace prefix if provided
|
||||
const fullKey = options?.ns ? `${options.ns}.${key}` : key
|
||||
const translations: Record<string, string> = {
|
||||
'plugin.marketplace.sortBy': 'Sort by',
|
||||
'plugin.marketplace.sortOption.mostPopular': 'Most Popular',
|
||||
|
|
@ -17,7 +19,7 @@ const mockTranslation = vi.fn((key: string) => {
|
|||
'plugin.marketplace.sortOption.newlyReleased': 'Newly Released',
|
||||
'plugin.marketplace.sortOption.firstReleased': 'First Released',
|
||||
}
|
||||
return translations[key] || key
|
||||
return translations[fullKey] || key
|
||||
})
|
||||
|
||||
vi.mock('../hooks', () => ({
|
||||
|
|
@ -157,7 +159,7 @@ describe('SortDropdown', () => {
|
|||
render(<SortDropdown locale="ja-JP" />)
|
||||
|
||||
// Translation function should be called for labels
|
||||
expect(mockTranslation).toHaveBeenCalledWith('plugin.marketplace.sortBy')
|
||||
expect(mockTranslation).toHaveBeenCalledWith('marketplace.sortBy', { ns: 'plugin' })
|
||||
})
|
||||
|
||||
it('should render without locale prop (undefined)', () => {
|
||||
|
|
@ -605,16 +607,16 @@ describe('SortDropdown', () => {
|
|||
it('should call translation for sortBy label', () => {
|
||||
render(<SortDropdown />)
|
||||
|
||||
expect(mockTranslation).toHaveBeenCalledWith('plugin.marketplace.sortBy')
|
||||
expect(mockTranslation).toHaveBeenCalledWith('marketplace.sortBy', { ns: 'plugin' })
|
||||
})
|
||||
|
||||
it('should call translation for all sort options', () => {
|
||||
render(<SortDropdown />)
|
||||
|
||||
expect(mockTranslation).toHaveBeenCalledWith('plugin.marketplace.sortOption.mostPopular')
|
||||
expect(mockTranslation).toHaveBeenCalledWith('plugin.marketplace.sortOption.recentlyUpdated')
|
||||
expect(mockTranslation).toHaveBeenCalledWith('plugin.marketplace.sortOption.newlyReleased')
|
||||
expect(mockTranslation).toHaveBeenCalledWith('plugin.marketplace.sortOption.firstReleased')
|
||||
expect(mockTranslation).toHaveBeenCalledWith('marketplace.sortOption.mostPopular', { ns: 'plugin' })
|
||||
expect(mockTranslation).toHaveBeenCalledWith('marketplace.sortOption.recentlyUpdated', { ns: 'plugin' })
|
||||
expect(mockTranslation).toHaveBeenCalledWith('marketplace.sortOption.newlyReleased', { ns: 'plugin' })
|
||||
expect(mockTranslation).toHaveBeenCalledWith('marketplace.sortOption.firstReleased', { ns: 'plugin' })
|
||||
})
|
||||
|
||||
it('should pass locale to useMixedTranslation', () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue