Skip to content
Snippets Groups Projects
Commit 9f591f35 authored by Jose Manuel Serrano Amaut's avatar Jose Manuel Serrano Amaut
Browse files

[FIX]: Fix url validation for uploading and autouploading

parent 8e1e32bc
No related branches found
No related tags found
No related merge requests found
{ {
"name": "@files-ui/react", "name": "@files-ui/react",
"version": "1.2.1", "version": "1.2.2",
"description": "UI components for file uploads with React js", "description": "UI components for file uploads with React js",
"main": "./build/index.js", "main": "./build/index.js",
"module": "./build/index.es.js", "module": "./build/index.es.js",
......
...@@ -269,7 +269,7 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => { ...@@ -269,7 +269,7 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
// flag is already true or there isnt files // flag is already true or there isnt files
//url was not provided //url was not provided
if (isUploading || localFiles.length === 0 || !url) { if (isUploading || localFiles.length === 0 || !shouldUpload) {
setIsUploading(false); setIsUploading(false);
return; return;
} }
......
...@@ -207,7 +207,7 @@ const FileInputButton: React.FC<FileInputButtonProps> = ( ...@@ -207,7 +207,7 @@ const FileInputButton: React.FC<FileInputButtonProps> = (
// flag is already true or there isnt files // flag is already true or there isnt files
//url was not provided //url was not provided
if (isUploading || localFiles.length === 0 || !url) { if (isUploading || localFiles.length === 0 || !shouldUpload) {
setIsUploading(false); setIsUploading(false);
return; return;
} }
......
...@@ -58,10 +58,9 @@ export { ...@@ -58,10 +58,9 @@ export {
JsonParseResponse, JsonParseResponse,
NAMED_COLORS, NAMED_COLORS,
NO_XHR_PROVIDED_ERROR, NO_XHR_PROVIDED_ERROR,
NamedColor, SyntheticFile, SyntheticFile,
TIMEOUT_ERROR_RESPONSE, TIMEOUT_ERROR_RESPONSE,
UNEXPECTED_ERROR_RESPONSE, UNEXPECTED_ERROR_RESPONSE,
UploadPromiseResponse,
ValidateErrorEnglish, ValidateErrorEnglish,
ValidateErrorFrench, ValidateErrorFrench,
ValidateErrorItalian, ValidateErrorItalian,
...@@ -128,7 +127,7 @@ export { ...@@ -128,7 +127,7 @@ export {
sleepTransition, sleepTransition,
unableToUploadResult, unableToUploadResult,
unexpectedErrorUploadResult, unexpectedErrorUploadResult,
} from "@files-ui/core" } from "@files-ui/core";
export type { export type {
ExtFile, ExtFile,
...@@ -145,7 +144,9 @@ export type { ...@@ -145,7 +144,9 @@ export type {
FileValidatorProps, FileValidatorProps,
FunctionLabel, FunctionLabel,
LocalLabels, LocalLabels,
Method Method,
NamedColor,
UploadPromiseResponse
} from "@files-ui/core" } from "@files-ui/core"
......
...@@ -5,5 +5,5 @@ export const isThereValidUrl = ( ...@@ -5,5 +5,5 @@ export const isThereValidUrl = (
urlFunction?: Function, urlFunction?: Function,
extFileList?: ExtFile[] extFileList?: ExtFile[]
): boolean => { ): 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
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);
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment