diff --git a/app/src/hooks/useForm.js b/app/src/hooks/useForm.js index 691c81f0..298ad896 100644 --- a/app/src/hooks/useForm.js +++ b/app/src/hooks/useForm.js @@ -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) => { diff --git a/app/src/hooks/useForm.test.js b/app/src/hooks/useForm.test.js index b0a658c4..55f10aec 100644 --- a/app/src/hooks/useForm.test.js +++ b/app/src/hooks/useForm.test.js @@ -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(); + + 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' + ); + }); }); });