mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-30 12:59:55 +00:00
## Summary See https://typescript-eslint.io/blog/project-service/ for context. Creates a browser_tests specific tsconfig so that they can be linted. Does not add a package.json script to do the linting yet, but `pnpm exec eslint browser_tests` should work for now. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-5633-lint-add-tsconfig-for-browser_tests-fix-existing-violations-2726d73d3650819d8ef2c4b0abc31e14) by [Unito](https://www.unito.io)
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { useNodeChatHistory } from '@/composables/node/useNodeChatHistory'
|
|
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
|
|
|
|
vi.mock(
|
|
'@/renderer/extensions/vueNodes/widgets/composables/useChatHistoryWidget',
|
|
() => ({
|
|
useChatHistoryWidget: () => {
|
|
return (node: any, inputSpec: any) => {
|
|
const widget = {
|
|
name: inputSpec.name,
|
|
type: inputSpec.type
|
|
}
|
|
|
|
if (!node.widgets) {
|
|
node.widgets = []
|
|
}
|
|
node.widgets.push(widget)
|
|
|
|
return widget
|
|
}
|
|
}
|
|
})
|
|
)
|
|
|
|
// Mock LGraphNode type
|
|
type MockNode = {
|
|
widgets: Array<{ name: string; type: string }>
|
|
setDirtyCanvas: ReturnType<typeof vi.fn>
|
|
addCustomWidget: ReturnType<typeof vi.fn>
|
|
[key: string]: any
|
|
}
|
|
|
|
describe('useNodeChatHistory', () => {
|
|
const mockNode = {
|
|
widgets: [],
|
|
setDirtyCanvas: vi.fn(),
|
|
addCustomWidget: vi.fn()
|
|
} as unknown as LGraphNode & MockNode
|
|
|
|
beforeEach(() => {
|
|
mockNode.widgets = []
|
|
mockNode.setDirtyCanvas.mockClear()
|
|
mockNode.addCustomWidget.mockClear()
|
|
})
|
|
|
|
it('adds chat history widget to node', () => {
|
|
const { showChatHistory } = useNodeChatHistory()
|
|
showChatHistory(mockNode)
|
|
|
|
expect(mockNode.widgets.length).toBe(1)
|
|
expect(mockNode.widgets[0].name).toBe('$$node-chat-history')
|
|
expect(mockNode.setDirtyCanvas).toHaveBeenCalled()
|
|
})
|
|
|
|
it('removes chat history widget from node', () => {
|
|
const { showChatHistory, removeChatHistory } = useNodeChatHistory()
|
|
showChatHistory(mockNode)
|
|
|
|
expect(mockNode.widgets.length).toBe(1)
|
|
|
|
removeChatHistory(mockNode)
|
|
expect(mockNode.widgets.length).toBe(0)
|
|
})
|
|
})
|