-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix * Remove line * Add unit test * CHANGELOG * Remove comment
- Loading branch information
1 parent
7c86604
commit b1b5d5b
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); |