mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-11 16:10:05 +00:00
## Summary Redesigned node search with categories ## Changes - **What**: Adds a v2 search component, leaving the existing implementation untouched - It also brings onboard the incomplete node library & preview changes, disabled and behind a hidden setting - **Breaking**: Changes the 'default' value of the node search setting to v2, adding v1 (legacy) as an option ## Screenshots (if applicable) https://github.com/user-attachments/assets/2ab797df-58f0-48e8-8b20-2a1809e3735f ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8987-V2-Node-Search-hidden-Node-Library-changes-30c6d73d36508160902bcb92553f147c) by [Unito](https://www.unito.io) --------- Co-authored-by: Yourz <crazilou@vip.qq.com> Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: GitHub Action <action@github.com> Co-authored-by: Christian Byrne <cbyrne@comfy.org>
133 lines
3.3 KiB
TypeScript
133 lines
3.3 KiB
TypeScript
import { mount } from '@vue/test-utils'
|
|
import { createTestingPinia } from '@pinia/testing'
|
|
import { TabsContent, TabsList, TabsRoot, TabsTrigger } from 'reka-ui'
|
|
import { ref } from 'vue'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { createI18n } from 'vue-i18n'
|
|
|
|
import NodeLibrarySidebarTabV2 from './NodeLibrarySidebarTabV2.vue'
|
|
|
|
vi.mock('@vueuse/core', async () => {
|
|
const actual = await vi.importActual('@vueuse/core')
|
|
return {
|
|
...actual,
|
|
useLocalStorage: vi.fn((_key: string, defaultValue: unknown) =>
|
|
ref(defaultValue)
|
|
)
|
|
}
|
|
})
|
|
|
|
vi.mock('@/composables/node/useNodeDragToCanvas', () => ({
|
|
useNodeDragToCanvas: () => ({
|
|
isDragging: { value: false },
|
|
draggedNode: { value: null },
|
|
cursorPosition: { value: { x: 0, y: 0 } },
|
|
startDrag: vi.fn(),
|
|
cancelDrag: vi.fn(),
|
|
setupGlobalListeners: vi.fn(),
|
|
cleanupGlobalListeners: vi.fn()
|
|
})
|
|
}))
|
|
|
|
vi.mock('@/services/nodeOrganizationService', () => ({
|
|
DEFAULT_TAB_ID: 'essentials',
|
|
DEFAULT_SORTING_ID: 'alphabetical',
|
|
nodeOrganizationService: {
|
|
organizeNodesByTab: vi.fn(() => []),
|
|
getSortingStrategies: vi.fn(() => [])
|
|
}
|
|
}))
|
|
|
|
vi.mock('./nodeLibrary/AllNodesPanel.vue', () => ({
|
|
default: {
|
|
name: 'AllNodesPanel',
|
|
template: '<div data-testid="all-panel"><slot /></div>',
|
|
props: ['sections', 'expandedKeys', 'fillNodeInfo']
|
|
}
|
|
}))
|
|
|
|
vi.mock('./nodeLibrary/CustomNodesPanel.vue', () => ({
|
|
default: {
|
|
name: 'CustomNodesPanel',
|
|
template: '<div data-testid="custom-panel"><slot /></div>',
|
|
props: ['sections', 'expandedKeys']
|
|
}
|
|
}))
|
|
|
|
vi.mock('./nodeLibrary/EssentialNodesPanel.vue', () => ({
|
|
default: {
|
|
name: 'EssentialNodesPanel',
|
|
template: '<div data-testid="essential-panel"><slot /></div>',
|
|
props: ['root', 'expandedKeys']
|
|
}
|
|
}))
|
|
|
|
vi.mock('./nodeLibrary/NodeDragPreview.vue', () => ({
|
|
default: {
|
|
name: 'NodeDragPreview',
|
|
template: '<div />'
|
|
}
|
|
}))
|
|
|
|
vi.mock('@/components/common/SearchBoxV2.vue', () => ({
|
|
default: {
|
|
name: 'SearchBox',
|
|
template: '<input data-testid="search-box" />',
|
|
props: ['modelValue', 'placeholder'],
|
|
setup() {
|
|
return { focus: vi.fn() }
|
|
},
|
|
expose: ['focus']
|
|
}
|
|
}))
|
|
|
|
const i18n = createI18n({
|
|
legacy: false,
|
|
locale: 'en',
|
|
messages: { en: {} }
|
|
})
|
|
|
|
describe('NodeLibrarySidebarTabV2', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
function mountComponent() {
|
|
return mount(NodeLibrarySidebarTabV2, {
|
|
global: {
|
|
plugins: [createTestingPinia({ stubActions: false }), i18n],
|
|
components: {
|
|
TabsRoot,
|
|
TabsList,
|
|
TabsTrigger,
|
|
TabsContent
|
|
},
|
|
stubs: {
|
|
teleport: true
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
it('should render with tabs', () => {
|
|
const wrapper = mountComponent()
|
|
|
|
const triggers = wrapper.findAllComponents(TabsTrigger)
|
|
expect(triggers.length).toBe(3)
|
|
})
|
|
|
|
it('should render search box', () => {
|
|
const wrapper = mountComponent()
|
|
|
|
expect(wrapper.find('[data-testid="search-box"]').exists()).toBe(true)
|
|
})
|
|
|
|
it('should render only the selected panel', () => {
|
|
const wrapper = mountComponent()
|
|
|
|
expect(wrapper.find('[data-testid="essential-panel"]').exists()).toBe(true)
|
|
expect(wrapper.find('[data-testid="all-panel"]').exists()).toBe(false)
|
|
expect(wrapper.find('[data-testid="custom-panel"]').exists()).toBe(false)
|
|
})
|
|
})
|