@alixpartners/ui-components 2.5.1 → 2.5.2
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.
- package/dist/RichTextEditor-CHGQT1Qj.js +363 -0
- package/dist/assets/Datepicker.css +1 -1
- package/dist/assets/RadioGroup.css +1 -1
- package/dist/assets/RichTextEditor.css +1 -0
- package/dist/components/Datepicker/Datepicker.js +55 -56
- package/dist/components/DragAndDrop/DragAndDrop.d.ts +3 -1
- package/dist/components/DragAndDrop/DragAndDrop.js +47 -39
- package/dist/components/DragAndDrop/DragAndDrop.test.js +179 -173
- package/dist/components/RadioGroup/RadioGroup.d.ts +3 -1
- package/dist/components/RadioGroup/RadioGroup.js +16 -14
- package/dist/components/RadioGroup/RadioGroup.test.js +8 -0
- package/dist/components/RichTextEditor/RichTextEditor.d.ts +26 -0
- package/dist/components/RichTextEditor/RichTextEditor.js +10 -0
- package/dist/components/RichTextEditor/RichTextEditor.model.d.ts +12 -0
- package/dist/components/RichTextEditor/RichTextEditor.test.d.ts +1 -0
- package/dist/components/RichTextEditor/RichTextEditor.test.js +91 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +50 -48
- package/package.json +1 -1
|
@@ -1,93 +1,99 @@
|
|
|
1
1
|
import { jsxs as v, jsx as i } from "react/jsx-runtime";
|
|
2
|
-
import { d as y, i as
|
|
3
|
-
import
|
|
4
|
-
import { c as
|
|
2
|
+
import { d as y, i as d, r, g as e, s as o, v as c, w as f, f as B } from "../../vi.bdSIJ99Y-017e_Pkz.js";
|
|
3
|
+
import l from "./DragAndDrop.js";
|
|
4
|
+
import { c as h, d as I } from "../../DragAndDrop.utils-D3xTV9EK.js";
|
|
5
5
|
import { u as w } from "../../index-DkTDHhag.js";
|
|
6
6
|
y("DragAndDrop", () => {
|
|
7
7
|
y("Rendering", () => {
|
|
8
8
|
y("Basic rendering", () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}),
|
|
12
|
-
|
|
13
|
-
}),
|
|
14
|
-
|
|
15
|
-
}),
|
|
16
|
-
|
|
17
|
-
}),
|
|
18
|
-
|
|
9
|
+
d("should render component with required props", () => {
|
|
10
|
+
r(/* @__PURE__ */ i(l, { label: "Upload File", fileExtensionsAllowed: ["pdf"], maxSize: 5 })), e(o.getByText("Upload File")).toBeInTheDocument(), e(o.getByTestId("drag-and-drop-zone")).toBeInTheDocument(), e(o.getByTestId("drag-and-drop-input")).toBeInTheDocument();
|
|
11
|
+
}), d("should not render label element when label prop is omitted", () => {
|
|
12
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5 })), e(o.queryByText("Upload File")).not.toBeInTheDocument(), e(o.getByTestId("drag-and-drop-zone")).toBeInTheDocument();
|
|
13
|
+
}), d("should render required asterisk when required prop is true", () => {
|
|
14
|
+
r(/* @__PURE__ */ i(l, { label: "Upload File", required: !0, fileExtensionsAllowed: ["pdf"], maxSize: 5 })), e(o.getByTestId("drag-and-drop-required")).toBeInTheDocument(), e(o.getByTestId("drag-and-drop-required")).toHaveTextContent("*");
|
|
15
|
+
}), d("should not render required asterisk when required prop is false", () => {
|
|
16
|
+
r(/* @__PURE__ */ i(l, { label: "Upload File", required: !1, fileExtensionsAllowed: ["pdf"], maxSize: 5 })), e(o.queryByTestId("drag-and-drop-required")).not.toBeInTheDocument();
|
|
17
|
+
}), d("should render browse button with default text for single file", () => {
|
|
18
|
+
r(/* @__PURE__ */ i(l, { type: "single", fileExtensionsAllowed: ["pdf"], maxSize: 5 }));
|
|
19
19
|
const t = o.getByText("Browse file");
|
|
20
20
|
e(t).toBeInTheDocument();
|
|
21
|
-
}),
|
|
22
|
-
|
|
21
|
+
}), d("should render browse button with default text for multiple files", () => {
|
|
22
|
+
r(/* @__PURE__ */ i(l, { type: "multiple", fileExtensionsAllowed: ["pdf"], maxSize: 5 }));
|
|
23
23
|
const t = o.getByText("Browse files");
|
|
24
24
|
e(t).toBeInTheDocument();
|
|
25
|
-
}),
|
|
26
|
-
|
|
27
|
-
}),
|
|
28
|
-
|
|
29
|
-
}),
|
|
25
|
+
}), d("should render drag text for single file", () => {
|
|
26
|
+
r(/* @__PURE__ */ i(l, { type: "single", fileExtensionsAllowed: ["pdf"], maxSize: 5 })), e(o.getByText("or drag your file")).toBeInTheDocument();
|
|
27
|
+
}), d("should render drag text for multiple files", () => {
|
|
28
|
+
r(/* @__PURE__ */ i(l, { type: "multiple", fileExtensionsAllowed: ["pdf"], maxSize: 5 })), e(o.getByText("or drag multiple files")).toBeInTheDocument();
|
|
29
|
+
}), d("should render file list when files are present", async () => {
|
|
30
30
|
const t = new File(["test"], "test.pdf", {
|
|
31
31
|
type: "application/pdf"
|
|
32
32
|
}), a = c.fn();
|
|
33
|
-
|
|
33
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a }));
|
|
34
34
|
const n = o.getByTestId("drag-and-drop-input");
|
|
35
35
|
await w.upload(n, t), await f(() => {
|
|
36
36
|
e(o.getByTestId("drag-and-drop-files-list")).toBeInTheDocument();
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
39
|
}), y("Disabled state", () => {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
d("should render browse button as enabled by default", () => {
|
|
41
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5 }));
|
|
42
42
|
const t = o.getByText("Browse file");
|
|
43
43
|
e(t).not.toBeDisabled();
|
|
44
|
-
}),
|
|
45
|
-
|
|
44
|
+
}), d("should render browse button as disabled when disabled prop is true", () => {
|
|
45
|
+
r(/* @__PURE__ */ i(l, { disabled: !0, fileExtensionsAllowed: ["pdf"], maxSize: 5 }));
|
|
46
46
|
const t = o.getByTestId("button");
|
|
47
47
|
e(t).toBeDisabled();
|
|
48
48
|
});
|
|
49
49
|
}), y("CSS Classes", () => {
|
|
50
|
-
|
|
50
|
+
d("should apply disabled CSS class to container when disabled prop is true", () => {
|
|
51
51
|
const {
|
|
52
52
|
container: t
|
|
53
|
-
} =
|
|
53
|
+
} = r(/* @__PURE__ */ i(l, { disabled: !0, fileExtensionsAllowed: ["pdf"], maxSize: 5 })), a = t.firstChild;
|
|
54
54
|
e(a.className).toContain("disabled");
|
|
55
|
-
}),
|
|
55
|
+
}), d("should merge custom className with default container classes", () => {
|
|
56
56
|
const {
|
|
57
57
|
container: t
|
|
58
|
-
} =
|
|
58
|
+
} = r(/* @__PURE__ */ i(l, { className: "custom-class", fileExtensionsAllowed: ["pdf"], maxSize: 5 })), a = t.firstChild;
|
|
59
59
|
e(a.className).toContain("custom-class");
|
|
60
60
|
});
|
|
61
61
|
});
|
|
62
62
|
}), y("Text Customization", () => {
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
d("should use custom browse text when provided as string", () => {
|
|
64
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, texts: {
|
|
65
65
|
browse: "Select File"
|
|
66
66
|
} })), e(o.getByText("Select File")).toBeInTheDocument();
|
|
67
|
-
}),
|
|
68
|
-
|
|
67
|
+
}), d("should use custom browse text when provided as function", () => {
|
|
68
|
+
r(/* @__PURE__ */ i(l, { type: "multiple", fileExtensionsAllowed: ["pdf"], maxSize: 5, texts: {
|
|
69
69
|
browse: (t) => t === "single" ? "Choose One" : "Choose Many"
|
|
70
70
|
} })), e(o.getByText("Choose Many")).toBeInTheDocument();
|
|
71
|
-
}),
|
|
72
|
-
|
|
71
|
+
}), d("should use custom drag text when provided as string", () => {
|
|
72
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, texts: {
|
|
73
73
|
drag: "or drop here"
|
|
74
74
|
} })), e(o.getByText("or drop here")).toBeInTheDocument();
|
|
75
|
-
}),
|
|
76
|
-
|
|
75
|
+
}), d("should use custom drag text when provided as function", () => {
|
|
76
|
+
r(/* @__PURE__ */ i(l, { type: "multiple", fileExtensionsAllowed: ["pdf"], maxSize: 5, texts: {
|
|
77
77
|
drag: (t) => t === "single" ? "drop one" : "drop many"
|
|
78
78
|
} })), e(o.getByText("drop many")).toBeInTheDocument();
|
|
79
|
-
}),
|
|
80
|
-
|
|
79
|
+
}), d("should use custom constraints text when provided", () => {
|
|
80
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf", "doc"], maxSize: 10, texts: {
|
|
81
81
|
constraints: ({
|
|
82
82
|
extensions: t,
|
|
83
83
|
maxSize: a
|
|
84
84
|
}) => `Formats: ${t.join(", ")}. Max: ${a}MB`
|
|
85
85
|
} })), e(o.getByText(/Formats: pdf, doc. Max: 10MB/)).toBeInTheDocument();
|
|
86
|
-
}),
|
|
86
|
+
}), d("should use constraintsText when provided", () => {
|
|
87
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, constraintsText: "PDF only, max 5 MB per file." })), e(o.getByText("PDF only, max 5 MB per file.")).toBeInTheDocument();
|
|
88
|
+
}), d("should prefer constraintsText over texts.constraints", () => {
|
|
89
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, constraintsText: "From prop", texts: {
|
|
90
|
+
constraints: () => "From texts"
|
|
91
|
+
} })), e(o.getByText("From prop")).toBeInTheDocument(), e(o.queryByText("From texts")).not.toBeInTheDocument();
|
|
92
|
+
}), d("should use custom error messages when provided", async () => {
|
|
87
93
|
const t = new File(["x".repeat(10485760)], "large.pdf", {
|
|
88
94
|
type: "application/pdf"
|
|
89
95
|
}), a = c.fn();
|
|
90
|
-
|
|
96
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 1, onUpload: a, texts: {
|
|
91
97
|
errors: {
|
|
92
98
|
sizeTooLarge: (s) => `File is too big! Maximum is ${s}MB`
|
|
93
99
|
}
|
|
@@ -98,55 +104,55 @@ y("DragAndDrop", () => {
|
|
|
98
104
|
});
|
|
99
105
|
});
|
|
100
106
|
}), y("Icon Customization", () => {
|
|
101
|
-
|
|
107
|
+
d("should use custom file icon when provided", async () => {
|
|
102
108
|
const t = new File(["test"], "test.pdf", {
|
|
103
109
|
type: "application/pdf"
|
|
104
110
|
}), a = c.fn();
|
|
105
|
-
|
|
111
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a, fileIcon: "ap-icon-document-rpm" }));
|
|
106
112
|
const n = o.getByTestId("drag-and-drop-input");
|
|
107
113
|
await w.upload(n, t), await f(() => {
|
|
108
114
|
const s = o.getByTestId("drag-and-drop-file-item-0").querySelector(".ap-icon-document-rpm");
|
|
109
115
|
e(s).toBeInTheDocument();
|
|
110
116
|
});
|
|
111
|
-
}),
|
|
117
|
+
}), d("should use custom error icon when provided", async () => {
|
|
112
118
|
const t = new File(["test"], "test.txt", {
|
|
113
119
|
type: "text/plain"
|
|
114
120
|
}), a = c.fn();
|
|
115
|
-
|
|
121
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a, errorIcon: "ap-icon-alert-filled" }));
|
|
116
122
|
const n = o.getByTestId("drag-and-drop-input"), s = new DataTransfer();
|
|
117
123
|
s.items.add(t), Object.defineProperty(n, "files", {
|
|
118
124
|
value: s.files,
|
|
119
125
|
writable: !1
|
|
120
126
|
}), B.change(n), await f(() => {
|
|
121
|
-
const
|
|
122
|
-
e(
|
|
123
|
-
const u =
|
|
127
|
+
const p = o.getByTestId("drag-and-drop-file-error-0");
|
|
128
|
+
e(p).toBeInTheDocument();
|
|
129
|
+
const u = p.querySelector(".ap-icon-alert-filled");
|
|
124
130
|
e(u).toBeInTheDocument();
|
|
125
131
|
});
|
|
126
|
-
}),
|
|
127
|
-
|
|
132
|
+
}), d("should use custom browse button icon when provided", () => {
|
|
133
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, browseButtonIcon: "ap-icon-upload" }));
|
|
128
134
|
const t = o.getByTestId("button-icon");
|
|
129
135
|
e(t).toBeInTheDocument(), e(t.className).toContain("ap-icon-upload");
|
|
130
136
|
});
|
|
131
137
|
}), y("Render Props", () => {
|
|
132
|
-
|
|
138
|
+
d("should use custom renderFileItem when provided", async () => {
|
|
133
139
|
const t = new File(["test"], "test.pdf", {
|
|
134
140
|
type: "application/pdf"
|
|
135
|
-
}), a = c.fn(), n = c.fn((
|
|
141
|
+
}), a = c.fn(), n = c.fn((p, u, g) => /* @__PURE__ */ v("div", { children: [
|
|
136
142
|
"Custom: ",
|
|
137
|
-
|
|
143
|
+
p.file.name,
|
|
138
144
|
/* @__PURE__ */ i("button", { onClick: g, children: "Remove" })
|
|
139
145
|
] }));
|
|
140
|
-
|
|
146
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a, renderFileItem: n }));
|
|
141
147
|
const s = o.getByTestId("drag-and-drop-input");
|
|
142
148
|
await w.upload(s, t), await f(() => {
|
|
143
149
|
e(o.getByTestId("custom-file-item")).toBeInTheDocument(), e(o.getByText("Custom: test.pdf")).toBeInTheDocument(), e(n).toHaveBeenCalledTimes(1);
|
|
144
150
|
});
|
|
145
|
-
}),
|
|
151
|
+
}), d("should call renderFileItem with correct parameters", async () => {
|
|
146
152
|
const t = new File(["test"], "test.pdf", {
|
|
147
153
|
type: "application/pdf"
|
|
148
|
-
}), a = c.fn(), n = c.fn((
|
|
149
|
-
|
|
154
|
+
}), a = c.fn(), n = c.fn((p, u, g) => /* @__PURE__ */ i("div", { children: "Custom" }));
|
|
155
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a, renderFileItem: n }));
|
|
150
156
|
const s = o.getByTestId("drag-and-drop-input");
|
|
151
157
|
await w.upload(s, t), await f(() => {
|
|
152
158
|
e(n).toHaveBeenCalledWith(e.objectContaining({
|
|
@@ -156,22 +162,22 @@ y("DragAndDrop", () => {
|
|
|
156
162
|
});
|
|
157
163
|
});
|
|
158
164
|
}), y("File Size Formatter", () => {
|
|
159
|
-
|
|
165
|
+
d("should use custom fileSizeFormatter when provided", async () => {
|
|
160
166
|
const t = new File(["test"], "test.pdf", {
|
|
161
167
|
type: "application/pdf"
|
|
162
|
-
}), a = c.fn(), n = c.fn((
|
|
163
|
-
|
|
168
|
+
}), a = c.fn(), n = c.fn((p) => `${(p / 1024).toFixed(0)} KB`);
|
|
169
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a, fileSizeFormatter: n }));
|
|
164
170
|
const s = o.getByTestId("drag-and-drop-input");
|
|
165
171
|
await w.upload(s, t), await f(() => {
|
|
166
172
|
e(n).toHaveBeenCalled();
|
|
167
|
-
const
|
|
168
|
-
e(
|
|
173
|
+
const p = o.getByTestId("drag-and-drop-file-size-0");
|
|
174
|
+
e(p.textContent).toBe(`${Math.round(t.size / 1024)} KB`);
|
|
169
175
|
});
|
|
170
|
-
}),
|
|
176
|
+
}), d("should use default formatter when fileSizeFormatter is not provided", async () => {
|
|
171
177
|
const t = new File(["test"], "test.pdf", {
|
|
172
178
|
type: "application/pdf"
|
|
173
179
|
}), a = c.fn();
|
|
174
|
-
|
|
180
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a }));
|
|
175
181
|
const n = o.getByTestId("drag-and-drop-input");
|
|
176
182
|
await w.upload(n, t), await f(() => {
|
|
177
183
|
const s = o.getByTestId("drag-and-drop-file-size-0");
|
|
@@ -179,8 +185,8 @@ y("DragAndDrop", () => {
|
|
|
179
185
|
});
|
|
180
186
|
});
|
|
181
187
|
}), y("Button Customization", () => {
|
|
182
|
-
|
|
183
|
-
|
|
188
|
+
d("should apply browseButtonProps to browse button", () => {
|
|
189
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, browseButtonProps: {
|
|
184
190
|
type: "primary",
|
|
185
191
|
variant: "danger",
|
|
186
192
|
size: "md"
|
|
@@ -189,146 +195,146 @@ y("DragAndDrop", () => {
|
|
|
189
195
|
e(t.className).toContain("btn-primary"), e(t.className).toContain("btn-danger"), e(t.className).toContain("btn-md");
|
|
190
196
|
});
|
|
191
197
|
}), y("File Upload Interactions", () => {
|
|
192
|
-
|
|
198
|
+
d("should call onUpload when file is selected", async () => {
|
|
193
199
|
const t = new File(["test"], "test.pdf", {
|
|
194
200
|
type: "application/pdf"
|
|
195
201
|
}), a = c.fn();
|
|
196
|
-
|
|
202
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a }));
|
|
197
203
|
const n = o.getByTestId("drag-and-drop-input");
|
|
198
204
|
await w.upload(n, t), await f(() => {
|
|
199
205
|
e(a).toHaveBeenCalledTimes(1), e(a).toHaveBeenCalledWith(e.arrayContaining([e.objectContaining({
|
|
200
206
|
file: e.any(File)
|
|
201
207
|
})]));
|
|
202
208
|
});
|
|
203
|
-
}),
|
|
209
|
+
}), d("should handle multiple file selection", async () => {
|
|
204
210
|
const t = new File(["test1"], "test1.pdf", {
|
|
205
211
|
type: "application/pdf"
|
|
206
212
|
}), a = new File(["test2"], "test2.pdf", {
|
|
207
213
|
type: "application/pdf"
|
|
208
214
|
}), n = c.fn();
|
|
209
|
-
|
|
215
|
+
r(/* @__PURE__ */ i(l, { type: "multiple", fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: n }));
|
|
210
216
|
const s = o.getByTestId("drag-and-drop-input");
|
|
211
217
|
await w.upload(s, [t, a]), await f(() => {
|
|
212
218
|
e(n).toHaveBeenCalledTimes(1);
|
|
213
|
-
const
|
|
214
|
-
e(
|
|
219
|
+
const p = n.mock.calls[0][0];
|
|
220
|
+
e(p).toHaveLength(2);
|
|
215
221
|
});
|
|
216
|
-
}),
|
|
222
|
+
}), d("should call onRemoveFile when remove button is clicked", async () => {
|
|
217
223
|
const t = new File(["test"], "test.pdf", {
|
|
218
224
|
type: "application/pdf"
|
|
219
225
|
}), a = c.fn(), n = c.fn();
|
|
220
|
-
|
|
226
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a, onRemoveFile: n }));
|
|
221
227
|
const s = o.getByTestId("drag-and-drop-input");
|
|
222
228
|
await w.upload(s, t), await f(() => {
|
|
223
229
|
e(o.getByTestId("drag-and-drop-files-list")).toBeInTheDocument();
|
|
224
230
|
});
|
|
225
|
-
const
|
|
226
|
-
B.click(
|
|
231
|
+
const p = o.getByTestId("drag-and-drop-remove-0");
|
|
232
|
+
B.click(p), e(n).toHaveBeenCalledTimes(1);
|
|
227
233
|
const [u, g] = n.mock.calls[0];
|
|
228
234
|
e(u).toBe(t), e(g).toHaveLength(0), await f(() => {
|
|
229
235
|
e(o.queryByTestId("drag-and-drop-files-list")).not.toBeInTheDocument();
|
|
230
236
|
});
|
|
231
|
-
}),
|
|
237
|
+
}), d("should queue files when queueFiles is true", async () => {
|
|
232
238
|
const t = new File(["test1"], "test1.pdf", {
|
|
233
239
|
type: "application/pdf"
|
|
234
240
|
}), a = new File(["test2"], "test2.pdf", {
|
|
235
241
|
type: "application/pdf"
|
|
236
242
|
}), n = c.fn();
|
|
237
|
-
|
|
243
|
+
r(/* @__PURE__ */ i(l, { type: "multiple", fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: n, queueFiles: !0 }));
|
|
238
244
|
const s = o.getByTestId("drag-and-drop-input");
|
|
239
245
|
await w.upload(s, t), await f(() => {
|
|
240
246
|
e(n).toHaveBeenCalledTimes(1);
|
|
241
247
|
}), await w.upload(s, a), await f(() => {
|
|
242
248
|
e(n).toHaveBeenCalledTimes(2);
|
|
243
|
-
const
|
|
244
|
-
e(
|
|
249
|
+
const p = n.mock.calls[1][0];
|
|
250
|
+
e(p.length).toBeGreaterThan(1);
|
|
245
251
|
});
|
|
246
252
|
});
|
|
247
253
|
}), y("Drag and Drop Interactions", () => {
|
|
248
|
-
|
|
254
|
+
d("should handle drag over event", () => {
|
|
249
255
|
const t = c.fn();
|
|
250
|
-
|
|
256
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onDragOver: t }));
|
|
251
257
|
const a = o.getByTestId("drag-and-drop-zone");
|
|
252
258
|
B.dragOver(a), e(t).toHaveBeenCalledTimes(1);
|
|
253
|
-
}),
|
|
259
|
+
}), d("should handle drag leave event", () => {
|
|
254
260
|
const t = c.fn();
|
|
255
|
-
|
|
261
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onDragLeave: t }));
|
|
256
262
|
const a = o.getByTestId("drag-and-drop-zone");
|
|
257
263
|
B.dragLeave(a), e(t).toHaveBeenCalledTimes(1);
|
|
258
|
-
}),
|
|
264
|
+
}), d("should handle drop event and call onUpload", async () => {
|
|
259
265
|
const t = new File(["test"], "test.pdf", {
|
|
260
266
|
type: "application/pdf"
|
|
261
267
|
}), a = c.fn(), n = c.fn();
|
|
262
|
-
|
|
263
|
-
const s = o.getByTestId("drag-and-drop-zone"),
|
|
268
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a, onDrop: n }));
|
|
269
|
+
const s = o.getByTestId("drag-and-drop-zone"), p = {
|
|
264
270
|
files: [t],
|
|
265
271
|
clearData: c.fn()
|
|
266
272
|
};
|
|
267
273
|
B.drop(s, {
|
|
268
|
-
dataTransfer:
|
|
274
|
+
dataTransfer: p
|
|
269
275
|
}), await f(() => {
|
|
270
276
|
e(n).toHaveBeenCalledTimes(1), e(a).toHaveBeenCalledTimes(1);
|
|
271
277
|
});
|
|
272
278
|
});
|
|
273
279
|
}), y("Validation", () => {
|
|
274
|
-
|
|
280
|
+
d("should validate file size and show error for oversized files", async () => {
|
|
275
281
|
const t = new File(["x".repeat(10485760)], "large.pdf", {
|
|
276
282
|
type: "application/pdf"
|
|
277
283
|
}), a = c.fn();
|
|
278
|
-
|
|
284
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 1, onUpload: a }));
|
|
279
285
|
const n = o.getByTestId("drag-and-drop-input");
|
|
280
286
|
await w.upload(n, t), await f(() => {
|
|
281
287
|
e(o.getByTestId("drag-and-drop-file-error-0")).toBeInTheDocument();
|
|
282
288
|
const s = o.getByTestId("drag-and-drop-file-error-0");
|
|
283
289
|
e(s.textContent).toContain("too large");
|
|
284
290
|
});
|
|
285
|
-
}),
|
|
291
|
+
}), d("should validate file extension and show error for invalid extensions", async () => {
|
|
286
292
|
const t = new File(["test"], "test.txt", {
|
|
287
293
|
type: "text/plain"
|
|
288
294
|
}), a = c.fn();
|
|
289
|
-
|
|
295
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a }));
|
|
290
296
|
const n = o.getByTestId("drag-and-drop-input"), s = new DataTransfer();
|
|
291
297
|
s.items.add(t), Object.defineProperty(n, "files", {
|
|
292
298
|
value: s.files,
|
|
293
299
|
writable: !1
|
|
294
300
|
}), B.change(n), await f(() => {
|
|
295
301
|
e(o.getByTestId("drag-and-drop-file-error-0")).toBeInTheDocument();
|
|
296
|
-
const
|
|
297
|
-
e(
|
|
302
|
+
const p = o.getByTestId("drag-and-drop-file-error-0");
|
|
303
|
+
e(p.textContent).toContain("format is incorrect");
|
|
298
304
|
});
|
|
299
|
-
}),
|
|
305
|
+
}), d("should use custom validator when provided", async () => {
|
|
300
306
|
const t = new File(["test"], "test.pdf", {
|
|
301
307
|
type: "application/pdf"
|
|
302
308
|
}), a = c.fn(), n = c.fn(
|
|
303
309
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
304
|
-
(
|
|
305
|
-
file:
|
|
310
|
+
(p, u) => p.name.includes("test") ? {
|
|
311
|
+
file: p,
|
|
306
312
|
error: 'Files with "test" in name are not allowed'
|
|
307
313
|
} : {
|
|
308
|
-
file:
|
|
314
|
+
file: p
|
|
309
315
|
}
|
|
310
316
|
);
|
|
311
|
-
|
|
317
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a, validator: n }));
|
|
312
318
|
const s = o.getByTestId("drag-and-drop-input");
|
|
313
319
|
await w.upload(s, t), await f(() => {
|
|
314
320
|
e(n).toHaveBeenCalledTimes(1), e(o.getByTestId("drag-and-drop-file-error-0")).toBeInTheDocument(), e(o.getByText('Files with "test" in name are not allowed')).toBeInTheDocument();
|
|
315
321
|
});
|
|
316
|
-
}),
|
|
322
|
+
}), d("should execute synchronous custom validator and display returned error message", async () => {
|
|
317
323
|
const t = new File(["test"], "test.pdf", {
|
|
318
324
|
type: "application/pdf"
|
|
319
325
|
}), a = c.fn(), n = c.fn(
|
|
320
326
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
321
|
-
(
|
|
322
|
-
file:
|
|
327
|
+
(p, u) => ({
|
|
328
|
+
file: p,
|
|
323
329
|
error: "Synchronous validation failed"
|
|
324
330
|
})
|
|
325
331
|
);
|
|
326
|
-
|
|
332
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a, validator: n }));
|
|
327
333
|
const s = o.getByTestId("drag-and-drop-input");
|
|
328
334
|
await w.upload(s, t), await f(() => {
|
|
329
335
|
e(n).toHaveBeenCalledTimes(1), e(o.getByTestId("drag-and-drop-file-error-0")).toBeInTheDocument(), e(o.getByText("Synchronous validation failed")).toBeInTheDocument();
|
|
330
336
|
});
|
|
331
|
-
}),
|
|
337
|
+
}), d("should accept first N files and mark excess files with error when maxFiles limit is exceeded", async () => {
|
|
332
338
|
const t = new File(["test1"], "test1.pdf", {
|
|
333
339
|
type: "application/pdf"
|
|
334
340
|
}), a = new File(["test2"], "test2.pdf", {
|
|
@@ -336,53 +342,53 @@ y("DragAndDrop", () => {
|
|
|
336
342
|
}), n = new File(["test3"], "test3.pdf", {
|
|
337
343
|
type: "application/pdf"
|
|
338
344
|
}), s = c.fn();
|
|
339
|
-
|
|
340
|
-
const
|
|
341
|
-
await w.upload(
|
|
345
|
+
r(/* @__PURE__ */ i(l, { type: "multiple", fileExtensionsAllowed: ["pdf"], maxSize: 5, maxFiles: 2, onUpload: s }));
|
|
346
|
+
const p = o.getByTestId("drag-and-drop-input");
|
|
347
|
+
await w.upload(p, [t, a, n]), await f(() => {
|
|
342
348
|
e(s).toHaveBeenCalledTimes(1);
|
|
343
349
|
const u = s.mock.calls[0][0];
|
|
344
350
|
e(u).toHaveLength(3), e(u[0].error).toBeUndefined(), e(u[1].error).toBeUndefined(), e(u[2].error).toContain("Maximum 2 files allowed");
|
|
345
351
|
});
|
|
346
|
-
}),
|
|
352
|
+
}), d("should only accept first file when type is single and multiple files are dropped", async () => {
|
|
347
353
|
const t = new File(["test1"], "test1.pdf", {
|
|
348
354
|
type: "application/pdf"
|
|
349
355
|
}), a = new File(["test2"], "test2.pdf", {
|
|
350
356
|
type: "application/pdf"
|
|
351
357
|
}), n = c.fn();
|
|
352
|
-
|
|
358
|
+
r(/* @__PURE__ */ i(l, { type: "single", fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: n }));
|
|
353
359
|
const s = o.getByTestId("drag-and-drop-input");
|
|
354
360
|
await w.upload(s, [t, a]), await f(() => {
|
|
355
361
|
e(n).toHaveBeenCalledTimes(1);
|
|
356
|
-
const
|
|
357
|
-
e(
|
|
362
|
+
const p = n.mock.calls[0][0];
|
|
363
|
+
e(p).toHaveLength(1);
|
|
358
364
|
});
|
|
359
365
|
});
|
|
360
366
|
}), y("Controlled Mode", () => {
|
|
361
|
-
|
|
367
|
+
d("should use controlled value when value prop is provided", async () => {
|
|
362
368
|
const t = new File(["test"], "test.pdf", {
|
|
363
369
|
type: "application/pdf"
|
|
364
370
|
}), a = c.fn(), {
|
|
365
371
|
rerender: n
|
|
366
|
-
} =
|
|
372
|
+
} = r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, value: t, onUpload: a }));
|
|
367
373
|
await f(() => {
|
|
368
374
|
e(o.getByTestId("drag-and-drop-files-list")).toBeInTheDocument(), e(o.getByTestId("drag-and-drop-file-name-0")).toHaveTextContent("test.pdf");
|
|
369
375
|
});
|
|
370
376
|
const s = new File(["new"], "new.pdf", {
|
|
371
377
|
type: "application/pdf"
|
|
372
378
|
});
|
|
373
|
-
n(/* @__PURE__ */ i(
|
|
379
|
+
n(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, value: s, onUpload: a })), await f(() => {
|
|
374
380
|
e(o.getByTestId("drag-and-drop-file-name-0")).toHaveTextContent("new.pdf");
|
|
375
381
|
});
|
|
376
|
-
}),
|
|
382
|
+
}), d("should use controlled value array when value prop is array", async () => {
|
|
377
383
|
const t = new File(["test1"], "test1.pdf", {
|
|
378
384
|
type: "application/pdf"
|
|
379
385
|
}), a = new File(["test2"], "test2.pdf", {
|
|
380
386
|
type: "application/pdf"
|
|
381
387
|
}), n = c.fn();
|
|
382
|
-
|
|
388
|
+
r(/* @__PURE__ */ i(l, { type: "multiple", fileExtensionsAllowed: ["pdf"], maxSize: 5, value: [t, a], onUpload: n })), await f(() => {
|
|
383
389
|
e(o.getByTestId("drag-and-drop-files-list")).toBeInTheDocument(), e(o.getByTestId("drag-and-drop-file-name-0")).toHaveTextContent("test1.pdf"), e(o.getByTestId("drag-and-drop-file-name-1")).toHaveTextContent("test2.pdf");
|
|
384
390
|
});
|
|
385
|
-
}),
|
|
391
|
+
}), d("should remove files by filename in controlled mode", async () => {
|
|
386
392
|
const t = new File(["test1"], "test1.pdf", {
|
|
387
393
|
type: "application/pdf"
|
|
388
394
|
}), a = new File(["test2"], "test2.pdf", {
|
|
@@ -391,128 +397,128 @@ y("DragAndDrop", () => {
|
|
|
391
397
|
let n = [];
|
|
392
398
|
const s = c.fn((m) => {
|
|
393
399
|
n = m;
|
|
394
|
-
}),
|
|
395
|
-
n =
|
|
400
|
+
}), p = c.fn((m, T) => {
|
|
401
|
+
n = T;
|
|
396
402
|
}), {
|
|
397
403
|
rerender: u
|
|
398
|
-
} =
|
|
404
|
+
} = r(/* @__PURE__ */ i(l, { type: "multiple", fileExtensionsAllowed: ["pdf"], maxSize: 5, value: n.map((m) => m.file), onUpload: s, onRemoveFile: p })), g = o.getByTestId("drag-and-drop-input");
|
|
399
405
|
await w.upload(g, [t, a]), await f(() => {
|
|
400
406
|
e(s).toHaveBeenCalled(), e(n.length).toBe(2);
|
|
401
|
-
}), u(/* @__PURE__ */ i(
|
|
407
|
+
}), u(/* @__PURE__ */ i(l, { type: "multiple", fileExtensionsAllowed: ["pdf"], maxSize: 5, value: n.map((m) => m.file), onUpload: s, onRemoveFile: p })), await f(() => {
|
|
402
408
|
e(o.getByTestId("drag-and-drop-file-name-0")).toHaveTextContent("test1.pdf"), e(o.getByTestId("drag-and-drop-file-name-1")).toHaveTextContent("test2.pdf");
|
|
403
409
|
});
|
|
404
410
|
const x = o.getByTestId("drag-and-drop-remove-0");
|
|
405
411
|
B.click(x), await f(() => {
|
|
406
|
-
e(
|
|
407
|
-
const [m,
|
|
408
|
-
e(m).toBe(t), e(
|
|
409
|
-
}), e(n.length).toBe(1), e(n.find((m) => m.file.name === "test1.pdf")).toBeUndefined(), u(/* @__PURE__ */ i(
|
|
412
|
+
e(p).toHaveBeenCalledTimes(1);
|
|
413
|
+
const [m, T] = p.mock.calls[0];
|
|
414
|
+
e(m).toBe(t), e(T).toHaveLength(1), e(T[0].file).toBe(a);
|
|
415
|
+
}), e(n.length).toBe(1), e(n.find((m) => m.file.name === "test1.pdf")).toBeUndefined(), u(/* @__PURE__ */ i(l, { type: "multiple", fileExtensionsAllowed: ["pdf"], maxSize: 5, value: n.map((m) => m.file), onUpload: s, onRemoveFile: p })), await f(() => {
|
|
410
416
|
e(o.getByTestId("drag-and-drop-files-list")).toBeInTheDocument();
|
|
411
417
|
const m = n[0];
|
|
412
418
|
e(o.getByTestId("drag-and-drop-file-name-0")).toHaveTextContent(m.file.name), e(o.queryByTestId("drag-and-drop-file-name-1")).not.toBeInTheDocument();
|
|
413
419
|
});
|
|
414
420
|
});
|
|
415
421
|
}), y("File Display", () => {
|
|
416
|
-
|
|
422
|
+
d("should display file name", async () => {
|
|
417
423
|
const t = new File(["test"], "test.pdf", {
|
|
418
424
|
type: "application/pdf"
|
|
419
425
|
}), a = c.fn();
|
|
420
|
-
|
|
426
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a }));
|
|
421
427
|
const n = o.getByTestId("drag-and-drop-input");
|
|
422
428
|
await w.upload(n, t), await f(() => {
|
|
423
429
|
e(o.getByTestId("drag-and-drop-file-name-0")).toHaveTextContent("test.pdf");
|
|
424
430
|
});
|
|
425
|
-
}),
|
|
431
|
+
}), d("should display file size", async () => {
|
|
426
432
|
const t = new File(["test"], "test.pdf", {
|
|
427
433
|
type: "application/pdf"
|
|
428
434
|
}), a = c.fn();
|
|
429
|
-
|
|
435
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a }));
|
|
430
436
|
const n = o.getByTestId("drag-and-drop-input");
|
|
431
437
|
await w.upload(n, t), await f(() => {
|
|
432
438
|
e(o.getByTestId("drag-and-drop-file-size-0")).toBeInTheDocument();
|
|
433
439
|
});
|
|
434
|
-
}),
|
|
440
|
+
}), d("should display error message when file has error", async () => {
|
|
435
441
|
const t = new File(["test"], "test.txt", {
|
|
436
442
|
type: "text/plain"
|
|
437
443
|
}), a = c.fn();
|
|
438
|
-
|
|
444
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a }));
|
|
439
445
|
const n = o.getByTestId("drag-and-drop-input"), s = new DataTransfer();
|
|
440
446
|
s.items.add(t), Object.defineProperty(n, "files", {
|
|
441
447
|
value: s.files,
|
|
442
448
|
writable: !1
|
|
443
449
|
}), B.change(n), await f(() => {
|
|
444
450
|
e(o.getByTestId("drag-and-drop-file-error-0")).toBeInTheDocument();
|
|
445
|
-
const
|
|
446
|
-
e(
|
|
451
|
+
const p = o.getByTestId("drag-and-drop-file-error-0");
|
|
452
|
+
e(p.textContent).toContain("format is incorrect");
|
|
447
453
|
});
|
|
448
454
|
});
|
|
449
455
|
}), y("External Errors Prop", () => {
|
|
450
|
-
|
|
456
|
+
d("should display external errors when no validator errors exist", async () => {
|
|
451
457
|
const t = new File(["test"], "test.pdf", {
|
|
452
458
|
type: "application/pdf"
|
|
453
459
|
}), a = c.fn();
|
|
454
|
-
|
|
460
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a, errors: {
|
|
455
461
|
"test.pdf": "Custom external error message"
|
|
456
462
|
} }));
|
|
457
463
|
const s = o.getByTestId("drag-and-drop-input");
|
|
458
464
|
await w.upload(s, t), await f(() => {
|
|
459
465
|
e(o.getByTestId("drag-and-drop-file-error-0")).toBeInTheDocument(), e(o.getByText("Custom external error message")).toBeInTheDocument();
|
|
460
466
|
});
|
|
461
|
-
}),
|
|
467
|
+
}), d("should hide external errors when validator errors exist (precedence)", async () => {
|
|
462
468
|
const t = new File(["test"], "test.txt", {
|
|
463
469
|
type: "text/plain"
|
|
464
470
|
}), a = c.fn();
|
|
465
|
-
|
|
471
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a, errors: {
|
|
466
472
|
"test.txt": "Custom external error message"
|
|
467
473
|
} }));
|
|
468
|
-
const s = o.getByTestId("drag-and-drop-input"),
|
|
469
|
-
|
|
470
|
-
value:
|
|
474
|
+
const s = o.getByTestId("drag-and-drop-input"), p = new DataTransfer();
|
|
475
|
+
p.items.add(t), Object.defineProperty(s, "files", {
|
|
476
|
+
value: p.files,
|
|
471
477
|
writable: !1
|
|
472
478
|
}), B.change(s), await f(() => {
|
|
473
479
|
e(o.getByTestId("drag-and-drop-file-error-0")).toBeInTheDocument(), e(o.getByText(/format is incorrect/)).toBeInTheDocument(), e(o.queryByText("Custom external error message")).not.toBeInTheDocument();
|
|
474
480
|
});
|
|
475
|
-
}),
|
|
481
|
+
}), d("should update external errors when errors prop changes", async () => {
|
|
476
482
|
const t = new File(["test"], "test.pdf", {
|
|
477
483
|
type: "application/pdf"
|
|
478
484
|
}), a = c.fn(), {
|
|
479
485
|
rerender: n
|
|
480
|
-
} =
|
|
486
|
+
} = r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a, value: t }));
|
|
481
487
|
await f(() => {
|
|
482
488
|
e(o.getByTestId("drag-and-drop-files-list")).toBeInTheDocument(), e(o.queryByTestId("drag-and-drop-file-error-0")).not.toBeInTheDocument();
|
|
483
|
-
}), n(/* @__PURE__ */ i(
|
|
489
|
+
}), n(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a, value: t, errors: {
|
|
484
490
|
"test.pdf": "New error message"
|
|
485
491
|
} })), await f(() => {
|
|
486
492
|
e(o.getByTestId("drag-and-drop-file-error-0")).toBeInTheDocument(), e(o.getByText("New error message")).toBeInTheDocument();
|
|
487
493
|
});
|
|
488
|
-
}),
|
|
494
|
+
}), d("should clear external errors when errors prop is cleared", async () => {
|
|
489
495
|
const t = new File(["test"], "test.pdf", {
|
|
490
496
|
type: "application/pdf"
|
|
491
497
|
}), a = c.fn(), {
|
|
492
498
|
rerender: n
|
|
493
|
-
} =
|
|
499
|
+
} = r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a, value: t, errors: {
|
|
494
500
|
"test.pdf": "Error message"
|
|
495
501
|
} }));
|
|
496
502
|
await f(() => {
|
|
497
503
|
e(o.getByTestId("drag-and-drop-file-error-0")).toBeInTheDocument();
|
|
498
|
-
}), n(/* @__PURE__ */ i(
|
|
504
|
+
}), n(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: a, value: t, errors: {} })), await f(() => {
|
|
499
505
|
e(o.queryByTestId("drag-and-drop-file-error-0")).not.toBeInTheDocument();
|
|
500
506
|
});
|
|
501
|
-
}),
|
|
507
|
+
}), d("should handle external errors with duplicate filenames correctly", async () => {
|
|
502
508
|
const t = new File(["test1"], "test.pdf", {
|
|
503
509
|
type: "application/pdf"
|
|
504
510
|
}), a = new File(["test2"], "test.pdf", {
|
|
505
511
|
type: "application/pdf"
|
|
506
512
|
}), n = c.fn();
|
|
507
|
-
|
|
513
|
+
r(/* @__PURE__ */ i(l, { type: "multiple", fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: n, value: [t, a], errors: {
|
|
508
514
|
"test.pdf": "Error for duplicate filename"
|
|
509
515
|
} })), await f(() => {
|
|
510
|
-
const
|
|
511
|
-
e(
|
|
516
|
+
const p = o.getAllByTestId(/drag-and-drop-file-error-/);
|
|
517
|
+
e(p.length).toBeGreaterThan(0);
|
|
512
518
|
});
|
|
513
519
|
});
|
|
514
520
|
}), y("composeValidators", () => {
|
|
515
|
-
|
|
521
|
+
d("should compose multiple validators correctly", () => {
|
|
516
522
|
const t = c.fn((m) => m.name.includes("test") ? {
|
|
517
523
|
file: m,
|
|
518
524
|
error: "Validator 1 error"
|
|
@@ -523,72 +529,72 @@ y("DragAndDrop", () => {
|
|
|
523
529
|
error: "Validator 2 error"
|
|
524
530
|
} : {
|
|
525
531
|
file: m
|
|
526
|
-
}), n =
|
|
532
|
+
}), n = h(t, a), s = {
|
|
527
533
|
maxSize: 5,
|
|
528
534
|
fileExtensionsAllowed: ["pdf"],
|
|
529
535
|
type: "single",
|
|
530
536
|
maxFiles: 1
|
|
531
|
-
},
|
|
537
|
+
}, p = new File(["test"], "test.pdf", {
|
|
532
538
|
type: "application/pdf"
|
|
533
|
-
}), u = n(
|
|
539
|
+
}), u = n(p, s);
|
|
534
540
|
e(u.error).toBe("Validator 1 error"), e(t).toHaveBeenCalledTimes(1), e(a).not.toHaveBeenCalled();
|
|
535
541
|
const g = new File(["x".repeat(2e3)], "valid.pdf", {
|
|
536
542
|
type: "application/pdf"
|
|
537
543
|
}), x = n(g, s);
|
|
538
544
|
e(x.error).toBe("Validator 2 error"), e(a).toHaveBeenCalledTimes(1);
|
|
539
|
-
}),
|
|
545
|
+
}), d("should return first error encountered", () => {
|
|
540
546
|
const t = c.fn((g) => ({
|
|
541
547
|
file: g,
|
|
542
548
|
error: "First error"
|
|
543
549
|
})), a = c.fn((g) => ({
|
|
544
550
|
file: g,
|
|
545
551
|
error: "Second error"
|
|
546
|
-
})), n =
|
|
552
|
+
})), n = h(t, a), s = {
|
|
547
553
|
maxSize: 5,
|
|
548
554
|
fileExtensionsAllowed: ["pdf"],
|
|
549
555
|
type: "single",
|
|
550
556
|
maxFiles: 1
|
|
551
|
-
},
|
|
557
|
+
}, p = new File(["test"], "test.pdf", {
|
|
552
558
|
type: "application/pdf"
|
|
553
|
-
}), u = n(
|
|
559
|
+
}), u = n(p, s);
|
|
554
560
|
e(u.error).toBe("First error"), e(t).toHaveBeenCalledTimes(1), e(a).not.toHaveBeenCalled();
|
|
555
|
-
}),
|
|
561
|
+
}), d("should return success when all validators pass", () => {
|
|
556
562
|
const t = c.fn((g) => ({
|
|
557
563
|
file: g
|
|
558
564
|
})), a = c.fn((g) => ({
|
|
559
565
|
file: g
|
|
560
|
-
})), n =
|
|
566
|
+
})), n = h(t, a), s = {
|
|
561
567
|
maxSize: 5,
|
|
562
568
|
fileExtensionsAllowed: ["pdf"],
|
|
563
569
|
type: "single",
|
|
564
570
|
maxFiles: 1
|
|
565
|
-
},
|
|
571
|
+
}, p = new File(["test"], "test.pdf", {
|
|
566
572
|
type: "application/pdf"
|
|
567
|
-
}), u = n(
|
|
573
|
+
}), u = n(p, s);
|
|
568
574
|
e(u.error).toBeUndefined(), e(t).toHaveBeenCalledTimes(1), e(a).toHaveBeenCalledTimes(1);
|
|
569
|
-
}),
|
|
575
|
+
}), d("should work with defaultValidator in composition", () => {
|
|
570
576
|
const t = c.fn((x, m) => {
|
|
571
|
-
const
|
|
572
|
-
return
|
|
577
|
+
const T = I(x, m);
|
|
578
|
+
return T.error ? T : x.name.startsWith("reject") ? {
|
|
573
579
|
file: x,
|
|
574
580
|
error: "Custom rejection error"
|
|
575
581
|
} : {
|
|
576
582
|
file: x
|
|
577
583
|
};
|
|
578
|
-
}), a =
|
|
584
|
+
}), a = h(I, t), n = {
|
|
579
585
|
maxSize: 1,
|
|
580
586
|
fileExtensionsAllowed: ["pdf"],
|
|
581
587
|
type: "single",
|
|
582
588
|
maxFiles: 1
|
|
583
589
|
}, s = new File(["x".repeat(2 * 1024 * 1024)], "large.pdf", {
|
|
584
590
|
type: "application/pdf"
|
|
585
|
-
}),
|
|
586
|
-
e(
|
|
591
|
+
}), p = a(s, n);
|
|
592
|
+
e(p.error).toContain("too large"), e(p.errorCode).toBe("SIZE_TOO_LARGE");
|
|
587
593
|
const u = new File(["test"], "reject.pdf", {
|
|
588
594
|
type: "application/pdf"
|
|
589
595
|
}), g = a(u, n);
|
|
590
596
|
e(g.error).toBe("Custom rejection error");
|
|
591
|
-
}),
|
|
597
|
+
}), d("should integrate composeValidators with component", async () => {
|
|
592
598
|
const t = c.fn((u, g) => {
|
|
593
599
|
const x = I(u, g);
|
|
594
600
|
return x.error ? x : u.name.startsWith("blocked") ? {
|
|
@@ -597,12 +603,12 @@ y("DragAndDrop", () => {
|
|
|
597
603
|
} : {
|
|
598
604
|
file: u
|
|
599
605
|
};
|
|
600
|
-
}), a =
|
|
606
|
+
}), a = h(I, t), n = new File(["test"], "blocked.pdf", {
|
|
601
607
|
type: "application/pdf"
|
|
602
608
|
}), s = c.fn();
|
|
603
|
-
|
|
604
|
-
const
|
|
605
|
-
await w.upload(
|
|
609
|
+
r(/* @__PURE__ */ i(l, { fileExtensionsAllowed: ["pdf"], maxSize: 5, onUpload: s, validator: a }));
|
|
610
|
+
const p = o.getByTestId("drag-and-drop-input");
|
|
611
|
+
await w.upload(p, n), await f(() => {
|
|
606
612
|
e(o.getByTestId("drag-and-drop-file-error-0")).toBeInTheDocument(), e(o.getByText("File name blocked")).toBeInTheDocument();
|
|
607
613
|
});
|
|
608
614
|
});
|