diff --git a/package.json b/package.json index 076d8d398a0b86d695c211cf69fe8fb4c0f2a973..4547d2baee6f25fb81e9d13dec4f5075c3e9f61b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@files-ui/react", - "version": "1.2.1", + "version": "1.2.2", "description": "UI components for file uploads with React js", "main": "./build/index.js", "module": "./build/index.es.js", diff --git a/src/Dropzone/components/dropzone/Dropzone.tsx b/src/Dropzone/components/dropzone/Dropzone.tsx index a130948cd18116684fef47cdd74af1923d061d4d..15a7b19f4e93dff31f2d2228b9306ff47be38d6c 100644 --- a/src/Dropzone/components/dropzone/Dropzone.tsx +++ b/src/Dropzone/components/dropzone/Dropzone.tsx @@ -269,7 +269,7 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => { // flag is already true or there isnt files //url was not provided - if (isUploading || localFiles.length === 0 || !url) { + if (isUploading || localFiles.length === 0 || !shouldUpload) { setIsUploading(false); return; } diff --git a/src/FileInputButton/FileInputButton.tsx b/src/FileInputButton/FileInputButton.tsx index 07ddc2726bf6b0cec6e5457b1aee15dfdbc78e22..380643445677be5d6e8de29bf0e49b0ef35e9e81 100644 --- a/src/FileInputButton/FileInputButton.tsx +++ b/src/FileInputButton/FileInputButton.tsx @@ -207,7 +207,7 @@ const FileInputButton: React.FC<FileInputButtonProps> = ( // flag is already true or there isnt files //url was not provided - if (isUploading || localFiles.length === 0 || !url) { + if (isUploading || localFiles.length === 0 || !shouldUpload) { setIsUploading(false); return; } diff --git a/src/index.ts b/src/index.ts index fcccdfad403420d321ed39e2c51927c9ef5919bd..746ee0e4334b980da1cc6654b65aaa7ff6196d61 100644 --- a/src/index.ts +++ b/src/index.ts @@ -58,10 +58,9 @@ export { JsonParseResponse, NAMED_COLORS, NO_XHR_PROVIDED_ERROR, - NamedColor, SyntheticFile, + SyntheticFile, TIMEOUT_ERROR_RESPONSE, UNEXPECTED_ERROR_RESPONSE, - UploadPromiseResponse, ValidateErrorEnglish, ValidateErrorFrench, ValidateErrorItalian, @@ -128,7 +127,7 @@ export { sleepTransition, unableToUploadResult, unexpectedErrorUploadResult, -} from "@files-ui/core" +} from "@files-ui/core"; export type { ExtFile, @@ -145,7 +144,9 @@ export type { FileValidatorProps, FunctionLabel, LocalLabels, - Method + Method, + NamedColor, + UploadPromiseResponse } from "@files-ui/core" diff --git a/src/utils/url.utils.ts b/src/utils/url.utils.ts index 17877c2a838b82aa07b17f742cf3bd78eb1d7e9a..ce9dcba8b28b360d5563a2f1ee2a2c01cadf34e9 100644 --- a/src/utils/url.utils.ts +++ b/src/utils/url.utils.ts @@ -5,5 +5,5 @@ export const isThereValidUrl = ( urlFunction?: Function, extFileList?: ExtFile[] ): boolean => { - return ExtFileInstance.someValidUrl(extFileList) && url && url.length && urlFunction != undefined; + return ExtFileInstance.someValidUrl(extFileList || []) || urlFunction != undefined || (url != undefined && url.length > 0); } \ No newline at end of file diff --git a/tests/Dropzone.test.tsx b/tests/Dropzone.test.tsx new file mode 100644 index 0000000000000000000000000000000000000000..e0e2143763aa9642477c76822d5ed49b5d14d9e2 --- /dev/null +++ b/tests/Dropzone.test.tsx @@ -0,0 +1,34 @@ +import "@testing-library/jest-dom"; +import React from "react"; +import { Dropzone } from "../src"; + +import { cleanup, fireEvent, render, screen } from "@testing-library/react"; + +test("Validate label text must be 'Drop yor files here...'", () => { + render(<Dropzone> Drop yor files here...</Dropzone>); + expect(screen.getByText("Drop yor files here...")).toBeInTheDocument(); +}); + +describe("Dropzone actionButtons", () => { + test.each([ + [{ uploadButton: { onClick: console.log } }, false], + [{ uploadButton: { onClick: console.log, disabled: false } }, false], + [{ uploadButton: { onClick: console.log, disabled: true } }, true], + [{ deleteButton: { onClick: console.log } }, false], + [{ deleteButton: { onClick: console.log, disabled: false } }, false], + [{ deleteButton: { onClick: console.log, disabled: true } }, true], + + // abortButton and cleanButton need more interaction + ])("disabled %s -> %s", (config, expected) => { + const { container } = render( + <Dropzone actionButtons={{ position: "after", ...config }} />, + ); + expect( + ( + container.querySelector( + ".files-ui-buttons-container button", + ) as HTMLInputElement + ).disabled, + ).toBe(expected); + }); +});