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
Branches
No related tags found
No related merge requests found
{
"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",
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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"
......
......@@ -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
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