mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 06:20:11 +00:00
## Summary Enforced test file naming conventions with ESLint rules and renamed 26 test files from `.spec.ts` to `.test.ts`. ## Changes - **What**: Added ESLint rules to enforce `.spec.ts` files only in `browser_tests/tests/` and `.test.ts` files only in `src/` - **What**: Renamed 26 component/unit test files from `.spec.ts` to `.test.ts` to comply with new convention ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-5820-enforce-test-file-naming-rule-27b6d73d365081269b32ddcc9d3a5048) by [Unito](https://www.unito.io)
150 lines
4.0 KiB
TypeScript
150 lines
4.0 KiB
TypeScript
import { mount } from '@vue/test-utils'
|
|
import { createPinia, setActivePinia } from 'pinia'
|
|
import PrimeVue from 'primevue/config'
|
|
import Tooltip from 'primevue/tooltip'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { createI18n } from 'vue-i18n'
|
|
|
|
import InfoButton from '@/components/graph/selectionToolbox/InfoButton.vue'
|
|
// NOTE: The component import must come after mocks so they take effect.
|
|
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
|
|
import { useNodeDefStore } from '@/stores/nodeDefStore'
|
|
|
|
const mockLGraphNode = {
|
|
type: 'TestNode',
|
|
title: 'Test Node'
|
|
}
|
|
|
|
vi.mock('@/utils/litegraphUtil', () => ({
|
|
isLGraphNode: vi.fn(() => true)
|
|
}))
|
|
|
|
vi.mock('@/composables/sidebarTabs/useNodeLibrarySidebarTab', () => ({
|
|
useNodeLibrarySidebarTab: () => ({
|
|
id: 'node-library'
|
|
})
|
|
}))
|
|
|
|
const openHelpMock = vi.fn()
|
|
const closeHelpMock = vi.fn()
|
|
const nodeHelpState: { currentHelpNode: any } = { currentHelpNode: null }
|
|
vi.mock('@/stores/workspace/nodeHelpStore', () => ({
|
|
useNodeHelpStore: () => ({
|
|
openHelp: (def: any) => {
|
|
nodeHelpState.currentHelpNode = def
|
|
openHelpMock(def)
|
|
},
|
|
closeHelp: () => {
|
|
nodeHelpState.currentHelpNode = null
|
|
closeHelpMock()
|
|
},
|
|
get currentHelpNode() {
|
|
return nodeHelpState.currentHelpNode
|
|
},
|
|
get isHelpOpen() {
|
|
return nodeHelpState.currentHelpNode !== null
|
|
}
|
|
})
|
|
}))
|
|
|
|
const toggleSidebarTabMock = vi.fn((id: string) => {
|
|
sidebarState.activeSidebarTabId =
|
|
sidebarState.activeSidebarTabId === id ? null : id
|
|
})
|
|
const sidebarState: { activeSidebarTabId: string | null } = {
|
|
activeSidebarTabId: 'other-tab'
|
|
}
|
|
vi.mock('@/stores/workspace/sidebarTabStore', () => ({
|
|
useSidebarTabStore: () => ({
|
|
get activeSidebarTabId() {
|
|
return sidebarState.activeSidebarTabId
|
|
},
|
|
toggleSidebarTab: toggleSidebarTabMock
|
|
})
|
|
}))
|
|
|
|
describe('InfoButton', () => {
|
|
let canvasStore: ReturnType<typeof useCanvasStore>
|
|
let nodeDefStore: ReturnType<typeof useNodeDefStore>
|
|
|
|
const i18n = createI18n({
|
|
legacy: false,
|
|
locale: 'en',
|
|
messages: {
|
|
en: {
|
|
g: {
|
|
info: 'Node Info'
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
beforeEach(() => {
|
|
setActivePinia(createPinia())
|
|
canvasStore = useCanvasStore()
|
|
nodeDefStore = useNodeDefStore()
|
|
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
const mountComponent = () => {
|
|
return mount(InfoButton, {
|
|
global: {
|
|
plugins: [i18n, PrimeVue],
|
|
directives: { tooltip: Tooltip },
|
|
stubs: {
|
|
'i-lucide:info': true,
|
|
Button: {
|
|
template:
|
|
'<button class="help-button" severity="secondary"><slot /></button>',
|
|
props: ['severity', 'text', 'class'],
|
|
emits: ['click']
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
it('should handle click without errors', async () => {
|
|
const mockNodeDef = {
|
|
nodePath: 'test/node',
|
|
display_name: 'Test Node'
|
|
}
|
|
canvasStore.selectedItems = [mockLGraphNode] as any
|
|
vi.spyOn(nodeDefStore, 'fromLGraphNode').mockReturnValue(mockNodeDef as any)
|
|
const wrapper = mountComponent()
|
|
const button = wrapper.find('button')
|
|
await button.trigger('click')
|
|
expect(button.exists()).toBe(true)
|
|
})
|
|
|
|
it('should have correct CSS classes', () => {
|
|
const mockNodeDef = {
|
|
nodePath: 'test/node',
|
|
display_name: 'Test Node'
|
|
}
|
|
canvasStore.selectedItems = [mockLGraphNode] as any
|
|
vi.spyOn(nodeDefStore, 'fromLGraphNode').mockReturnValue(mockNodeDef as any)
|
|
|
|
const wrapper = mountComponent()
|
|
const button = wrapper.find('button')
|
|
|
|
expect(button.classes()).toContain('help-button')
|
|
expect(button.attributes('severity')).toBe('secondary')
|
|
})
|
|
|
|
it('should have correct tooltip', () => {
|
|
const mockNodeDef = {
|
|
nodePath: 'test/node',
|
|
display_name: 'Test Node'
|
|
}
|
|
canvasStore.selectedItems = [mockLGraphNode] as any
|
|
vi.spyOn(nodeDefStore, 'fromLGraphNode').mockReturnValue(mockNodeDef as any)
|
|
|
|
const wrapper = mountComponent()
|
|
const button = wrapper.find('button')
|
|
|
|
expect(button.exists()).toBe(true)
|
|
})
|
|
})
|