mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-25 12:10:31 +08:00
Fix File updating (#3375)
* Fix * Remove line * Add unit test * CHANGELOG * Remove comment
This commit is contained in:
parent
be4ca360ca
commit
99945c951b
@ -60,6 +60,7 @@ By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3297](https://git
|
||||
- Ensure that the initial empty value for `gr.Dropdown(Multiselect=True)` is an empty list and the initial value for `gr.Dropdown(Multiselect=False)` is an empty string by [@pngwn](https://github.com/pngwn) in [PR 3338](https://github.com/gradio-app/gradio/pull/3338)
|
||||
- Ensure uploaded images respect the shape property when the canvas is also enabled by [@pngwn](https://github.com/pngwn) in [PR 3351](https://github.com/gradio-app/gradio/pull/3351)
|
||||
- Ensure that Google Analytics works correctly when gradio apps are created with `analytics_enabled=True` by [@abidlabs](https://github.com/abidlabs) in [PR 3349](https://github.com/gradio-app/gradio/pull/3349)
|
||||
- Fix bug where files were being re-uploaded after updates by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3375](https://github.com/gradio-app/gradio/pull/3375)
|
||||
- Fix error when using backen_fn and custom js at the same time by [@jialeicui](https://github.com/jialeicui) in [PR 3358](https://github.com/gradio-app/gradio/pull/3358)
|
||||
- Support new embeds for huggingface spaces subdomains by [@pngwn](https://github.com/pngwn) in [PR 3367](https://github.com/gradio-app/gradio/pull/3367)
|
||||
|
||||
|
@ -43,6 +43,12 @@
|
||||
if (_value === null) {
|
||||
dispatch("change");
|
||||
pending_upload = false;
|
||||
} else if (
|
||||
!(Array.isArray(_value) ? _value : [_value]).every(
|
||||
(file_data) => file_data.blob
|
||||
)
|
||||
) {
|
||||
pending_upload = false;
|
||||
} else if (mode === "dynamic") {
|
||||
let files = (Array.isArray(_value) ? _value : [_value]).map(
|
||||
(file_data) => file_data.blob!
|
||||
|
64
ui/packages/app/src/components/File/File.test.ts
Normal file
64
ui/packages/app/src/components/File/File.test.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import { test, describe, assert, expect, afterEach, vi } from "vitest";
|
||||
import { cleanup, render } from "@gradio/tootils";
|
||||
|
||||
import File from "./File.svelte";
|
||||
import type { LoadingStatus } from "../StatusTracker/types";
|
||||
import { upload_files } from "../../api";
|
||||
|
||||
const loading_status = {
|
||||
eta: 0,
|
||||
queue_position: 1,
|
||||
queue_size: 1,
|
||||
status: "complete" as LoadingStatus["status"],
|
||||
scroll_to_output: false,
|
||||
visible: true,
|
||||
fn_index: 0
|
||||
};
|
||||
|
||||
describe("File", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
test("Uploads with blob", async () => {
|
||||
vi.mock("../../api", async () => {
|
||||
return {
|
||||
upload_files: vi.fn((f) => new Promise((res) => res({})))
|
||||
};
|
||||
});
|
||||
|
||||
const api = await import("../../api");
|
||||
|
||||
render(File, {
|
||||
loading_status,
|
||||
label: "file",
|
||||
// @ts-ignore
|
||||
value: { name: "freddy.json", data: "{'name': 'freddy'}", blob: vi.fn() },
|
||||
show_label: true,
|
||||
mode: "dynamic",
|
||||
root: "http://localhost:7860",
|
||||
file_count: "1",
|
||||
root_url: null
|
||||
});
|
||||
|
||||
expect(api.upload_files).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("Does not upload without blob", () => {
|
||||
const spy = vi.fn(upload_files);
|
||||
|
||||
render(File, {
|
||||
loading_status,
|
||||
label: "file",
|
||||
value: { name: "freddy.json", data: "{'name': 'freddy'}" },
|
||||
show_label: true,
|
||||
mode: "dynamic",
|
||||
root: "http://localhost:7860",
|
||||
file_count: "1",
|
||||
root_url: null
|
||||
});
|
||||
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user