mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-26 19:09:52 +00:00
* 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>
200 lines
5.3 KiB
TypeScript
200 lines
5.3 KiB
TypeScript
import { createPinia, setActivePinia } from 'pinia'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { useCoreCommands } from '@/composables/useCoreCommands'
|
|
import { useSettingStore } from '@/platform/settings/settingStore'
|
|
import { api } from '@/scripts/api'
|
|
import { app } from '@/scripts/app'
|
|
|
|
vi.mock('@/scripts/app', () => {
|
|
const mockGraphClear = vi.fn()
|
|
const mockCanvas = { subgraph: undefined }
|
|
|
|
return {
|
|
app: {
|
|
clean: vi.fn(() => {
|
|
// Simulate app.clean() calling graph.clear() only when not in subgraph
|
|
if (!mockCanvas.subgraph) {
|
|
mockGraphClear()
|
|
}
|
|
}),
|
|
canvas: mockCanvas,
|
|
graph: {
|
|
clear: mockGraphClear
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
vi.mock('@/scripts/api', () => ({
|
|
api: {
|
|
dispatchCustomEvent: vi.fn(),
|
|
apiURL: vi.fn(() => 'http://localhost:8188')
|
|
}
|
|
}))
|
|
|
|
vi.mock('@/platform/settings/settingStore')
|
|
|
|
vi.mock('@/stores/firebaseAuthStore', () => ({
|
|
useFirebaseAuthStore: vi.fn(() => ({}))
|
|
}))
|
|
|
|
vi.mock('@/composables/auth/useFirebaseAuth', () => ({
|
|
useFirebaseAuth: vi.fn(() => null)
|
|
}))
|
|
|
|
vi.mock('firebase/auth', () => ({
|
|
setPersistence: vi.fn(),
|
|
browserLocalPersistence: {},
|
|
onAuthStateChanged: vi.fn()
|
|
}))
|
|
|
|
vi.mock('@/platform/workflow/core/services/workflowService', () => ({
|
|
useWorkflowService: vi.fn(() => ({}))
|
|
}))
|
|
|
|
vi.mock('@/services/dialogService', () => ({
|
|
useDialogService: vi.fn(() => ({}))
|
|
}))
|
|
|
|
vi.mock('@/services/litegraphService', () => ({
|
|
useLitegraphService: vi.fn(() => ({}))
|
|
}))
|
|
|
|
vi.mock('@/stores/executionStore', () => ({
|
|
useExecutionStore: vi.fn(() => ({}))
|
|
}))
|
|
|
|
vi.mock('@/stores/toastStore', () => ({
|
|
useToastStore: vi.fn(() => ({}))
|
|
}))
|
|
|
|
vi.mock('@/platform/workflow/management/stores/workflowStore', () => ({
|
|
useWorkflowStore: vi.fn(() => ({}))
|
|
}))
|
|
|
|
vi.mock('@/stores/subgraphStore', () => ({
|
|
useSubgraphStore: vi.fn(() => ({}))
|
|
}))
|
|
|
|
vi.mock('@/stores/workspace/colorPaletteStore', () => ({
|
|
useColorPaletteStore: vi.fn(() => ({}))
|
|
}))
|
|
|
|
vi.mock('@/composables/auth/useFirebaseAuthActions', () => ({
|
|
useFirebaseAuthActions: vi.fn(() => ({}))
|
|
}))
|
|
|
|
describe('useCoreCommands', () => {
|
|
const mockSubgraph = {
|
|
nodes: [
|
|
// Mock input node
|
|
{
|
|
constructor: { comfyClass: 'SubgraphInputNode' },
|
|
id: 'input1'
|
|
},
|
|
// Mock output node
|
|
{
|
|
constructor: { comfyClass: 'SubgraphOutputNode' },
|
|
id: 'output1'
|
|
},
|
|
// Mock user node
|
|
{
|
|
constructor: { comfyClass: 'SomeUserNode' },
|
|
id: 'user1'
|
|
},
|
|
// Another mock user node
|
|
{
|
|
constructor: { comfyClass: 'AnotherUserNode' },
|
|
id: 'user2'
|
|
}
|
|
],
|
|
remove: vi.fn()
|
|
}
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
|
|
// Set up Pinia
|
|
setActivePinia(createPinia())
|
|
|
|
// Reset app state
|
|
app.canvas.subgraph = undefined
|
|
|
|
// Mock settings store
|
|
vi.mocked(useSettingStore).mockReturnValue({
|
|
get: vi.fn().mockReturnValue(false) // Skip confirmation dialog
|
|
} as any)
|
|
|
|
// Mock global confirm
|
|
global.confirm = vi.fn().mockReturnValue(true)
|
|
})
|
|
|
|
describe('ClearWorkflow command', () => {
|
|
it('should clear main graph when not in subgraph', async () => {
|
|
const commands = useCoreCommands()
|
|
const clearCommand = commands.find(
|
|
(cmd) => cmd.id === 'Comfy.ClearWorkflow'
|
|
)!
|
|
|
|
// Execute the command
|
|
await clearCommand.function()
|
|
|
|
expect(app.clean).toHaveBeenCalled()
|
|
expect(app.graph.clear).toHaveBeenCalled()
|
|
expect(api.dispatchCustomEvent).toHaveBeenCalledWith('graphCleared')
|
|
})
|
|
|
|
it('should preserve input/output nodes when clearing subgraph', async () => {
|
|
// Set up subgraph context
|
|
app.canvas.subgraph = mockSubgraph as any
|
|
|
|
const commands = useCoreCommands()
|
|
const clearCommand = commands.find(
|
|
(cmd) => cmd.id === 'Comfy.ClearWorkflow'
|
|
)!
|
|
|
|
// Execute the command
|
|
await clearCommand.function()
|
|
|
|
expect(app.clean).toHaveBeenCalled()
|
|
expect(app.graph.clear).not.toHaveBeenCalled()
|
|
|
|
// Should only remove user nodes, not input/output nodes
|
|
expect(mockSubgraph.remove).toHaveBeenCalledTimes(2)
|
|
expect(mockSubgraph.remove).toHaveBeenCalledWith(mockSubgraph.nodes[2]) // user1
|
|
expect(mockSubgraph.remove).toHaveBeenCalledWith(mockSubgraph.nodes[3]) // user2
|
|
expect(mockSubgraph.remove).not.toHaveBeenCalledWith(
|
|
mockSubgraph.nodes[0]
|
|
) // input1
|
|
expect(mockSubgraph.remove).not.toHaveBeenCalledWith(
|
|
mockSubgraph.nodes[1]
|
|
) // output1
|
|
|
|
expect(api.dispatchCustomEvent).toHaveBeenCalledWith('graphCleared')
|
|
})
|
|
|
|
it('should respect confirmation setting', async () => {
|
|
// Mock confirmation required
|
|
vi.mocked(useSettingStore).mockReturnValue({
|
|
get: vi.fn().mockReturnValue(true) // Require confirmation
|
|
} as any)
|
|
|
|
global.confirm = vi.fn().mockReturnValue(false) // User cancels
|
|
|
|
const commands = useCoreCommands()
|
|
const clearCommand = commands.find(
|
|
(cmd) => cmd.id === 'Comfy.ClearWorkflow'
|
|
)!
|
|
|
|
// Execute the command
|
|
await clearCommand.function()
|
|
|
|
// Should not clear anything when user cancels
|
|
expect(app.clean).not.toHaveBeenCalled()
|
|
expect(app.graph.clear).not.toHaveBeenCalled()
|
|
expect(api.dispatchCustomEvent).not.toHaveBeenCalled()
|
|
})
|
|
})
|
|
})
|