From 3cf07334d132f83cb735cb3018a8d7f9dbb878b1 Mon Sep 17 00:00:00 2001 From: CodingOnStar Date: Mon, 29 Dec 2025 17:18:08 +0800 Subject: [PATCH] test: update marketplace component tests to use updated translation function with namespace support --- .../plugins/marketplace/empty/index.spec.tsx | 6 +++-- .../plugins/marketplace/index.spec.tsx | 25 ++++++++++--------- .../plugins/marketplace/list/index.spec.tsx | 8 +++--- .../marketplace/search-box/index.spec.tsx | 6 +++-- .../marketplace/sort-dropdown/index.spec.tsx | 18 +++++++------ 5 files changed, 36 insertions(+), 27 deletions(-) diff --git a/web/app/components/plugins/marketplace/empty/index.spec.tsx b/web/app/components/plugins/marketplace/empty/index.spec.tsx index f9feced7bc..4cbc85a309 100644 --- a/web/app/components/plugins/marketplace/empty/index.spec.tsx +++ b/web/app/components/plugins/marketplace/empty/index.spec.tsx @@ -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 = { 'plugin.marketplace.noPluginFound': 'No plugin found', } - return translations[key] || key + return translations[fullKey] || key }, }), })) diff --git a/web/app/components/plugins/marketplace/index.spec.tsx b/web/app/components/plugins/marketplace/index.spec.tsx index 75a6413f8e..9cfac94ccd 100644 --- a/web/app/components/plugins/marketplace/index.spec.tsx +++ b/web/app/components/plugins/marketplace/index.spec.tsx @@ -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', () => { , ) - 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', () => { , ) - 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') }) }) diff --git a/web/app/components/plugins/marketplace/list/index.spec.tsx b/web/app/components/plugins/marketplace/list/index.spec.tsx index 862e55cc67..e367f8fb6a 100644 --- a/web/app/components/plugins/marketplace/list/index.spec.tsx +++ b/web/app/components/plugins/marketplace/list/index.spec.tsx @@ -15,15 +15,17 @@ import ListWrapper from './list-wrapper' // Mock useMixedTranslation hook vi.mock('../hooks', () => ({ useMixedTranslation: (_locale?: string) => ({ - t: (key: string, params?: Record) => { + 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 = { '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 }, }), })) diff --git a/web/app/components/plugins/marketplace/search-box/index.spec.tsx b/web/app/components/plugins/marketplace/search-box/index.spec.tsx index 66feeb3fe1..8c3131f6d1 100644 --- a/web/app/components/plugins/marketplace/search-box/index.spec.tsx +++ b/web/app/components/plugins/marketplace/search-box/index.spec.tsx @@ -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 = { 'pluginTags.allTags': 'All Tags', 'pluginTags.searchTags': 'Search tags', 'plugin.searchPlugins': 'Search plugins', } - return translations[key] || key + return translations[fullKey] || key }, }), })) diff --git a/web/app/components/plugins/marketplace/sort-dropdown/index.spec.tsx b/web/app/components/plugins/marketplace/sort-dropdown/index.spec.tsx index 1bc52568f9..d42d4fbbf3 100644 --- a/web/app/components/plugins/marketplace/sort-dropdown/index.spec.tsx +++ b/web/app/components/plugins/marketplace/sort-dropdown/index.spec.tsx @@ -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 = { '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() // 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() - expect(mockTranslation).toHaveBeenCalledWith('plugin.marketplace.sortBy') + expect(mockTranslation).toHaveBeenCalledWith('marketplace.sortBy', { ns: 'plugin' }) }) it('should call translation for all sort options', () => { render() - 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', () => {