From 223cf64050c9612399b036d20881c7fceda47c9a Mon Sep 17 00:00:00 2001 From: Roland Date: Sat, 8 Aug 2026 16:59:24 -0600 Subject: [PATCH] test: model a real DataTransfer when simulating firmware drops The Flasher drop tests built dataTransfer by hand with only {files, types}. react-dropzone reads dropped files from dataTransfer.items, so the bundled file-selector threw "undefined is not iterable" on Array.from(dt.items). Populate items alongside files, as a browser does. The mock is correct on either version of the library, so the tests pass before and after the bump. Co-Authored-By: Claude Opus 5 (1M context) --- app/src/components/Flasher.test.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/components/Flasher.test.js b/app/src/components/Flasher.test.js index 2156a57d..a84e2265 100644 --- a/app/src/components/Flasher.test.js +++ b/app/src/components/Flasher.test.js @@ -243,6 +243,17 @@ function switchTab(name) { fireEvent.click(screen.getAllByText(name)[0]); } +// A drop event's dataTransfer as a browser actually builds it. react-dropzone reads dropped files from `items` +// (a DataTransferItemList of {kind, getAsFile()}), not from `files`, so supplying only `files` makes it throw +// "undefined is not iterable". Both are populated here, matching the real thing. +function dropData(files) { + return { + files, + items: files.map(file => ({kind: 'file', type: file.type, getAsFile: () => file})), + types: ['Files'], + }; +} + describe('FlasherPage', () => { const original = Object.getOwnPropertyDescriptor(global.navigator, 'serial'); @@ -391,7 +402,7 @@ describe('FlasherPage', () => { // The dropzone root wraps the whole page; a drop on any descendant bubbles up to it. react-dropzone // requires dataTransfer.types to include 'Files' before it reads the dropped files. const target = screen.getAllByText('1. Firmware files')[0]; - fireEvent.drop(target, {dataTransfer: {files: [binFile, txtFile], types: ['Files']}}); + fireEvent.drop(target, {dataTransfer: dropData([binFile, txtFile])}); // The .bin is added (shown in the selected-firmware table) and the .txt is ignored. expect((await screen.findAllByText('dropped.bin')).length).toBeGreaterThan(0); @@ -411,8 +422,7 @@ describe('FlasherPage', () => { // Changing the firmware selection (drop a new file) must drop the connection so it is re-checked. const bin = new File([new Uint8Array([0xe9, 0, 0])], 'swapped.bin'); - fireEvent.drop(screen.getAllByText('1. Firmware files')[0], - {dataTransfer: {files: [bin], types: ['Files']}}); + fireEvent.drop(screen.getAllByText('1. Firmware files')[0], {dataTransfer: dropData([bin])}); await waitFor(() => expect(screen.getAllByText('Connect Device').length).toBeGreaterThan(0)); expect(screen.queryByText('Disconnect')).not.toBeInTheDocument();