gradio-pr-bot commited on
Commit
efb9bbc
·
verified ·
1 Parent(s): 2e37c04

Upload folder using huggingface_hub

Browse files
6.11.0/tootils/src/render.ts CHANGED
@@ -14,7 +14,7 @@ import type {
14
  } from "@testing-library/dom";
15
  import { vi, type Mock } from "vitest";
16
  import { GRADIO_ROOT, allowed_shared_props } from "@gradio/utils";
17
- import type { LoadingStatus } from "@gradio/statustracker";
18
  import { _ } from "svelte-i18n";
19
 
20
  const containerCache = new Map();
@@ -31,16 +31,44 @@ export type RenderResult<
31
  debug: (el?: HTMLElement | DocumentFragment) => void;
32
  unmount: () => void;
33
  } & { [P in keyof Q]: BoundFunction<Q[P]> };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
- const loading_status: LoadingStatus = {
36
  eta: 0,
37
  queue_position: 1,
38
  queue_size: 1,
39
- status: "complete" as LoadingStatus["status"],
 
 
 
 
 
 
 
40
  scroll_to_output: false,
41
- visible: true,
42
  fn_index: 0,
43
- show_progress: "full"
44
  };
45
 
46
  export interface RenderOptions<Q extends Queries = typeof queries> {
@@ -166,6 +194,10 @@ export async function render<
166
  }
167
  }
168
 
 
 
 
 
169
  const componentProps = {
170
  shared_props: shared_props_obj,
171
  props: {
 
14
  } from "@testing-library/dom";
15
  import { vi, type Mock } from "vitest";
16
  import { GRADIO_ROOT, allowed_shared_props } from "@gradio/utils";
17
+ import type { LoadingStatus, ILoadingStatus } from "@gradio/statustracker";
18
  import { _ } from "svelte-i18n";
19
 
20
  const containerCache = new Map();
 
31
  debug: (el?: HTMLElement | DocumentFragment) => void;
32
  unmount: () => void;
33
  } & { [P in keyof Q]: BoundFunction<Q[P]> };
34
+ export interface ILoadingStatus {
35
+ eta: number | null;
36
+ status: "pending" | "error" | "complete" | "generating" | "streaming";
37
+ queue: boolean;
38
+ queue_position: number | null;
39
+ queue_size?: number;
40
+ fn_index: number;
41
+ message?: string | null;
42
+ scroll_to_output?: boolean;
43
+ show_progress?: "full" | "minimal" | "hidden";
44
+ time_limit?: number | null | undefined;
45
+ progress?: {
46
+ progress: number | null;
47
+ index: number | null;
48
+ length: number | null;
49
+ unit: string | null;
50
+ desc: string | null;
51
+ }[];
52
+ validation_error?: string | null;
53
+ type: "input" | "output";
54
+ stream_state: "open" | "closed" | "waiting" | null;
55
+ }
56
 
57
+ const loading_status: ILoadingStatus = {
58
  eta: 0,
59
  queue_position: 1,
60
  queue_size: 1,
61
+ queue: true,
62
+ message: null,
63
+ time_limit: null,
64
+ progress: [],
65
+ validation_error: null,
66
+ type: "output",
67
+ stream_state: null,
68
+ status: "complete" as ILoadingStatus["status"],
69
  scroll_to_output: false,
 
70
  fn_index: 0,
71
+ show_progress: "full" as ILoadingStatus["show_progress"]
72
  };
73
 
74
  export interface RenderOptions<Q extends Queries = typeof queries> {
 
194
  }
195
  }
196
 
197
+ shared_props_obj.loading_status = props?.loading_status
198
+ ? props.loading_status
199
+ : loading_status;
200
+
201
  const componentProps = {
202
  shared_props: shared_props_obj,
203
  props: {
6.11.0/tootils/src/shared-prop-tests.ts CHANGED
@@ -28,6 +28,13 @@ export interface SharedPropTestConfig {
28
  * @default true
29
  */
30
  has_validation_error?: boolean;
 
 
 
 
 
 
 
31
  }
32
 
33
  export function run_shared_prop_tests(config: SharedPropTestConfig): void {
@@ -36,7 +43,8 @@ export function run_shared_prop_tests(config: SharedPropTestConfig): void {
36
  base_props,
37
  name,
38
  has_label = true,
39
- has_validation_error = true
 
40
  } = config;
41
 
42
  const label = "Test Label";
@@ -93,15 +101,28 @@ export function run_shared_prop_tests(config: SharedPropTestConfig): void {
93
  expect(el).not.toBeVisible();
94
  });
95
 
96
- test("visible: false removes the component from the DOM", async () => {
97
- const result = await render(
98
- component,
99
- make_props({ visible: false, elem_id: "gone-test" })
100
- );
 
101
 
102
- const el = result.container.querySelector("#gone-test");
103
- expect(el).toBeNull();
104
- });
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
  if (has_label) {
107
  test("label text is rendered", async () => {
@@ -139,7 +160,10 @@ export function run_shared_prop_tests(config: SharedPropTestConfig): void {
139
  test("validation_error displays error text", async () => {
140
  const result = await render(
141
  component,
142
- make_props({ validation_error: "This field is required" })
 
 
 
143
  );
144
  const el = result.getByText("This field is required");
145
  expect(el).toBeTruthy();
 
28
  * @default true
29
  */
30
  has_validation_error?: boolean;
31
+ /**
32
+ * Some components (e.g. Accordion) map visible=false to "hidden"
33
+ * instead of removing from the DOM. Set to true to expect hidden
34
+ * behaviour rather than removal.
35
+ * @default false
36
+ */
37
+ visible_false_hides?: boolean;
38
  }
39
 
40
  export function run_shared_prop_tests(config: SharedPropTestConfig): void {
 
43
  base_props,
44
  name,
45
  has_label = true,
46
+ has_validation_error = true,
47
+ visible_false_hides = false
48
  } = config;
49
 
50
  const label = "Test Label";
 
101
  expect(el).not.toBeVisible();
102
  });
103
 
104
+ if (visible_false_hides) {
105
+ test("visible: false hides the component but keeps it in the DOM", async () => {
106
+ const result = await render(
107
+ component,
108
+ make_props({ visible: false, elem_id: "gone-test" })
109
+ );
110
 
111
+ const el = result.container.querySelector("#gone-test");
112
+ expect(el).not.toBeNull();
113
+ expect(el).not.toBeVisible();
114
+ });
115
+ } else {
116
+ test("visible: false removes the component from the DOM", async () => {
117
+ const result = await render(
118
+ component,
119
+ make_props({ visible: false, elem_id: "gone-test" })
120
+ );
121
+
122
+ const el = result.container.querySelector("#gone-test");
123
+ expect(el).toBeNull();
124
+ });
125
+ }
126
 
127
  if (has_label) {
128
  test("label text is rendered", async () => {
 
160
  test("validation_error displays error text", async () => {
161
  const result = await render(
162
  component,
163
+ make_props({
164
+ validation_error: "This field is required",
165
+ show_validation_error: true
166
+ })
167
  );
168
  const el = result.getByText("This field is required");
169
  expect(el).toBeTruthy();