-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(upload): accept type should be more lenient #1064
Open
ktmud
wants to merge
6
commits into
testing-library:main
Choose a base branch
from
ktmud:pr/accept-file-type
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3ce135d
fix(upload): accept type should be more lenient
ktmud d900be3
Also throw if no files left
ktmud 6218cfa
Fix jpeg replacement
ktmud 6b817ff
Use global replace
ktmud 57474b5
Add test case for file name upper case extension
ktmud 44b6498
Fix type error and warnings
ktmud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -151,19 +151,62 @@ test('do nothing when element is disabled', async () => { | |
}) | ||
|
||
test.each([ | ||
[true, 'video/*,audio/*', 2], | ||
[true, '.png', 1], | ||
[true, 'text/csv', 1], | ||
[true, '', 4], | ||
[false, 'video/*', 4], | ||
[true, 'video/*,audio/*', ['audio.mp3', 'mp3.jpg', 'video.mp4']], | ||
[ | ||
true, | ||
'image/png, image/gif, image/jpeg', | ||
['image.png', 'image2.PNG', 'image.jpeg', 'image.jpg'], | ||
], | ||
[ | ||
true, | ||
`image/jpeg, | ||
image/png, image/gif`, | ||
['image.png', 'image2.PNG', 'image.jpeg', 'image.jpg'], | ||
], | ||
[true, 'image/JPG', ['image.jpeg', 'image.jpg']], | ||
[true, '.JPEG', ['image.jpeg', 'image.jpg', 'mp3.jpg']], | ||
[true, '.png', ['image.png', 'image2.PNG']], | ||
[true, 'text/csv', ['file.csv']], | ||
[ | ||
true, | ||
'', | ||
[ | ||
'image.png', | ||
'image2.PNG', | ||
'image.jpeg', | ||
'image.jpg', | ||
'audio.mp3', | ||
'mp3.jpg', | ||
'file.csv', | ||
'video.mp4', | ||
], | ||
], | ||
[ | ||
false, | ||
'video/*', | ||
[ | ||
'image.png', | ||
'image2.PNG', | ||
'image.jpeg', | ||
'image.jpg', | ||
'audio.mp3', | ||
'mp3.jpg', | ||
'file.csv', | ||
'video.mp4', | ||
], | ||
], | ||
])( | ||
'filter according to accept attribute applyAccept=%s, acceptAttribute=%s', | ||
async (applyAccept, acceptAttribute, expectedLength) => { | ||
async (applyAccept, acceptAttribute, expectedFileNames) => { | ||
const files = [ | ||
new File(['hello'], 'hello.png', {type: 'image/png'}), | ||
new File(['there'], 'there.jpg', {type: 'audio/mp3'}), | ||
new File(['there'], 'there.csv', {type: 'text/csv'}), | ||
new File(['there'], 'there.jpg', {type: 'video/mp4'}), | ||
new File(['hello'], 'image.png', {type: 'image/png'}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put in some image.PNG for good measure |
||
new File(['hello'], 'image2.PNG', {type: 'image/png'}), | ||
new File(['hello'], 'image.jpeg', {type: 'image/jpeg'}), | ||
new File(['hello'], 'image.jpg', {type: 'image/jpeg'}), | ||
new File(['hello'], 'audio.mp3', {type: 'audio/mp3'}), | ||
new File(['hello'], 'mp3.jpg', {type: 'audio/mp3'}), | ||
new File(['hello'], 'file.csv', {type: 'text/csv'}), | ||
new File(['hello'], 'video.mp4', {type: 'video/mp4'}), | ||
] | ||
const {element, user} = setup<HTMLInputElement>( | ||
` | ||
|
@@ -176,8 +219,25 @@ test.each([ | |
) | ||
|
||
await user.upload(element, files) | ||
expect( | ||
Array.from(element.files as FileList).map(item => item.name), | ||
).toEqual(expectedFileNames) | ||
}, | ||
) | ||
|
||
expect(element.files).toHaveLength(expectedLength) | ||
test.each([true, false])( | ||
'throw if no files are accepted, multiple=%s', | ||
async multiple => { | ||
const files = [ | ||
new File(['hello'], 'hello.png', {type: 'image/png'}), | ||
new File(['hello'], 'hello.jpeg', {type: 'image/jpg'}), | ||
] | ||
const {element, user} = setup<HTMLInputElement>( | ||
`<input type="file" accept="video/*" ${multiple ? 'multiple' : ''} />`, | ||
) | ||
await expect(async () => { | ||
await user.upload(element, multiple ? files : files[0]) | ||
}).rejects.toThrowError('No files were accepted by the `accept` attribute') | ||
}, | ||
) | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes came here to complain about them being case sensitive :D