mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 06:56:18 -05:00
URLs can be dropped onto download textarea.
This commit is contained in:
parent
7bf1c80847
commit
ae460af8d6
2 changed files with 37 additions and 2 deletions
|
|
@ -424,7 +424,7 @@ export function UrlsTextarea({name = 'urls', required, form}) {
|
|||
let urls = (inputProps.value || '').split('\n');
|
||||
urls = [...urls, droppedUrl];
|
||||
urls = urls.filter(i => !!i).join('\n');
|
||||
inputAttrs.setValue(`${urls}\n`);
|
||||
inputAttrs.localSetValue(`${urls}\n`);
|
||||
};
|
||||
|
||||
const handleKeyDown = (event) => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import React from 'react';
|
||||
import {act, renderHook, screen, waitFor} from '@testing-library/react';
|
||||
import {act, fireEvent, renderHook, screen, waitFor} from '@testing-library/react';
|
||||
import {
|
||||
commaSeparatedValidator,
|
||||
InputForm,
|
||||
|
|
@ -1001,5 +1001,40 @@ describe('Form Components', () => {
|
|||
expect.objectContaining({name: 'urls'})
|
||||
);
|
||||
});
|
||||
|
||||
it('appends dropped URL via localSetValue on drop', () => {
|
||||
// Regression: handleDrop previously called inputAttrs.setValue, which does
|
||||
// not exist on the attrs returned by getInputProps. The correct helper is
|
||||
// localSetValue.
|
||||
const localSetValue = jest.fn();
|
||||
const form = {
|
||||
disabled: false,
|
||||
formData: {urls: 'https://existing.example/'},
|
||||
getInputProps: jest.fn(() => [
|
||||
{
|
||||
type: 'text',
|
||||
disabled: false,
|
||||
value: 'https://existing.example/',
|
||||
name: 'urls',
|
||||
onChange: jest.fn(),
|
||||
error: null,
|
||||
'data-path': 'urls',
|
||||
},
|
||||
{valid: true, path: 'urls', localSetValue},
|
||||
]),
|
||||
onSubmit: jest.fn(),
|
||||
};
|
||||
|
||||
renderWithProviders(<UrlsTextarea form={form}/>);
|
||||
|
||||
const textarea = screen.getByPlaceholderText('Enter one URL per line');
|
||||
fireEvent.drop(textarea, {
|
||||
dataTransfer: {getData: () => 'https://dropped.example/'},
|
||||
});
|
||||
|
||||
expect(localSetValue).toHaveBeenCalledWith(
|
||||
'https://existing.example/\nhttps://dropped.example/\n'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue