mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-30 12:59:55 +00:00
* [feat] Add formatKeySequence function to format keybindings for commands * [feat] Add lock and unlock canvas commands with keybindings and update localization * feat: Implement canvas scale synchronization and zoom level adjustment * feat: Enhance GraphCanvasMenu with zoom controls and improved button functionality * feat: Refactor MiniMap component layout and remove unused bottomPanelStore * feat: Update zoom control shortcuts to use formatted key sequences * feat: Add tests for ZoomControlsModal and enhance GraphCanvasMenu tests * Update locales [skip ci] * Fix browser tests * ui: align minimap properly * Update locales [skip ci] * feat: focus zoom input when zoom modal loads * style: improve styling of zoom controls and add focus effect * fix styling and tests * styling: add divider to graph canvas menu * styling: position minimap properly * styling: add close button for minimap * styling: add horizontal divider to minimap * styling: update minimap toggle button text and remove old styles * Update locales [skip ci] * Update locales [skip ci] * feat: disable canvas menu in viewport settings after zoom adjustments * Update test expectations [skip ci] * fix: update canvas read-only property access to use state object * Update locales [skip ci] * fix: adjust button group and minimap positioning * feat: enhance zoom controls and adjust minimap positioning per PR comments * feat: implement zoom controls composable * feat: add timeout delays for headless tests * fix: update zoom input validation range in applyZoom function * [refactor] Update positioning and styles for GraphCanvasMenu, MiniMap, and ZoomControlsModal components * [refactor] Adjust z-index and positioning for GraphCanvasMenu, MiniMap, and ZoomControlsModal components * [style] Adjust margin for minimap button styles in GraphCanvasMenu component * [refactor] minimap should show on focus mode * [refactor] Update LiteGraphCanvasSplitterOverlay to conditionally render side and bottom panels based on focus mode * [style] Adjust right positioning for MiniMap and ZoomControlsModal components * [style] Adjust right positioning for MiniMap and ZoomControlsModal components --------- Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Christian Byrne <cbyrne@comfy.org>
169 lines
4.6 KiB
TypeScript
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('@/stores/graphStore', () => ({
|
|
useCanvasStore: () => ({
|
|
appScalePercentage: 100,
|
|
setAppZoomFromPercentage: mockSetAppZoom
|
|
})
|
|
}))
|
|
|
|
vi.mock('@/stores/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()
|
|
})
|
|
})
|