-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
201 additions
and
43 deletions.
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,40 @@ | ||
// @vitest-environment jsdom | ||
|
||
import {fireEvent, render} from '@testing-library/react'; | ||
import {FileSelector} from './file_selector.tsx'; | ||
import {assert, expect, test, vi} from 'vitest'; | ||
|
||
test('FileSelector should render correctly', () => { | ||
const mockHandler = vi.fn(); | ||
const {getByText} = render(<FileSelector handler={mockHandler}/>); | ||
expect(getByText('Select file')).toBeInTheDocument(); | ||
}); | ||
|
||
test('FileSelector should call handler when file size is within limit', () => { | ||
const mockHandler = vi.fn(); | ||
const {getByLabelText} = render(<FileSelector handler={mockHandler}/>); | ||
const file = new File(['dummy content'], 'dummy.txt', {type: 'text/plain'}); | ||
fireEvent.change(getByLabelText('Select file'), {target: {files: [file]}}); | ||
expect(mockHandler).toHaveBeenCalledWith(file); | ||
}); | ||
|
||
test('FileSelector should not call handler when file size exceeds limit', () => { | ||
const mockHandler = vi.fn(); | ||
const {getByLabelText} = render(<FileSelector handler={mockHandler}/>); | ||
const file = new File(["0".repeat(1024 * 1024 * 31)], 'dummy.txt', {type: 'text/plain'}); | ||
assert(file.size > 1024 * 1024 * 30); | ||
|
||
fireEvent.change(getByLabelText('Select file'), {target: {files: [file]}}); | ||
expect(mockHandler).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test('FileSelector should call handler when file size exceeds limit and user chooses to continue', () => { | ||
const mockHandler = vi.fn(); | ||
const {getByLabelText, getByText} = render(<FileSelector handler={mockHandler}/>); | ||
const file = new File(["0".repeat(1024 * 1024 * 31)], 'dummy.txt', {type: 'text/plain'}); | ||
assert(file.size > 1024 * 1024 * 30); | ||
|
||
fireEvent.change(getByLabelText('Select file'), {target: {files: [file]}}); | ||
fireEvent.click(getByText('Continue')); | ||
expect(mockHandler).toHaveBeenCalledWith(file); | ||
}); |
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
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
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
"include": [ | ||
"vite.config.ts", | ||
"vite.config-explorer.ts", | ||
"vitest.config.ts", | ||
"common.ts", | ||
] | ||
} |
Oops, something went wrong.