mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-10 01:50:08 +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)
96 lines
2.5 KiB
TypeScript
96 lines
2.5 KiB
TypeScript
import { mount } from '@vue/test-utils'
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
import { createI18n } from 'vue-i18n'
|
|
|
|
import ChatHistoryWidget from '@/components/graph/widgets/ChatHistoryWidget.vue'
|
|
|
|
const i18n = createI18n({
|
|
legacy: false,
|
|
locale: 'en',
|
|
messages: {
|
|
en: {
|
|
g: { edit: 'Edit' },
|
|
chatHistory: {
|
|
cancelEdit: 'Cancel edit',
|
|
cancelEditTooltip: 'Cancel edit'
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
vi.mock('@/components/graph/widgets/chatHistory/CopyButton.vue', () => ({
|
|
default: {
|
|
name: 'CopyButton',
|
|
template: '<div class="mock-copy-button"></div>',
|
|
props: ['text']
|
|
}
|
|
}))
|
|
|
|
vi.mock('@/components/graph/widgets/chatHistory/ResponseBlurb.vue', () => ({
|
|
default: {
|
|
name: 'ResponseBlurb',
|
|
template: '<div class="mock-response-blurb"><slot /></div>',
|
|
props: ['text']
|
|
}
|
|
}))
|
|
|
|
describe('ChatHistoryWidget.vue', () => {
|
|
const mockHistory = JSON.stringify([
|
|
{ prompt: 'Test prompt', response: 'Test response', response_id: '123' }
|
|
])
|
|
|
|
const mountWidget = (props: { history: string; widget?: any }) => {
|
|
return mount(ChatHistoryWidget, {
|
|
props,
|
|
global: {
|
|
plugins: [i18n],
|
|
stubs: {
|
|
Button: {
|
|
template: '<button><slot /></button>',
|
|
props: ['icon', 'aria-label']
|
|
},
|
|
ScrollPanel: { template: '<div><slot /></div>' }
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
it('renders chat history correctly', () => {
|
|
const wrapper = mountWidget({ history: mockHistory })
|
|
expect(wrapper.text()).toContain('Test prompt')
|
|
expect(wrapper.text()).toContain('Test response')
|
|
})
|
|
|
|
it('handles empty history', () => {
|
|
const wrapper = mountWidget({ history: '[]' })
|
|
expect(wrapper.find('.mb-4').exists()).toBe(false)
|
|
})
|
|
|
|
it('edits previous prompts', () => {
|
|
const mockWidget = {
|
|
node: { widgets: [{ name: 'prompt', value: '' }] }
|
|
}
|
|
|
|
const wrapper = mountWidget({ history: mockHistory, widget: mockWidget })
|
|
const vm = wrapper.vm as any
|
|
vm.handleEdit(0)
|
|
|
|
expect(mockWidget.node.widgets[0].value).toContain('Test prompt')
|
|
expect(mockWidget.node.widgets[0].value).toContain('starting_point_id')
|
|
})
|
|
|
|
it('cancels editing correctly', () => {
|
|
const mockWidget = {
|
|
node: { widgets: [{ name: 'prompt', value: 'Original value' }] }
|
|
}
|
|
|
|
const wrapper = mountWidget({ history: mockHistory, widget: mockWidget })
|
|
const vm = wrapper.vm as any
|
|
|
|
vm.handleEdit(0)
|
|
vm.handleCancelEdit()
|
|
|
|
expect(mockWidget.node.widgets[0].value).toBe('Original value')
|
|
})
|
|
})
|