mirror of
https://github.com/langgenius/dify.git
synced 2026-05-09 21:28:25 +08:00
test: fix failed test
This commit is contained in:
parent
95d68437d1
commit
1d2ed8da2a
@ -47,6 +47,15 @@ vi.mock('@/hooks/use-theme', () => ({
|
||||
default: () => ({ theme: 'light' }),
|
||||
}))
|
||||
|
||||
vi.mock('@/app/components/workflow/utils', () => ({
|
||||
getKeyboardKeyNameBySystem: (key: string) => key,
|
||||
}))
|
||||
|
||||
// Mock ShortcutsName to avoid polluting button accessible names
|
||||
vi.mock('@/app/components/workflow/shortcuts-name', () => ({
|
||||
default: () => null,
|
||||
}))
|
||||
|
||||
const mockNotify = vi.fn()
|
||||
const mockUseRouter = vi.mocked(useRouter)
|
||||
const mockPush = vi.fn()
|
||||
|
||||
@ -85,6 +85,15 @@ vi.mock('@/context/provider-context', () => ({
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock('@/app/components/workflow/utils', () => ({
|
||||
getKeyboardKeyNameBySystem: (key: string) => key,
|
||||
}))
|
||||
|
||||
// Mock ShortcutsName to avoid polluting button accessible names
|
||||
vi.mock('@/app/components/workflow/shortcuts-name', () => ({
|
||||
default: () => null,
|
||||
}))
|
||||
|
||||
type ConfirmPayload = Parameters<CreateAppModalProps['onConfirm']>[0]
|
||||
|
||||
const setup = (overrides: Partial<CreateAppModalProps> = {}) => {
|
||||
|
||||
@ -86,6 +86,7 @@ vi.mock('./actions/commands/registry', () => ({
|
||||
|
||||
vi.mock('@/app/components/workflow/utils/common', () => ({
|
||||
getKeyboardKeyCodeBySystem: () => 'ctrl',
|
||||
getKeyboardKeyNameBySystem: (key: string) => key,
|
||||
isEventTargetInputArea: () => false,
|
||||
isMac: () => false,
|
||||
}))
|
||||
|
||||
@ -134,19 +134,20 @@ vi.mock('@/app/components/workflow/constants', () => ({
|
||||
WORKFLOW_DATA_UPDATE: 'WORKFLOW_DATA_UPDATE',
|
||||
}))
|
||||
|
||||
// Mock FileReader
|
||||
// Mock FileReader - synchronous to avoid timing issues in tests
|
||||
class MockFileReader {
|
||||
result: string | null = null
|
||||
onload: ((e: { target: { result: string | null } }) => void) | null = null
|
||||
|
||||
readAsText(_file: File) {
|
||||
// Simulate async file reading
|
||||
setTimeout(() => {
|
||||
this.result = 'test file content'
|
||||
if (this.onload) {
|
||||
// Call onload synchronously to avoid race conditions in tests
|
||||
this.result = 'test file content'
|
||||
// Use queueMicrotask instead of setTimeout to ensure it runs before other timers
|
||||
// but still allows React state updates to complete
|
||||
queueMicrotask(() => {
|
||||
if (this.onload)
|
||||
this.onload({ target: { result: this.result } })
|
||||
}
|
||||
}, 0)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -33,6 +33,11 @@ vi.mock('@/context/i18n', () => ({
|
||||
useDocLink: () => (path: string) => `https://docs.example.com${path}`,
|
||||
}))
|
||||
|
||||
// Mock workflow utils for ShortcutsName component
|
||||
vi.mock('@/app/components/workflow/utils', () => ({
|
||||
getKeyboardKeyNameBySystem: (key: string) => key,
|
||||
}))
|
||||
|
||||
// Mock StartNodeSelectionPanel (using real component would be better for integration,
|
||||
// but for this test we'll mock to control behavior)
|
||||
vi.mock('./start-node-selection-panel', () => ({
|
||||
@ -551,8 +556,10 @@ describe('WorkflowOnboardingModal', () => {
|
||||
|
||||
// Assert
|
||||
const escKey = screen.getByText('workflow.onboarding.escTip.key')
|
||||
expect(escKey.closest('kbd')).toBeInTheDocument()
|
||||
expect(escKey.closest('kbd')).toHaveClass('system-kbd')
|
||||
// ShortcutsName renders a div with system-kbd class, not a kbd element
|
||||
const kbdContainer = escKey.closest('.system-kbd')
|
||||
expect(kbdContainer).toBeInTheDocument()
|
||||
expect(kbdContainer).toHaveClass('system-kbd')
|
||||
})
|
||||
|
||||
it('should have descriptive text for ESC functionality', () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user