mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 20:06:22 -05:00
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) <noreply@anthropic.com>
This commit is contained in:
parent
1d49b99abc
commit
223cf64050
1 changed files with 13 additions and 3 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue