import type { AutoUpdateConfig } from './auto-update-setting/types' import type { Permissions, ReferenceSetting } from '@/app/components/plugins/types' import { fireEvent, render, screen, waitFor } from '@testing-library/react' import * as React from 'react' import { beforeEach, describe, expect, it, vi } from 'vitest' import { PermissionType } from '@/app/components/plugins/types' import { AUTO_UPDATE_MODE, AUTO_UPDATE_STRATEGY } from './auto-update-setting/types' import ReferenceSettingModal from './index' import Label from './label' // ================================ // Mock External Dependencies Only // ================================ // Mock react-i18next vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string, options?: { ns?: string }) => { const translations: Record = { 'privilege.title': 'Plugin Permissions', 'privilege.whoCanInstall': 'Who can install plugins', 'privilege.whoCanDebug': 'Who can debug plugins', 'privilege.everyone': 'Everyone', 'privilege.admins': 'Admins Only', 'privilege.noone': 'No One', 'operation.cancel': 'Cancel', 'operation.save': 'Save', 'autoUpdate.updateSettings': 'Update Settings', } const fullKey = options?.ns ? `${options.ns}.${key}` : key return translations[fullKey] || translations[key] || key }, }), })) // Mock global public store const mockSystemFeatures = { enable_marketplace: true } vi.mock('@/context/global-public-context', () => ({ useGlobalPublicStore: (selector: (s: { systemFeatures: typeof mockSystemFeatures }) => typeof mockSystemFeatures) => { return selector({ systemFeatures: mockSystemFeatures }) }, })) // Mock Modal component vi.mock('@/app/components/base/modal', () => ({ default: ({ children, isShow, onClose, closable, className }: { children: React.ReactNode isShow: boolean onClose: () => void closable?: boolean className?: string }) => { if (!isShow) return null return (
{closable && ( )} {children}
) }, })) // Mock OptionCard component vi.mock('@/app/components/workflow/nodes/_base/components/option-card', () => ({ default: ({ title, onSelect, selected, className }: { title: string onSelect: () => void selected: boolean className?: string }) => ( ), })) // Mock AutoUpdateSetting component const mockAutoUpdateSettingOnChange = vi.fn() vi.mock('./auto-update-setting', () => ({ default: ({ payload, onChange }: { payload: AutoUpdateConfig onChange: (payload: AutoUpdateConfig) => void }) => { mockAutoUpdateSettingOnChange.mockImplementation(onChange) return (
{payload.strategy_setting} {payload.upgrade_mode}
) }, })) // Mock config default value vi.mock('./auto-update-setting/config', () => ({ defaultValue: { strategy_setting: AUTO_UPDATE_STRATEGY.disabled, upgrade_time_of_day: 0, upgrade_mode: AUTO_UPDATE_MODE.update_all, exclude_plugins: [], include_plugins: [], }, })) // ================================ // Test Data Factories // ================================ const createMockPermissions = (overrides: Partial = {}): Permissions => ({ install_permission: PermissionType.everyone, debug_permission: PermissionType.admin, ...overrides, }) const createMockAutoUpdateConfig = (overrides: Partial = {}): AutoUpdateConfig => ({ strategy_setting: AUTO_UPDATE_STRATEGY.fixOnly, upgrade_time_of_day: 36000, upgrade_mode: AUTO_UPDATE_MODE.update_all, exclude_plugins: [], include_plugins: [], ...overrides, }) const createMockReferenceSetting = (overrides: Partial = {}): ReferenceSetting => ({ permission: createMockPermissions(), auto_upgrade: createMockAutoUpdateConfig(), ...overrides, }) // ================================ // Test Suites // ================================ describe('reference-setting-modal', () => { beforeEach(() => { vi.clearAllMocks() mockSystemFeatures.enable_marketplace = true }) // ============================================================ // Label Component Tests // ============================================================ describe('Label (label.tsx)', () => { describe('Rendering', () => { it('should render label text', () => { // Arrange & Act render(