The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(assistant-ui): add test for file drop on thread viewport
Steven Enamakelff646a7fbe00
diff --git a/app/src/features/conversations/components/AssistantUiChat.slots.test.tsx b/app/src/features/conversations/components/AssistantUiChat.slots.test.tsxindex 0a43fe3f7f..208618b1d0 100644--- a/app/src/features/conversations/components/AssistantUiChat.slots.test.tsx+++ b/app/src/features/conversations/components/AssistantUiChat.slots.test.tsx@@ -60,7 +60,11 @@ function buildStore() {function chat(onOpenHumanMode?: () => void,- overrides: { attachmentsEnabled?: boolean; attachmentInteractionBlocked?: boolean } = {}+ overrides: {+ attachmentsEnabled?: boolean;+ attachmentInteractionBlocked?: boolean;+ onAttachFiles?: (files: FileList | File[] | null) => Promise<void>;+ } = {}) {return (<AssistantUiChat@@ -69,7 +73,7 @@ function chat(inputValue=""onInputValueChange={vi.fn()}attachments={[]}- onAttachFiles={vi.fn()}+ onAttachFiles={overrides.onAttachFiles ?? vi.fn()}onRemoveAttachment={vi.fn()}maxAttachments={5}attachmentsEnabled={overrides.attachmentsEnabled ?? false}@@ -80,6 +84,10 @@ function chat();}+function threadViewport(): HTMLElement {+ return document.querySelector('[data-slot="aui_thread-viewport"]') as HTMLElement;+}+function composerShell(): HTMLElement {return document.querySelector('[data-slot="aui_composer-shell"]') as HTMLElement;}@@ -130,4 +138,29 @@ describe('assistant-ui composer slots', () => {// the primitive's own (capability-gated) handling is what remains.expect(composerShell().getAttribute('data-dragging')).toBeNull();});++ it('takes a file dropped anywhere over the open thread, not just the composer', () => {+ const store = buildStore();+ const onAttachFiles = vi.fn(() => Promise.resolve());+ render(+ <Provider store={store}>{chat(undefined, { attachmentsEnabled: true, onAttachFiles })}</Provider>+ );++ const file = new File(['png'], 'shot.png', { type: 'image/png' });+ const dragOver = { types: ['Files'], dropEffect: 'none' };+ fireEvent.dragOver(threadViewport(), { dataTransfer: dragOver });++ // The drag is claimed over the transcript and the composer lights up as+ // the place the file will land.+ expect(dragOver.dropEffect).toBe('copy');+ expect(composerShell().getAttribute('data-dragging')).toBe('true');++ const drop = fireEvent.drop(threadViewport(), {+ dataTransfer: { types: ['Files'], files: [file], items: [] },+ });++ expect(drop).toBe(false); // default (navigate to the file) cancelled+ expect(onAttachFiles).toHaveBeenCalledWith([file]);+ expect(composerShell().getAttribute('data-dragging')).toBeNull();+ });});diff --git a/app/src/utils/fileDropGuard.test.ts b/app/src/utils/fileDropGuard.test.tsnew file mode 100644index 0000000000..5e7268c132--- /dev/null+++ b/app/src/utils/fileDropGuard.test.ts@@ -0,0 +1,71 @@+import { afterEach, beforeEach, describe, expect, it } from 'vitest';++import { installFileDropGuard } from './fileDropGuard';++function dragEvent(type: 'dragover' | 'drop', types: string[]) {+ const event = new Event(type, { bubbles: true, cancelable: true }) as DragEvent;+ const dataTransfer = { types, dropEffect: 'copy' };+ Object.defineProperty(event, 'dataTransfer', { value: dataTransfer });+ return { event, dataTransfer };+}++describe('installFileDropGuard', () => {+ let teardown: () => void = () => {};+ let host: HTMLDivElement;++ beforeEach(() => {+ host = document.createElement('div');+ document.body.appendChild(host);+ teardown = installFileDropGuard();+ });++ afterEach(() => {+ teardown();+ host.remove();+ });++ it('refuses an unclaimed file drag so the webview never opens the file', () => {+ const over = dragEvent('dragover', ['Files']);+ host.dispatchEvent(over.event);+ expect(over.event.defaultPrevented).toBe(true);+ expect(over.dataTransfer.dropEffect).toBe('none');++ const drop = dragEvent('drop', ['Files']);+ host.dispatchEvent(drop.event);+ expect(drop.event.defaultPrevented).toBe(true);+ });++ it('leaves a drag a real drop target already claimed alone', () => {+ host.addEventListener('dragover', event => {+ event.preventDefault();+ event.dataTransfer!.dropEffect = 'copy';+ });+ const over = dragEvent('dragover', ['Files']);+ host.dispatchEvent(over.event);+ expect(over.dataTransfer.dropEffect).toBe('copy');+ });++ it('ignores in-app drags that carry no files', () => {+ const over = dragEvent('dragover', ['application/tinyflows-node']);+ host.dispatchEvent(over.event);+ expect(over.event.defaultPrevented).toBe(false);+ expect(over.dataTransfer.dropEffect).toBe('copy');+ });++ it('leaves a native file input to its own drop handling', () => {+ const input = document.createElement('input');+ input.type = 'file';+ host.appendChild(input);+ const drop = dragEvent('drop', ['Files']);+ input.dispatchEvent(drop.event);+ expect(drop.event.defaultPrevented).toBe(false);+ });++ it('stops guarding once torn down', () => {+ teardown();+ teardown = () => {};+ const drop = dragEvent('drop', ['Files']);+ host.dispatchEvent(drop.event);+ expect(drop.event.defaultPrevented).toBe(false);+ });+});