@fldr/ui 0.3.6 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/ai/component-registry.json +962 -43
  2. package/ai/component-registry.md +1 -1
  3. package/dist/.build-complete +1 -1
  4. package/dist/ai/schemas.d.ts +18 -18
  5. package/dist/blocks-source/activity-feed/activity-feed.test.tsx +75 -0
  6. package/dist/blocks-source/activity-feed/activity-feed.tsx +256 -0
  7. package/dist/blocks-source/app-shell/app-shell.test.tsx +74 -0
  8. package/dist/blocks-source/app-shell/app-shell.tsx +123 -0
  9. package/dist/blocks-source/auth-card/auth-card.test.tsx +64 -0
  10. package/dist/blocks-source/auth-card/auth-card.tsx +234 -0
  11. package/dist/blocks-source/dashboard-page/dashboard-page.tsx +167 -0
  12. package/dist/blocks-source/error-page/error-page.test.tsx +60 -0
  13. package/dist/blocks-source/error-page/error-page.tsx +97 -0
  14. package/dist/blocks-source/file-table/file-item.tsx +164 -0
  15. package/dist/blocks-source/file-table/file-table.test.tsx +82 -0
  16. package/dist/blocks-source/file-table/file-table.tsx +292 -0
  17. package/dist/blocks-source/folder-grid/folder-grid.test.tsx +54 -0
  18. package/dist/blocks-source/folder-grid/folder-grid.tsx +170 -0
  19. package/dist/blocks-source/login-page/login-page.tsx +47 -0
  20. package/dist/blocks-source/onboarding-checklist/onboarding-checklist.test.tsx +50 -0
  21. package/dist/blocks-source/onboarding-checklist/onboarding-checklist.tsx +180 -0
  22. package/dist/blocks-source/settings-section/settings-section.test.tsx +43 -0
  23. package/dist/blocks-source/settings-section/settings-section.tsx +165 -0
  24. package/dist/blocks-source/share-dialog/share-dialog.test.tsx +69 -0
  25. package/dist/blocks-source/share-dialog/share-dialog.tsx +307 -0
  26. package/dist/blocks-source/stat-grid/stat-grid.test.tsx +52 -0
  27. package/dist/blocks-source/stat-grid/stat-grid.tsx +153 -0
  28. package/dist/blocks-source/upload-dropzone/upload-dropzone.test.tsx +82 -0
  29. package/dist/blocks-source/upload-dropzone/upload-dropzone.tsx +264 -0
  30. package/dist/blocks.d.ts +780 -0
  31. package/dist/blocks.js +1664 -0
  32. package/dist/chunks/delete-resource-cmlptb61ih8s84r3.js +151 -0
  33. package/dist/delete-resource-DY-GFy2s.d.ts +48 -0
  34. package/dist/index.d.ts +4 -50
  35. package/dist/index.js +1 -146
  36. package/dist/primitives.d.ts +1 -1
  37. package/dist/styles/kumo-standalone.css +1 -1
  38. package/package.json +5 -1
@@ -0,0 +1,69 @@
1
+ if (!HTMLElement.prototype.getAnimations) {
2
+ HTMLElement.prototype.getAnimations = () => [];
3
+ }
4
+
5
+ import { fireEvent, render, screen } from "@testing-library/react";
6
+ import { describe, expect, it, vi } from "vite-plus/test";
7
+ import { ShareDialog, type ShareDialogProps } from "./share-dialog";
8
+
9
+ function setup(overrides: Partial<ShareDialogProps> = {}) {
10
+ const props: ShareDialogProps = {
11
+ open: true,
12
+ resourceName: "Q4 receipts",
13
+ link: "https://fldr.app/f/q4-receipts",
14
+ members: [
15
+ {
16
+ id: "1",
17
+ name: "Ada Lovelace",
18
+ email: "ada@fldr.app",
19
+ role: "editor",
20
+ owner: true,
21
+ },
22
+ {
23
+ id: "2",
24
+ name: "Grace Hopper",
25
+ email: "grace@fldr.app",
26
+ role: "viewer",
27
+ },
28
+ ],
29
+ linkAccess: { scope: "restricted", role: "viewer" },
30
+ onInvite: vi.fn(),
31
+ onRoleChange: vi.fn(),
32
+ onRemove: vi.fn(),
33
+ onLinkAccessChange: vi.fn(),
34
+ ...overrides,
35
+ };
36
+ render(<ShareDialog {...props} />);
37
+ return props;
38
+ }
39
+
40
+ describe("ShareDialog", () => {
41
+ it("renders the title and members", () => {
42
+ setup();
43
+ expect(screen.getByText('Share "Q4 receipts"')).toBeDefined();
44
+ expect(screen.getByText("grace@fldr.app")).toBeDefined();
45
+ expect(
46
+ screen.queryByRole("button", { name: "Remove Ada Lovelace" }),
47
+ ).toBeNull();
48
+ });
49
+
50
+ it("invites a valid email with the default role", () => {
51
+ const props = setup();
52
+ const input = screen.getByPlaceholderText("Add people by email");
53
+ fireEvent.change(input, { target: { value: "not-an-email" } });
54
+ fireEvent.submit(input.closest("form")!);
55
+ expect(props.onInvite).not.toHaveBeenCalled();
56
+
57
+ fireEvent.change(input, { target: { value: " bob@fldr.app " } });
58
+ fireEvent.click(screen.getByRole("button", { name: "Invite" }));
59
+ expect(props.onInvite).toHaveBeenCalledWith("bob@fldr.app", "viewer");
60
+ });
61
+
62
+ it("removes a member", () => {
63
+ const props = setup();
64
+ fireEvent.click(
65
+ screen.getByRole("button", { name: "Remove Grace Hopper" }),
66
+ );
67
+ expect(props.onRemove).toHaveBeenCalledWith("2");
68
+ });
69
+ });
@@ -0,0 +1,307 @@
1
+ import { useState, type FormEvent, type ReactElement } from "react";
2
+ import { GlobeIcon, LockIcon, XIcon } from "@phosphor-icons/react";
3
+ import { Button } from "../../components/button";
4
+ import { ClipboardText } from "../../components/clipboard-text";
5
+ import { Input } from "../../components/input";
6
+ import { LayerDialog } from "../../components/layer-dialog";
7
+ import { Select } from "../../components/select";
8
+ import { cn } from "../../utils/cn";
9
+
10
+ /** Role key, e.g. `"viewer"`. Keys come from the `roles` prop. */
11
+ export type ShareRole = string;
12
+
13
+ export interface ShareMember {
14
+ id: string;
15
+ name: string;
16
+ email: string;
17
+ role: ShareRole;
18
+ avatarUrl?: string;
19
+ /** Owners show a fixed label and cannot be removed. */
20
+ owner?: boolean;
21
+ }
22
+
23
+ export type ShareLinkScope = "restricted" | "anyone";
24
+
25
+ export interface ShareLinkAccess {
26
+ scope: ShareLinkScope;
27
+ role: ShareRole;
28
+ }
29
+
30
+ export interface ShareDialogLabels {
31
+ title?: (resourceName: string) => string;
32
+ emailPlaceholder?: string;
33
+ invite?: string;
34
+ people?: string;
35
+ owner?: string;
36
+ remove?: (name: string) => string;
37
+ roleFor?: (name: string) => string;
38
+ generalAccess?: string;
39
+ restricted?: string;
40
+ restrictedHint?: string;
41
+ anyone?: string;
42
+ anyoneHint?: string;
43
+ linkRole?: string;
44
+ copyLink?: string;
45
+ }
46
+
47
+ export interface ShareDialogProps {
48
+ /** Name of the shared file or folder, used in the title. */
49
+ resourceName: string;
50
+ members: ShareMember[];
51
+ linkAccess: ShareLinkAccess;
52
+ link: string;
53
+ onInvite: (email: string, role: ShareRole) => void;
54
+ onRoleChange: (id: string, role: ShareRole) => void;
55
+ onRemove: (id: string) => void;
56
+ onLinkAccessChange: (access: ShareLinkAccess) => void;
57
+ /** Role key → label. First key is the default invite role. */
58
+ roles?: Record<ShareRole, string>;
59
+ open?: boolean;
60
+ onOpenChange?: (open: boolean) => void;
61
+ /** Element that opens the dialog, e.g. `<Button>Share</Button>`. */
62
+ trigger?: ReactElement;
63
+ labels?: ShareDialogLabels;
64
+ className?: string;
65
+ }
66
+
67
+ const DEFAULT_ROLES: Record<ShareRole, string> = {
68
+ viewer: "Viewer",
69
+ editor: "Editor",
70
+ };
71
+ const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
72
+
73
+ function initials(name: string) {
74
+ const parts = name.trim().split(/\s+/);
75
+ return ((parts[0]?.[0] ?? "") + (parts[1]?.[0] ?? "")).toUpperCase();
76
+ }
77
+
78
+ /**
79
+ * Share dialog for a file or folder: invite people, manage their roles,
80
+ * set general link access and copy the link.
81
+ *
82
+ * @example
83
+ * ```tsx
84
+ * <ShareDialog
85
+ * resourceName="Q4 receipts"
86
+ * trigger={<Button>Share</Button>}
87
+ * members={members}
88
+ * linkAccess={access}
89
+ * link="https://fldr.app/f/q4-receipts"
90
+ * onInvite={(email, role) => invite(email, role)}
91
+ * onRoleChange={setRole}
92
+ * onRemove={remove}
93
+ * onLinkAccessChange={setAccess}
94
+ * />
95
+ * ```
96
+ */
97
+ export function ShareDialog({
98
+ resourceName,
99
+ members,
100
+ linkAccess,
101
+ link,
102
+ onInvite,
103
+ onRoleChange,
104
+ onRemove,
105
+ onLinkAccessChange,
106
+ roles = DEFAULT_ROLES,
107
+ open,
108
+ onOpenChange,
109
+ trigger,
110
+ labels = {},
111
+ className,
112
+ }: ShareDialogProps) {
113
+ const roleKeys = Object.keys(roles);
114
+ const [email, setEmail] = useState("");
115
+ const [inviteRole, setInviteRole] = useState<ShareRole>(roleKeys[0] ?? "");
116
+ const l = {
117
+ title: (name: string) => `Share "${name}"`,
118
+ emailPlaceholder: "Add people by email",
119
+ invite: "Invite",
120
+ people: "People with access",
121
+ owner: "Owner",
122
+ remove: (name: string) => `Remove ${name}`,
123
+ roleFor: (name: string) => `Role for ${name}`,
124
+ generalAccess: "General access",
125
+ restricted: "Restricted",
126
+ restrictedHint: "Only people with access can open",
127
+ anyone: "Anyone with the link",
128
+ anyoneHint: "Anyone on the internet with the link can open",
129
+ linkRole: "Link role",
130
+ copyLink: "Copy link",
131
+ ...labels,
132
+ };
133
+ const valid = EMAIL_RE.test(email.trim());
134
+
135
+ const submit = (event: FormEvent) => {
136
+ event.preventDefault();
137
+ if (!valid) return;
138
+ onInvite(email.trim(), inviteRole);
139
+ setEmail("");
140
+ };
141
+
142
+ const roleOptions = roleKeys.map((key) => (
143
+ <Select.Option key={key} value={key}>
144
+ {roles[key]}
145
+ </Select.Option>
146
+ ));
147
+ const anyone = linkAccess.scope === "anyone";
148
+
149
+ return (
150
+ <LayerDialog.Root open={open} onOpenChange={onOpenChange}>
151
+ {trigger && <LayerDialog.Trigger render={trigger} />}
152
+ <LayerDialog.Content size="base">
153
+ <LayerDialog.Title>{l.title(resourceName)}</LayerDialog.Title>
154
+ <LayerDialog.Body>
155
+ <div className={cn("flex flex-col gap-4", className)}>
156
+ <form onSubmit={submit} className="flex gap-2">
157
+ <Input
158
+ type="email"
159
+ aria-label={l.emailPlaceholder}
160
+ placeholder={l.emailPlaceholder}
161
+ value={email}
162
+ onChange={(event) => setEmail(event.target.value)}
163
+ className="min-w-0 flex-1"
164
+ />
165
+ <Select
166
+ aria-label={l.roleFor(email || l.invite)}
167
+ value={inviteRole}
168
+ onValueChange={(value) => setInviteRole(value as ShareRole)}
169
+ renderValue={(value) => roles[value as ShareRole]}
170
+ className="w-26"
171
+ >
172
+ {roleOptions}
173
+ </Select>
174
+ <Button type="submit" variant="primary" disabled={!valid}>
175
+ {l.invite}
176
+ </Button>
177
+ </form>
178
+
179
+ <section className="flex flex-col gap-1">
180
+ <h3 className="text-sm font-medium text-kumo-subtle">
181
+ {l.people}
182
+ </h3>
183
+ <ul className="-mx-2 flex flex-col">
184
+ {members.map((member) => (
185
+ <li
186
+ key={member.id}
187
+ className="flex items-center gap-3 rounded-lg px-2 py-1.5 hover:bg-kumo-tint"
188
+ >
189
+ {member.avatarUrl ? (
190
+ <img
191
+ src={member.avatarUrl}
192
+ alt=""
193
+ className="size-8 shrink-0 rounded-full object-cover"
194
+ />
195
+ ) : (
196
+ <span
197
+ aria-hidden
198
+ className="flex size-8 shrink-0 items-center justify-center rounded-full bg-kumo-fill text-xs font-medium text-kumo-strong"
199
+ >
200
+ {initials(member.name)}
201
+ </span>
202
+ )}
203
+ <div className="min-w-0 flex-1">
204
+ <p className="truncate text-sm text-kumo-default">
205
+ {member.name}
206
+ </p>
207
+ <p className="truncate text-xs text-kumo-subtle">
208
+ {member.email}
209
+ </p>
210
+ </div>
211
+ {member.owner ? (
212
+ <span className="pr-2 text-sm text-kumo-subtle">
213
+ {l.owner}
214
+ </span>
215
+ ) : (
216
+ <>
217
+ <Select
218
+ size="sm"
219
+ aria-label={l.roleFor(member.name)}
220
+ value={member.role}
221
+ onValueChange={(value) =>
222
+ onRoleChange(member.id, value as ShareRole)
223
+ }
224
+ renderValue={(value) => roles[value as ShareRole]}
225
+ className="w-24"
226
+ >
227
+ {roleOptions}
228
+ </Select>
229
+ <Button
230
+ size="sm"
231
+ variant="ghost"
232
+ shape="square"
233
+ icon={<XIcon />}
234
+ aria-label={l.remove(member.name)}
235
+ onClick={() => onRemove(member.id)}
236
+ />
237
+ </>
238
+ )}
239
+ </li>
240
+ ))}
241
+ </ul>
242
+ </section>
243
+
244
+ <section className="flex flex-col gap-2">
245
+ <h3 className="text-sm font-medium text-kumo-subtle">
246
+ {l.generalAccess}
247
+ </h3>
248
+ <div className="flex items-center gap-3">
249
+ <span className="flex size-8 shrink-0 items-center justify-center rounded-full bg-kumo-fill text-kumo-subtle">
250
+ {anyone ? <GlobeIcon size={16} /> : <LockIcon size={16} />}
251
+ </span>
252
+ <div className="min-w-0 flex-1">
253
+ <Select
254
+ size="sm"
255
+ aria-label={l.generalAccess}
256
+ value={linkAccess.scope}
257
+ onValueChange={(value) =>
258
+ onLinkAccessChange({
259
+ ...linkAccess,
260
+ scope: value as ShareLinkScope,
261
+ })
262
+ }
263
+ renderValue={(value) =>
264
+ value === "anyone" ? l.anyone : l.restricted
265
+ }
266
+ className="w-auto"
267
+ >
268
+ <Select.Option value="restricted">
269
+ {l.restricted}
270
+ </Select.Option>
271
+ <Select.Option value="anyone">{l.anyone}</Select.Option>
272
+ </Select>
273
+ <p className="mt-0.5 truncate text-xs text-kumo-subtle">
274
+ {anyone ? l.anyoneHint : l.restrictedHint}
275
+ </p>
276
+ </div>
277
+ {anyone && (
278
+ <Select
279
+ size="sm"
280
+ aria-label={l.linkRole}
281
+ value={linkAccess.role}
282
+ onValueChange={(value) =>
283
+ onLinkAccessChange({
284
+ ...linkAccess,
285
+ role: value as ShareRole,
286
+ })
287
+ }
288
+ renderValue={(value) => roles[value as ShareRole]}
289
+ className="w-24"
290
+ >
291
+ {roleOptions}
292
+ </Select>
293
+ )}
294
+ </div>
295
+ </section>
296
+
297
+ <ClipboardText
298
+ text={link}
299
+ size="base"
300
+ labels={{ copyAction: l.copyLink }}
301
+ />
302
+ </div>
303
+ </LayerDialog.Body>
304
+ </LayerDialog.Content>
305
+ </LayerDialog.Root>
306
+ );
307
+ }
@@ -0,0 +1,52 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import { describe, expect, it } from "vite-plus/test";
3
+ import { Stat, StatGrid } from "./stat-grid";
4
+
5
+ describe("StatGrid", () => {
6
+ it("renders items and children", () => {
7
+ render(
8
+ <StatGrid items={[{ label: "Files", value: "1,284" }]}>
9
+ <Stat label="Shared links" value="18" />
10
+ </StatGrid>,
11
+ );
12
+ expect(screen.getByText("Files")).toBeTruthy();
13
+ expect(screen.getByText("1,284")).toBeTruthy();
14
+ expect(screen.getByText("Shared links")).toBeTruthy();
15
+ });
16
+
17
+ it("colours deltas by trend and polarity", () => {
18
+ render(
19
+ <StatGrid
20
+ items={[
21
+ {
22
+ label: "Files",
23
+ value: "1,284",
24
+ delta: { value: "+36", trend: "up" },
25
+ },
26
+ {
27
+ label: "Failed uploads",
28
+ value: "4",
29
+ delta: { value: "+2", trend: "up", positiveIsGood: false },
30
+ },
31
+ { label: "Folders", value: "52", delta: { value: "0" } },
32
+ ]}
33
+ />,
34
+ );
35
+ expect(screen.getByText("+36").className).toContain("text-kumo-success");
36
+ expect(screen.getByText("+2").className).toContain("text-kumo-danger");
37
+ expect(screen.getByText("0").className).toContain("text-kumo-subtle");
38
+ });
39
+
40
+ it("renders a storage meter and hint", () => {
41
+ render(
42
+ <Stat
43
+ label="Storage"
44
+ value="12.4 GB"
45
+ hint="of 50 GB"
46
+ meter={{ value: 25, label: "Storage used" }}
47
+ />,
48
+ );
49
+ expect(screen.getByRole("meter")).toBeTruthy();
50
+ expect(screen.getByText("of 50 GB")).toBeTruthy();
51
+ });
52
+ });
@@ -0,0 +1,153 @@
1
+ import type { ReactNode } from "react";
2
+ import { ArrowDownIcon, ArrowUpIcon } from "@phosphor-icons/react";
3
+ import { Meter } from "../../components/meter";
4
+ import { cn } from "../../utils/cn";
5
+
6
+ export type StatTrend = "up" | "down" | "neutral";
7
+
8
+ export interface StatDelta {
9
+ /** Display text, e.g. "+12%" or "-3". */
10
+ value: string;
11
+ /** Direction of change. @default "neutral" */
12
+ trend?: StatTrend;
13
+ /**
14
+ * Whether an increase is good. Set to `false` for metrics like
15
+ * "Failed uploads" where going up should read as danger. @default true
16
+ */
17
+ positiveIsGood?: boolean;
18
+ }
19
+
20
+ export interface StatProps {
21
+ /** Metric name, e.g. "Files". */
22
+ label: ReactNode;
23
+ /** Formatted metric value, e.g. "1,284". */
24
+ value: ReactNode;
25
+ /** Optional change indicator shown next to the value. */
26
+ delta?: StatDelta;
27
+ /** Optional footnote under the value, e.g. "vs. last 30 days". */
28
+ hint?: ReactNode;
29
+ /** Optional icon shown beside the label. */
30
+ icon?: ReactNode;
31
+ /** Optional usage meter (0–100), e.g. storage used of quota. */
32
+ meter?: { value: number; label: string };
33
+ className?: string;
34
+ }
35
+
36
+ const TREND_CLASSES = {
37
+ good: "text-kumo-success",
38
+ bad: "text-kumo-danger",
39
+ neutral: "text-kumo-subtle",
40
+ } as const;
41
+
42
+ function deltaTone({ trend = "neutral", positiveIsGood = true }: StatDelta) {
43
+ if (trend === "neutral") return TREND_CLASSES.neutral;
44
+ return (trend === "up") === positiveIsGood
45
+ ? TREND_CLASSES.good
46
+ : TREND_CLASSES.bad;
47
+ }
48
+
49
+ /** A single metric card. Usable on its own or inside `StatGrid`. */
50
+ export function Stat({
51
+ label,
52
+ value,
53
+ delta,
54
+ hint,
55
+ icon,
56
+ meter,
57
+ className,
58
+ }: StatProps) {
59
+ const TrendIcon =
60
+ delta?.trend === "up"
61
+ ? ArrowUpIcon
62
+ : delta?.trend === "down"
63
+ ? ArrowDownIcon
64
+ : null;
65
+
66
+ return (
67
+ <div
68
+ className={cn(
69
+ "flex min-w-0 flex-col gap-1.5 rounded-lg bg-kumo-elevated px-3 py-2.5",
70
+ className,
71
+ )}
72
+ >
73
+ <div className="flex items-center gap-1.5 text-sm text-kumo-subtle">
74
+ {icon && <span className="flex shrink-0 [&_svg]:size-4">{icon}</span>}
75
+ <span className="truncate">{label}</span>
76
+ </div>
77
+ <div className="flex flex-wrap items-baseline gap-2">
78
+ <span className="text-2xl font-semibold text-kumo-default tabular-nums">
79
+ {value}
80
+ </span>
81
+ {delta && (
82
+ <span
83
+ data-trend={delta.trend ?? "neutral"}
84
+ className={cn(
85
+ "inline-flex items-center gap-0.5 text-sm font-medium tabular-nums",
86
+ deltaTone(delta),
87
+ )}
88
+ >
89
+ {TrendIcon && (
90
+ <TrendIcon aria-hidden weight="bold" className="size-3" />
91
+ )}
92
+ {delta.value}
93
+ </span>
94
+ )}
95
+ </div>
96
+ {meter && (
97
+ <Meter label={meter.label} value={meter.value} showValue={false} />
98
+ )}
99
+ {hint && <p className="text-xs text-kumo-subtle">{hint}</p>}
100
+ </div>
101
+ );
102
+ }
103
+
104
+ export interface StatGridProps {
105
+ /** Stats to render. Alternatively pass `Stat` elements as children. */
106
+ items?: StatProps[];
107
+ children?: ReactNode;
108
+ /** Maximum columns on wide screens. @default 4 */
109
+ columns?: 2 | 3 | 4;
110
+ className?: string;
111
+ }
112
+
113
+ const COLUMN_CLASSES = {
114
+ 2: "sm:grid-cols-2",
115
+ 3: "sm:grid-cols-2 lg:grid-cols-3",
116
+ 4: "sm:grid-cols-2 lg:grid-cols-4",
117
+ } as const;
118
+
119
+ /**
120
+ * Responsive grid of metric cards with optional delta, footnote, icon and meter.
121
+ *
122
+ * @example
123
+ * ```tsx
124
+ * <StatGrid
125
+ * items={[
126
+ * { label: "Files", value: "1,284", delta: { value: "+36", trend: "up" } },
127
+ * { label: "Storage", value: "12.4 GB", hint: "of 50 GB", meter: { value: 25, label: "Storage used" } },
128
+ * { label: "Shared links", value: "18", icon: <LinkIcon /> },
129
+ * ]}
130
+ * />
131
+ * ```
132
+ */
133
+ export function StatGrid({
134
+ items,
135
+ children,
136
+ columns = 4,
137
+ className,
138
+ }: StatGridProps) {
139
+ return (
140
+ <div
141
+ className={cn(
142
+ "grid grid-cols-1 gap-2",
143
+ COLUMN_CLASSES[columns],
144
+ className,
145
+ )}
146
+ >
147
+ {items?.map((item, index) => (
148
+ <Stat key={index} {...item} />
149
+ ))}
150
+ {children}
151
+ </div>
152
+ );
153
+ }
@@ -0,0 +1,82 @@
1
+ import { fireEvent, render, screen } from "@testing-library/react";
2
+ import { describe, expect, it, vi } from "vite-plus/test";
3
+ import { UploadDropzone, type UploadItem } from "./upload-dropzone";
4
+
5
+ const file = (name: string, size: number, type = "application/pdf") =>
6
+ new File([new Uint8Array(size)], name, { type });
7
+
8
+ describe("UploadDropzone", () => {
9
+ it("calls onFiles from the file input", () => {
10
+ const onFiles = vi.fn();
11
+ render(<UploadDropzone onFiles={onFiles} />);
12
+ const receipt = file("receipt.pdf", 10);
13
+ fireEvent.change(screen.getByTestId("upload-dropzone-input"), {
14
+ target: { files: [receipt] },
15
+ });
16
+ expect(onFiles).toHaveBeenCalledWith([receipt]);
17
+ });
18
+
19
+ it("splits dropped files into accepted and rejected", () => {
20
+ const onFiles = vi.fn();
21
+ const onReject = vi.fn();
22
+ render(
23
+ <UploadDropzone
24
+ accept=".pdf,image/*"
25
+ maxSize={100}
26
+ onFiles={onFiles}
27
+ onReject={onReject}
28
+ />,
29
+ );
30
+ const ok = file("invoice.pdf", 50);
31
+ const big = file("scan.png", 500, "image/png");
32
+ const wrong = file("notes.exe", 5, "application/octet-stream");
33
+ fireEvent.drop(screen.getByText("Drop files here").parentElement!, {
34
+ dataTransfer: { files: [ok, big, wrong] },
35
+ });
36
+ expect(onFiles).toHaveBeenCalledWith([ok]);
37
+ expect(onReject).toHaveBeenCalledWith([
38
+ { file: big, reason: "size" },
39
+ { file: wrong, reason: "type" },
40
+ ]);
41
+ });
42
+
43
+ it("renders upload rows with retry and remove actions", () => {
44
+ const onRetry = vi.fn();
45
+ const onRemove = vi.fn();
46
+ const uploads: UploadItem[] = [
47
+ {
48
+ id: "a",
49
+ name: "lease.pdf",
50
+ size: 2048,
51
+ progress: 40,
52
+ status: "uploading",
53
+ },
54
+ {
55
+ id: "b",
56
+ name: "w2.pdf",
57
+ size: 1024,
58
+ progress: 10,
59
+ status: "error",
60
+ error: "Network lost",
61
+ },
62
+ ];
63
+ render(
64
+ <UploadDropzone
65
+ uploads={uploads}
66
+ onFiles={() => {}}
67
+ onRetry={onRetry}
68
+ onRemove={onRemove}
69
+ />,
70
+ );
71
+ expect(
72
+ screen
73
+ .getByRole("progressbar", { name: "lease.pdf" })
74
+ .getAttribute("aria-valuenow"),
75
+ ).toBe("40");
76
+ expect(screen.getByText("Network lost")).toBeDefined();
77
+ fireEvent.click(screen.getByRole("button", { name: "Retry w2.pdf" }));
78
+ expect(onRetry).toHaveBeenCalledWith("b");
79
+ fireEvent.click(screen.getByRole("button", { name: "Remove lease.pdf" }));
80
+ expect(onRemove).toHaveBeenCalledWith("a");
81
+ });
82
+ });