Files
ComfyUI_frontend/tests-ui/tests/components/graph/ZoomControlsModal.spec.ts
Christian Byrne 4c8c4a1ad4 [refactor] Improve settings domain organization (#5550)
* refactor: move settingStore to platform/settings

Move src/stores/settingStore.ts to src/platform/settings/settingStore.ts
to separate platform infrastructure from domain logic following DDD principles.

Updates all import references across ~70 files to maintain compatibility.

* fix: update remaining settingStore imports after rebase

* fix: complete remaining settingStore import updates

* fix: update vi.mock paths for settingStore in tests

Update all test files to mock the new settingStore location at
@/platform/settings/settingStore instead of @/stores/settingStore

* fix: resolve remaining settingStore imports and unused imports after rebase

* fix: update settingStore mock path in SelectionToolbox test

Fix vi.mock path from @/stores/settingStore to @/platform/settings/settingStore
to resolve failing Load3D viewer button test.

* refactor: complete comprehensive settings migration to platform layer

This commit completes the migration of all settings-related code to the platform layer
as part of the Domain-Driven Design (DDD) architecture refactoring.

- constants/coreSettings.ts → platform/settings/constants/coreSettings.ts
- types/settingTypes.ts → platform/settings/types.ts
- stores/settingStore.ts → platform/settings/settingStore.ts (already moved)

- composables/setting/useSettingUI.ts → platform/settings/composables/useSettingUI.ts
- composables/setting/useSettingSearch.ts → platform/settings/composables/useSettingSearch.ts
- composables/useLitegraphSettings.ts → platform/settings/composables/useLitegraphSettings.ts

- components/dialog/content/SettingDialogContent.vue → platform/settings/components/SettingDialogContent.vue
- components/dialog/content/setting/SettingItem.vue → platform/settings/components/SettingItem.vue
- components/dialog/content/setting/SettingGroup.vue → platform/settings/components/SettingGroup.vue
- components/dialog/content/setting/SettingsPanel.vue → platform/settings/components/SettingsPanel.vue
- components/dialog/content/setting/ColorPaletteMessage.vue → platform/settings/components/ColorPaletteMessage.vue
- components/dialog/content/setting/ExtensionPanel.vue → platform/settings/components/ExtensionPanel.vue
- components/dialog/content/setting/ServerConfigPanel.vue → platform/settings/components/ServerConfigPanel.vue

- ~100+ import statements updated across the codebase
- Test file imports corrected
- Component imports fixed in dialog service and command menubar
- Composable imports updated in GraphCanvas.vue

```
src/platform/settings/
├── components/          # All settings UI components
├── composables/         # Settings-related composables
├── constants/          # Core settings definitions
├── types.ts           # Settings type definitions
└── settingStore.ts    # Central settings state management
```

 TypeScript compilation successful
 All tests passing (settings store, search functionality, UI components)
 Production build successful
 Domain boundaries properly established

This migration consolidates all settings functionality into a cohesive platform domain,
improving maintainability and following DDD principles for better code organization.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: format and lint after rebase conflict resolution

* fix: update remaining import paths to platform settings

- Fix browser test import: extensionAPI.spec.ts
- Fix script import: collect-i18n-general.ts
- Complete settings migration import path updates

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-09-15 03:53:08 -07:00

169 lines
4.6 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
// Mock functions
const mockExecute = vi.fn()
const mockGetCommand = vi.fn().mockReturnValue({
keybinding: {
combo: {
getKeySequences: () => ['Ctrl', '+']
}
}
})
const mockFormatKeySequence = vi.fn().mockReturnValue('Ctrl+')
const mockSetAppZoom = vi.fn()
const mockSettingGet = vi.fn().mockReturnValue(true)
// Mock dependencies
vi.mock('@/renderer/extensions/minimap/composables/useMinimap', () => ({
useMinimap: () => ({
containerStyles: { value: { backgroundColor: '#fff', borderRadius: '8px' } }
})
}))
vi.mock('@/stores/commandStore', () => ({
useCommandStore: () => ({
execute: mockExecute,
getCommand: mockGetCommand,
formatKeySequence: mockFormatKeySequence
})
}))
vi.mock('@/renderer/core/canvas/canvasStore', () => ({
useCanvasStore: () => ({
appScalePercentage: 100,
setAppZoomFromPercentage: mockSetAppZoom
})
}))
vi.mock('@/platform/settings/settingStore', () => ({
useSettingStore: () => ({
get: mockSettingGet
})
}))
describe('ZoomControlsModal', () => {
it('should have proper props interface', () => {
// Test that the component file structure and basic exports work
expect(mockExecute).toBeDefined()
expect(mockGetCommand).toBeDefined()
expect(mockFormatKeySequence).toBeDefined()
expect(mockSetAppZoom).toBeDefined()
expect(mockSettingGet).toBeDefined()
})
it('should call command store execute when executeCommand is invoked', () => {
mockExecute.mockClear()
// Simulate the executeCommand function behavior
const executeCommand = (command: string) => {
mockExecute(command)
}
executeCommand('Comfy.Canvas.FitView')
expect(mockExecute).toHaveBeenCalledWith('Comfy.Canvas.FitView')
})
it('should validate zoom input ranges correctly', () => {
mockSetAppZoom.mockClear()
// Simulate the applyZoom function behavior
const applyZoom = (val: { value: number }) => {
const inputValue = val.value as number
if (isNaN(inputValue) || inputValue < 1 || inputValue > 1000) {
return
}
mockSetAppZoom(inputValue)
}
// Test invalid values
applyZoom({ value: 0 })
applyZoom({ value: 1010 })
applyZoom({ value: NaN })
expect(mockSetAppZoom).not.toHaveBeenCalled()
// Test valid value
applyZoom({ value: 50 })
expect(mockSetAppZoom).toHaveBeenCalledWith(50)
})
it('should return correct minimap toggle text based on setting', () => {
const t = (key: string) => {
const translations: Record<string, string> = {
'zoomControls.showMinimap': 'Show Minimap',
'zoomControls.hideMinimap': 'Hide Minimap'
}
return translations[key] || key
}
// Simulate the minimapToggleText computed property
const minimapToggleText = () =>
mockSettingGet('Comfy.Minimap.Visible')
? t('zoomControls.hideMinimap')
: t('zoomControls.showMinimap')
// Test when minimap is visible
mockSettingGet.mockReturnValue(true)
expect(minimapToggleText()).toBe('Hide Minimap')
// Test when minimap is hidden
mockSettingGet.mockReturnValue(false)
expect(minimapToggleText()).toBe('Show Minimap')
})
it('should format keyboard shortcuts correctly', () => {
mockFormatKeySequence.mockReturnValue('Ctrl+')
expect(mockFormatKeySequence()).toBe('Ctrl+')
expect(mockGetCommand).toBeDefined()
})
it('should handle repeat command functionality', () => {
mockExecute.mockClear()
let interval: number | null = null
// Simulate the repeat functionality
const startRepeat = (command: string) => {
if (interval) return
const cmd = () => mockExecute(command)
cmd() // Execute immediately
interval = 1 // Mock interval ID
}
const stopRepeat = () => {
if (interval) {
interval = null
}
}
startRepeat('Comfy.Canvas.ZoomIn')
expect(mockExecute).toHaveBeenCalledWith('Comfy.Canvas.ZoomIn')
stopRepeat()
expect(interval).toBeNull()
})
it('should have proper filteredMinimapStyles computed property', () => {
const mockContainerStyles = {
backgroundColor: '#fff',
borderRadius: '8px',
height: '100px',
width: '200px'
}
// Simulate the filteredMinimapStyles computed property
const filteredMinimapStyles = () => {
return {
...mockContainerStyles,
height: undefined,
width: undefined
}
}
const result = filteredMinimapStyles()
expect(result.backgroundColor).toBe('#fff')
expect(result.borderRadius).toBe('8px')
expect(result.height).toBeUndefined()
expect(result.width).toBeUndefined()
})
})