Files
hapi/web/src/components/AssistantChat/DragDropZone.test.tsx
T
weishu 9b299eaab7 feat(web): migrate to @assistant-ui/react 0.14 (tap 0.9.8 with update-depth fix)
- @assistant-ui/react ^0.11.53 -> ^0.14.29, react-markdown ^0.11.9 -> ^0.14.7
- resolves @assistant-ui/tap 0.9.8, which ships the upstream fix for
  bulk message prepends (per-scheduler MAX_UPDATE_DEPTH guard, PR
  assistant-ui/assistant-ui#5370) that the local patch covered for 0.3.5
- API migration: useAssistantApi -> useAui, useAssistantState -> useAuiState
  with s.* selector access; TextMessagePart type-guard for content.find;
  portable DefaultComponentsMap annotation for memoizeMarkdownComponents

Verified: tsc clean, 1762 unit tests, history-load e2e 12/12 against the
unpatched upstream scheduler.
2026-08-02 00:12:29 +08:00

80 lines
2.4 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, fireEvent } from '@testing-library/react'
const addAttachment = vi.fn()
vi.mock('@assistant-ui/react', () => ({
useAui: () => ({
composer: () => ({ addAttachment }),
}),
}))
vi.mock('@/lib/use-translation', () => ({
useTranslation: () => ({ t: (key: string) => key }),
}))
import { DragDropZone } from './DragDropZone'
function createDropEvent(types: string[], files: File[]): Event {
const event = new Event('drop', { bubbles: true, cancelable: true })
Object.defineProperty(event, 'dataTransfer', {
value: { types, files },
configurable: true,
})
return event
}
describe('DragDropZone drop handling', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('adds dropped files as attachments and cancels the browser default', () => {
const { container } = render(
<DragDropZone>
<div />
</DragDropZone>
)
const zone = container.firstChild as HTMLElement
const file = new File(['x'], 'a.txt', { type: 'text/plain' })
const event = createDropEvent(['Files'], [file])
fireEvent(zone, event)
expect(event.defaultPrevented).toBe(true)
expect(addAttachment).toHaveBeenCalledTimes(1)
expect(addAttachment).toHaveBeenCalledWith(file)
})
it('ignores non-file drops so the browser keeps its default (e.g. text into composer)', () => {
const { container } = render(
<DragDropZone>
<div />
</DragDropZone>
)
const zone = container.firstChild as HTMLElement
const event = createDropEvent(['text/plain'], [])
fireEvent(zone, event)
expect(event.defaultPrevented).toBe(false)
expect(addAttachment).not.toHaveBeenCalled()
})
it('does not attach when disabled but still cancels the file default', () => {
const { container } = render(
<DragDropZone disabled>
<div />
</DragDropZone>
)
const zone = container.firstChild as HTMLElement
const file = new File(['x'], 'a.txt', { type: 'text/plain' })
const event = createDropEvent(['Files'], [file])
fireEvent(zone, event)
expect(event.defaultPrevented).toBe(true)
expect(addAttachment).not.toHaveBeenCalled()
})
})