From 19cf778744ba15c5684bf152adc2be30a6bf2cb6 Mon Sep 17 00:00:00 2001 From: Graham Cole Date: Sat, 11 Jul 2020 12:44:49 +0100 Subject: [PATCH] fix(examples): rejectedFiles to fileRejections --- examples/accept/README.md | 28 +++++++++++++++++----------- src/index.spec.js | 36 ++++++++++++++++++++++++++++++------ typings/tests/all.tsx | 4 ++-- typings/tests/events.tsx | 4 ++-- 4 files changed, 51 insertions(+), 21 deletions(-) diff --git a/examples/accept/README.md b/examples/accept/README.md index 00efb1fa..08476c30 100644 --- a/examples/accept/README.md +++ b/examples/accept/README.md @@ -14,38 +14,44 @@ import React from 'react'; import {useDropzone} from 'react-dropzone'; function Accept(props) { - const {acceptedFiles, rejectedFiles, getRootProps, getInputProps} = useDropzone({ + const { + acceptedFiles, + fileRejections, + getRootProps, + getInputProps + } = useDropzone({ accept: 'image/jpeg, image/png' }); - - const acceptedFilesItems = acceptedFiles.map(file => ( + + const acceptedFileItems = acceptedFiles.map(file => (
  • {file.path} - {file.size} bytes
  • )); - const rejectedFilesItems = rejectedFiles.map(file => ( + const fileRejectionItems = fileRejections.map({ file, errors}) => (
  • {file.path} - {file.size} bytes +
  • )); return (
    -
    +

    Drag 'n' drop some files here, or click to select files

    (Only *.jpeg and *.png images will be accepted)
    ); diff --git a/src/index.spec.js b/src/index.spec.js index f9e077a0..d3550f33 100644 --- a/src/index.spec.js +++ b/src/index.spec.js @@ -1920,29 +1920,49 @@ describe('useDropzone() hook', () => { expect(onDropSpy).toHaveBeenCalledWith(files, [], expect.anything()) }) - it('sets {acceptedFiles, rejectedFiles}', async () => { - const FileList = (props = { files: [] }) => ( + it('sets {acceptedFiles, fileRejections}', async () => { + const FileList = ({ files = [] }) => ( ) + const RejectedFileList = ({ fileRejections = [] }) => ( + + ) + const getAcceptedFiles = node => node.querySelectorAll(`[data-type="accepted"]`) const getRejectedFiles = node => node.querySelectorAll(`[data-type="rejected"]`) + const getRejectedFilesErrors = node => node.querySelectorAll(`[data-type="error"]`) const matchToFiles = (fileList, files) => Array.from(fileList).every(item => !!files.find(file => file.name === item.textContent)) + const matchToErrorCode = (errorList, code) => + Array.from(errorList).every(item => item.textContent === code) const ui = ( {({ getRootProps, getInputProps, acceptedFiles, fileRejections }) => (
    - - rejection.file)} type="rejected" /> + +
    )}
    @@ -1961,8 +1981,12 @@ describe('useDropzone() hook', () => { const rejectedFileList = getRejectedFiles(dropzone) expect(rejectedFileList).toHaveLength(files.length) expect(matchToFiles(rejectedFileList, files)).toBe(true) + const rejectedFileErrorList = getRejectedFilesErrors(dropzone) + expect(rejectedFileErrorList).toHaveLength(files.length) + expect(matchToErrorCode(rejectedFileErrorList, 'file-invalid-type')).toBe(true) }) + it('resets {isDragActive, isDragAccept, isDragReject}', async () => { const ui = ( diff --git a/typings/tests/all.tsx b/typings/tests/all.tsx index 8f0816d4..0c47d375 100644 --- a/typings/tests/all.tsx +++ b/typings/tests/all.tsx @@ -6,8 +6,8 @@ export default class Test extends React.Component { return (
    - console.log(acceptedFiles, rejectedFiles, event)} + onDrop={(acceptedFiles, fileRejections, event) => + console.log(acceptedFiles, fileRejections, event)} onDragEnter={event => console.log(event)} onDragOver={event => console.log(event)} onDragLeave={event => console.log(event)} diff --git a/typings/tests/events.tsx b/typings/tests/events.tsx index 70a6a891..9cddf03a 100644 --- a/typings/tests/events.tsx +++ b/typings/tests/events.tsx @@ -7,8 +7,8 @@ export class Events extends React.Component {
    - console.log(acceptedFiles, rejectedFiles, event)} + onDrop={(acceptedFiles, fileRejections, event) => + console.log(acceptedFiles, fileRejections, event)} onDragEnter={event => console.log(event)} onDragOver={event => console.log(event)} onDragLeave={event => console.log(event)}