-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ai): fixes reattaching the same file by always triggering the onC… (
#5776) * fix(ai): fixes reattaching the same file by always triggering the onChange event * Create thin-pants-turn.md * Update packages/react-ai/src/components/AIConversation/views/default/Form.tsx Co-authored-by: Danny Banks <[email protected]> * fix changeset comment --------- Co-authored-by: Danny Banks <[email protected]>
- Loading branch information
1 parent
52082ae
commit b600b3b
Showing
3 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@aws-amplify/ui-react-ai": patch | ||
--- | ||
|
||
fix(ai): fixes reattaching the same file by always triggering the onChange event |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/react-ai/src/components/AIConversation/views/default/__tests__/Form.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent, waitFor } from '@testing-library/react'; | ||
import { Form } from '../Form'; | ||
|
||
const setInput = jest.fn(); | ||
const input = {}; | ||
const handleSubmit = jest.fn(); | ||
|
||
describe('Form', () => { | ||
beforeEach(() => { | ||
setInput.mockClear(); | ||
handleSubmit.mockClear(); | ||
}); | ||
|
||
it('renders a Form component with the correct elements', () => { | ||
const result = render( | ||
<Form setInput={setInput} input={input} handleSubmit={handleSubmit} /> | ||
); | ||
expect(result.container).toBeDefined(); | ||
|
||
const form = screen.findByRole('form'); | ||
const buttons = screen.getAllByRole('button'); | ||
const textInput = screen.getByTestId('text-input'); | ||
const fileInput = screen.getByTestId('hidden-file-input'); | ||
|
||
expect(form).toBeDefined(); | ||
expect(buttons).toHaveLength(2); | ||
expect(textInput).toBeDefined(); | ||
expect(fileInput).toBeDefined(); | ||
}); | ||
|
||
it('can upload files to the input', async () => { | ||
const result = render( | ||
<Form setInput={setInput} input={input} handleSubmit={handleSubmit} /> | ||
); | ||
expect(result.container).toBeDefined(); | ||
|
||
const fileInput: HTMLInputElement = screen.getByTestId('hidden-file-input'); | ||
const testFile = new File(['file content'], 'file.txt', { | ||
type: 'text/plain', | ||
}); | ||
File.prototype.text = jest.fn().mockResolvedValueOnce('foo.txt'); | ||
await waitFor(() => | ||
fireEvent.change(fileInput, { | ||
target: { files: [testFile] }, | ||
}) | ||
); | ||
expect(setInput).toHaveBeenCalledTimes(1); | ||
expect(fileInput.files).not.toBeNull(); | ||
expect(fileInput.files![0]).toStrictEqual(testFile); | ||
}); | ||
}); |