@akinon/akiform-builder 1.3.1 → 1.3.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/cjs/__tests__/akiform-builder.test.js +354 -345
- package/dist/cjs/src/akiform-builder.d.ts +1 -1
- package/dist/cjs/src/akiform-builder.d.ts.map +1 -1
- package/dist/cjs/src/akiform-builder.js +1 -1
- package/dist/cjs/src/field-builder.d.ts +3 -3
- package/dist/cjs/src/field-builder.d.ts.map +1 -1
- package/dist/cjs/src/i18n/index.d.ts +4 -1
- package/dist/cjs/src/i18n/index.d.ts.map +1 -1
- package/dist/cjs/src/types.d.ts +4 -4
- package/dist/cjs/src/types.d.ts.map +1 -1
- package/dist/esm/__tests__/akiform-builder.test.js +354 -345
- package/dist/esm/src/akiform-builder.d.ts +1 -1
- package/dist/esm/src/akiform-builder.d.ts.map +1 -1
- package/dist/esm/src/akiform-builder.js +1 -1
- package/dist/esm/src/field-builder.d.ts +3 -3
- package/dist/esm/src/field-builder.d.ts.map +1 -1
- package/dist/esm/src/i18n/index.d.ts +4 -1
- package/dist/esm/src/i18n/index.d.ts.map +1 -1
- package/dist/esm/src/types.d.ts +4 -4
- package/dist/esm/src/types.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
13
|
const akiform_1 = require("@akinon/akiform");
|
|
@@ -12,13 +21,13 @@ describe('AkiformBuilder', () => {
|
|
|
12
21
|
const mockOnSubmit = vi.fn();
|
|
13
22
|
const mockOnReset = vi.fn();
|
|
14
23
|
const mockOnValueChange = vi.fn();
|
|
15
|
-
const expandCollapsable =
|
|
24
|
+
const expandCollapsable = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
25
|
const user = utils_1.userEvent.setup();
|
|
17
|
-
const expandIcons = (
|
|
26
|
+
const expandIcons = (yield utils_1.screen.findAllByRole('button')).filter(el => el.className.includes('akinon-collapse-expand-icon'));
|
|
18
27
|
for (const expandIcon of expandIcons) {
|
|
19
|
-
|
|
28
|
+
yield user.click(expandIcon);
|
|
20
29
|
}
|
|
21
|
-
};
|
|
30
|
+
});
|
|
22
31
|
const defaultFields = [
|
|
23
32
|
{
|
|
24
33
|
key: 'name',
|
|
@@ -38,11 +47,11 @@ describe('AkiformBuilder', () => {
|
|
|
38
47
|
vi.clearAllMocks();
|
|
39
48
|
});
|
|
40
49
|
describe('AkiformBuilder in uncontrolled mode', () => {
|
|
41
|
-
it('renders form fields correctly',
|
|
50
|
+
it('renders form fields correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
51
|
const newDefaultFields = defaultFields.map((field, key) => (Object.assign(Object.assign({}, field), { help: `Description text ${key}`, labelDescription: `Label description text ${key}` })));
|
|
43
|
-
|
|
52
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
53
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: newDefaultFields, onSubmit: mockOnSubmit }));
|
|
45
|
-
});
|
|
54
|
+
}));
|
|
46
55
|
for (const field of newDefaultFields) {
|
|
47
56
|
if (field.label) {
|
|
48
57
|
expect(utils_1.screen.getByText(field.label)).toBeInTheDocument();
|
|
@@ -53,8 +62,8 @@ describe('AkiformBuilder', () => {
|
|
|
53
62
|
expect(utils_1.screen.getByText(field.help)).toBeInTheDocument();
|
|
54
63
|
expect(utils_1.screen.getByText(field.labelDescription)).toBeInTheDocument();
|
|
55
64
|
}
|
|
56
|
-
});
|
|
57
|
-
it('renders form fields correctly with row and column fields',
|
|
65
|
+
}));
|
|
66
|
+
it('renders form fields correctly with row and column fields', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
67
|
const newDefaultFields = [
|
|
59
68
|
{
|
|
60
69
|
type: 'row',
|
|
@@ -120,9 +129,9 @@ describe('AkiformBuilder', () => {
|
|
|
120
129
|
]
|
|
121
130
|
}
|
|
122
131
|
];
|
|
123
|
-
|
|
132
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
133
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: newDefaultFields, onSubmit: mockOnSubmit }));
|
|
125
|
-
});
|
|
134
|
+
}));
|
|
126
135
|
// Check fields
|
|
127
136
|
expect(utils_1.screen.getByLabelText('Test Field 1')).toBeInTheDocument();
|
|
128
137
|
expect(utils_1.screen.getByLabelText('Test Field 2')).toBeInTheDocument();
|
|
@@ -133,8 +142,8 @@ describe('AkiformBuilder', () => {
|
|
|
133
142
|
// Check props
|
|
134
143
|
expect(document.querySelector('.akinon-row-middle')).toBeInTheDocument();
|
|
135
144
|
expect(document.querySelector('.akinon-col-24')).toBeInTheDocument();
|
|
136
|
-
});
|
|
137
|
-
it('handles form with custom field and onChange',
|
|
145
|
+
}));
|
|
146
|
+
it('handles form with custom field and onChange', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
138
147
|
const CustomComponent = ({ field, control }) => {
|
|
139
148
|
const { field: controllerField } = (0, akiform_1.useController)({
|
|
140
149
|
name: field.key,
|
|
@@ -151,25 +160,25 @@ describe('AkiformBuilder', () => {
|
|
|
151
160
|
}
|
|
152
161
|
];
|
|
153
162
|
const onValueChangeMock = vi.fn();
|
|
154
|
-
|
|
163
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
155
164
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: mockOnSubmit, onValueChange: onValueChangeMock }));
|
|
156
|
-
});
|
|
165
|
+
}));
|
|
157
166
|
const customInput = utils_1.screen.getByTestId('custom-input');
|
|
158
167
|
expect(customInput).toBeInTheDocument();
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
});
|
|
162
|
-
|
|
168
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
169
|
+
yield utils_1.userEvent.type(customInput, 'test value');
|
|
170
|
+
}));
|
|
171
|
+
yield (0, utils_1.waitFor)(() => {
|
|
163
172
|
expect(onValueChangeMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
164
173
|
customField: 'test value'
|
|
165
174
|
}));
|
|
166
175
|
});
|
|
167
|
-
});
|
|
168
|
-
it('resets form when reset button is clicked',
|
|
169
|
-
|
|
176
|
+
}));
|
|
177
|
+
it('resets form when reset button is clicked', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
178
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
170
179
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: defaultFields, onSubmit: mockOnSubmit, onReset: mockOnReset, showResetButton: true }));
|
|
171
|
-
});
|
|
172
|
-
|
|
180
|
+
}));
|
|
181
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
173
182
|
utils_1.fireEvent.change(utils_1.screen.getByLabelText('Name'), {
|
|
174
183
|
target: { value: 'John Doe' }
|
|
175
184
|
});
|
|
@@ -177,82 +186,82 @@ describe('AkiformBuilder', () => {
|
|
|
177
186
|
target: { value: '30' }
|
|
178
187
|
});
|
|
179
188
|
utils_1.fireEvent.click(utils_1.screen.getByText('RESET'));
|
|
180
|
-
});
|
|
181
|
-
|
|
189
|
+
}));
|
|
190
|
+
yield (0, utils_1.waitFor)(() => {
|
|
182
191
|
expect(mockOnReset).toHaveBeenCalled();
|
|
183
192
|
expect(utils_1.screen.getByLabelText('Name')).toHaveValue('');
|
|
184
193
|
expect(utils_1.screen.getByLabelText('Age')).toHaveValue('');
|
|
185
194
|
});
|
|
186
|
-
});
|
|
187
|
-
it('exposes reset method through ref',
|
|
195
|
+
}));
|
|
196
|
+
it('exposes reset method through ref', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
188
197
|
const ref = React.createRef();
|
|
189
198
|
const onResetMock = vi.fn();
|
|
190
|
-
|
|
199
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
191
200
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { ref: ref, fields: defaultFields, onSubmit: mockOnSubmit, onReset: onResetMock }));
|
|
192
|
-
});
|
|
201
|
+
}));
|
|
193
202
|
// Fill in some values
|
|
194
|
-
|
|
203
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
195
204
|
utils_1.fireEvent.change(utils_1.screen.getByLabelText('Name'), {
|
|
196
205
|
target: { value: 'John Doe' }
|
|
197
206
|
});
|
|
198
|
-
});
|
|
207
|
+
}));
|
|
199
208
|
// Call reset through ref
|
|
200
|
-
|
|
209
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
201
210
|
var _a;
|
|
202
211
|
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.reset();
|
|
203
|
-
});
|
|
212
|
+
}));
|
|
204
213
|
// Check if form is reset and onReset is called
|
|
205
214
|
expect(utils_1.screen.getByLabelText('Name')).toHaveValue('');
|
|
206
215
|
expect(onResetMock).toHaveBeenCalled();
|
|
207
216
|
// Test partial reset
|
|
208
|
-
|
|
217
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
209
218
|
utils_1.fireEvent.change(utils_1.screen.getByLabelText('Name'), {
|
|
210
219
|
target: { value: 'John Doe' }
|
|
211
220
|
});
|
|
212
221
|
utils_1.fireEvent.change(utils_1.screen.getByLabelText('Age'), {
|
|
213
222
|
target: { value: '30' }
|
|
214
223
|
});
|
|
215
|
-
});
|
|
216
|
-
|
|
224
|
+
}));
|
|
225
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
217
226
|
var _a;
|
|
218
227
|
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.reset({ name: 'Jane Doe' });
|
|
219
|
-
});
|
|
228
|
+
}));
|
|
220
229
|
expect(utils_1.screen.getByLabelText('Name')).toHaveValue('Jane Doe');
|
|
221
230
|
expect(utils_1.screen.getByLabelText('Age')).toHaveValue('30');
|
|
222
|
-
});
|
|
223
|
-
it('calls onValueChange when form values change in uncontrolled mode',
|
|
224
|
-
|
|
231
|
+
}));
|
|
232
|
+
it('calls onValueChange when form values change in uncontrolled mode', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
233
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
225
234
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: defaultFields, onSubmit: mockOnSubmit, onValueChange: mockOnValueChange }));
|
|
226
|
-
});
|
|
227
|
-
|
|
235
|
+
}));
|
|
236
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
228
237
|
utils_1.fireEvent.change(utils_1.screen.getByLabelText('Name'), {
|
|
229
238
|
target: { value: 'John Doe' }
|
|
230
239
|
});
|
|
231
|
-
});
|
|
232
|
-
|
|
240
|
+
}));
|
|
241
|
+
yield (0, utils_1.waitFor)(() => {
|
|
233
242
|
expect(mockOnValueChange).toHaveBeenCalledWith(expect.objectContaining({
|
|
234
243
|
name: 'John Doe'
|
|
235
244
|
}));
|
|
236
245
|
});
|
|
237
|
-
});
|
|
238
|
-
it('applies throttling in uncontrolled mode',
|
|
246
|
+
}));
|
|
247
|
+
it('applies throttling in uncontrolled mode', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
239
248
|
vi.useFakeTimers();
|
|
240
|
-
|
|
249
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
241
250
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: defaultFields, onSubmit: mockOnSubmit, onValueChange: mockOnValueChange }));
|
|
242
|
-
});
|
|
243
|
-
|
|
251
|
+
}));
|
|
252
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
244
253
|
utils_1.fireEvent.change(utils_1.screen.getByLabelText('Name'), {
|
|
245
254
|
target: { value: 'John Doe' }
|
|
246
255
|
});
|
|
247
|
-
});
|
|
256
|
+
}));
|
|
248
257
|
expect(mockOnValueChange).not.toHaveBeenCalled();
|
|
249
|
-
|
|
258
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
250
259
|
vi.advanceTimersByTime(akiform_builder_1.THROTTLE_DELAY);
|
|
251
|
-
});
|
|
260
|
+
}));
|
|
252
261
|
expect(mockOnValueChange).toHaveBeenCalledWith(expect.objectContaining({ name: 'John Doe' }));
|
|
253
262
|
vi.useRealTimers();
|
|
254
|
-
});
|
|
255
|
-
it('renders different field types correctly',
|
|
263
|
+
}));
|
|
264
|
+
it('renders different field types correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
256
265
|
const fields = [
|
|
257
266
|
{
|
|
258
267
|
key: 'name',
|
|
@@ -276,9 +285,9 @@ describe('AkiformBuilder', () => {
|
|
|
276
285
|
{ key: 'birthdate', label: 'Birth Date', type: 'date' },
|
|
277
286
|
{ key: 'bio', label: 'Biography', type: 'textarea' }
|
|
278
287
|
];
|
|
279
|
-
|
|
288
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
280
289
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: mockOnSubmit }));
|
|
281
|
-
});
|
|
290
|
+
}));
|
|
282
291
|
expect(utils_1.screen.getByPlaceholderText('Enter your name')).toHaveAttribute('type', 'text');
|
|
283
292
|
expect(utils_1.screen.getByText('Help text')).toBeInTheDocument();
|
|
284
293
|
expect(utils_1.screen.getByText('Label description text')).toBeInTheDocument();
|
|
@@ -287,8 +296,8 @@ describe('AkiformBuilder', () => {
|
|
|
287
296
|
expect(utils_1.screen.getByLabelText('Subscribe')).toHaveAttribute('type', 'checkbox');
|
|
288
297
|
expect(utils_1.screen.getByLabelText('Birth Date')).toBeInTheDocument();
|
|
289
298
|
expect(utils_1.screen.getByLabelText('Biography')).toBeInTheDocument();
|
|
290
|
-
});
|
|
291
|
-
it('renders field array correctly',
|
|
299
|
+
}));
|
|
300
|
+
it('renders field array correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
292
301
|
const user = utils_1.userEvent.setup();
|
|
293
302
|
const fields = [
|
|
294
303
|
(0, field_builder_1.field)()
|
|
@@ -308,18 +317,18 @@ describe('AkiformBuilder', () => {
|
|
|
308
317
|
])
|
|
309
318
|
.build()
|
|
310
319
|
];
|
|
311
|
-
|
|
320
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
312
321
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: mockOnSubmit }));
|
|
313
|
-
});
|
|
322
|
+
}));
|
|
314
323
|
expect(utils_1.screen.getByText('Add Addresses')).toBeInTheDocument();
|
|
315
|
-
|
|
316
|
-
|
|
324
|
+
yield user.click(utils_1.screen.getByTestId('addresses-add-button'));
|
|
325
|
+
yield expandCollapsable();
|
|
317
326
|
expect(utils_1.screen.getAllByText('Street')).toHaveLength(1);
|
|
318
327
|
expect(utils_1.screen.getAllByText('City')).toHaveLength(1);
|
|
319
328
|
expect(utils_1.screen.getByText('Help text')).toBeInTheDocument();
|
|
320
329
|
expect(utils_1.screen.getByText('Label description text')).toBeInTheDocument();
|
|
321
|
-
});
|
|
322
|
-
it('handles form with field array and nested validation',
|
|
330
|
+
}));
|
|
331
|
+
it('handles form with field array and nested validation', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
323
332
|
const user = utils_1.userEvent.setup();
|
|
324
333
|
const fields = [
|
|
325
334
|
{
|
|
@@ -343,40 +352,40 @@ describe('AkiformBuilder', () => {
|
|
|
343
352
|
}
|
|
344
353
|
];
|
|
345
354
|
const onSubmitMock = vi.fn();
|
|
346
|
-
|
|
355
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
347
356
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: onSubmitMock }));
|
|
348
|
-
});
|
|
357
|
+
}));
|
|
349
358
|
// Add an item
|
|
350
|
-
|
|
359
|
+
yield user.click(utils_1.screen.getByTestId('items-add-button'));
|
|
351
360
|
// Try to submit without filling required fields
|
|
352
|
-
|
|
361
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
353
362
|
utils_1.fireEvent.submit(utils_1.screen.getByTestId('akiform-builder'));
|
|
354
|
-
});
|
|
355
|
-
|
|
363
|
+
}));
|
|
364
|
+
yield (0, utils_1.waitFor)(() => {
|
|
356
365
|
expect(utils_1.screen.getByText('An error occurred in here')).toBeInTheDocument();
|
|
357
366
|
expect(onSubmitMock).not.toHaveBeenCalled();
|
|
358
367
|
});
|
|
359
|
-
|
|
368
|
+
yield expandCollapsable();
|
|
360
369
|
// Fill in valid data
|
|
361
|
-
|
|
370
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
362
371
|
const nameInput = utils_1.screen.getByRole('textbox', { name: /item name/i });
|
|
363
372
|
const quantityInput = utils_1.screen.getByRole('spinbutton', {
|
|
364
373
|
name: /quantity/i
|
|
365
374
|
});
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
});
|
|
375
|
+
yield utils_1.userEvent.type(nameInput, 'Test Item');
|
|
376
|
+
yield utils_1.userEvent.type(quantityInput, '2');
|
|
377
|
+
}));
|
|
369
378
|
// Submit the form
|
|
370
|
-
|
|
379
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
371
380
|
utils_1.fireEvent.submit(utils_1.screen.getByTestId('akiform-builder'));
|
|
372
|
-
});
|
|
373
|
-
|
|
381
|
+
}));
|
|
382
|
+
yield (0, utils_1.waitFor)(() => {
|
|
374
383
|
expect(onSubmitMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
375
384
|
items: [{ name: 'Test Item', quantity: 2 }]
|
|
376
385
|
}), expect.anything());
|
|
377
386
|
});
|
|
378
|
-
});
|
|
379
|
-
it('handles field array operations correctly',
|
|
387
|
+
}));
|
|
388
|
+
it('handles field array operations correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
380
389
|
const user = utils_1.userEvent.setup();
|
|
381
390
|
const fields = [
|
|
382
391
|
{
|
|
@@ -397,25 +406,25 @@ describe('AkiformBuilder', () => {
|
|
|
397
406
|
} }),
|
|
398
407
|
React.createElement("div", { "data-testid": "form-values" }, JSON.stringify(formValues))));
|
|
399
408
|
};
|
|
400
|
-
|
|
409
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
401
410
|
(0, utils_1.render)(React.createElement(TestComponent, null));
|
|
402
|
-
});
|
|
411
|
+
}));
|
|
403
412
|
// Add an item
|
|
404
|
-
|
|
405
|
-
|
|
413
|
+
yield user.click(utils_1.screen.getByTestId('items-add-button'));
|
|
414
|
+
yield expandCollapsable();
|
|
406
415
|
// Fill in the fields
|
|
407
|
-
|
|
416
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
408
417
|
utils_1.fireEvent.change(utils_1.screen.getByLabelText('Item Name'), {
|
|
409
418
|
target: { value: 'Test Item' }
|
|
410
419
|
});
|
|
411
|
-
});
|
|
412
|
-
|
|
420
|
+
}));
|
|
421
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
413
422
|
utils_1.fireEvent.change(utils_1.screen.getByLabelText('Quantity'), {
|
|
414
423
|
target: { value: '5' }
|
|
415
424
|
});
|
|
416
|
-
});
|
|
425
|
+
}));
|
|
417
426
|
// Wait for the form values to update
|
|
418
|
-
|
|
427
|
+
yield (0, utils_1.waitFor)(() => {
|
|
419
428
|
const formValuesElement = utils_1.screen.getByTestId('form-values');
|
|
420
429
|
const formValues = JSON.parse(formValuesElement.textContent || '{}');
|
|
421
430
|
expect(formValues).toEqual(expect.objectContaining({
|
|
@@ -423,24 +432,24 @@ describe('AkiformBuilder', () => {
|
|
|
423
432
|
}));
|
|
424
433
|
});
|
|
425
434
|
// Submit the form
|
|
426
|
-
|
|
435
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
427
436
|
utils_1.fireEvent.submit(utils_1.screen.getByTestId('akiform-builder'));
|
|
428
|
-
});
|
|
437
|
+
}));
|
|
429
438
|
// Check the submitted values
|
|
430
|
-
|
|
439
|
+
yield (0, utils_1.waitFor)(() => {
|
|
431
440
|
expect(mockOnSubmit).toHaveBeenCalledWith(expect.objectContaining({
|
|
432
441
|
items: [{ name: 'Test Item', quantity: 5 }]
|
|
433
442
|
}), expect.anything());
|
|
434
443
|
});
|
|
435
|
-
});
|
|
436
|
-
it('applies layout options correctly',
|
|
437
|
-
|
|
444
|
+
}));
|
|
445
|
+
it('applies layout options correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
446
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
438
447
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: defaultFields, onSubmit: mockOnSubmit, layout: "horizontal", layoutOptions: { labelCol: { span: 8 }, wrapperCol: { span: 16 } } }));
|
|
439
|
-
});
|
|
448
|
+
}));
|
|
440
449
|
const form = utils_1.screen.getByTestId('akiform-builder');
|
|
441
450
|
expect(form).toHaveClass('akinon-form-horizontal');
|
|
442
|
-
});
|
|
443
|
-
it('conditionally renders and disables fields',
|
|
451
|
+
}));
|
|
452
|
+
it('conditionally renders and disables fields', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
444
453
|
const fields = [
|
|
445
454
|
{ key: 'showField', label: 'Show Field', type: 'checkbox' },
|
|
446
455
|
{
|
|
@@ -457,21 +466,21 @@ describe('AkiformBuilder', () => {
|
|
|
457
466
|
config: { disabled: values => !values.enableField }
|
|
458
467
|
}
|
|
459
468
|
];
|
|
460
|
-
|
|
469
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
461
470
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: mockOnSubmit }));
|
|
462
|
-
});
|
|
471
|
+
}));
|
|
463
472
|
expect(utils_1.screen.queryByLabelText('Conditional Field')).not.toBeInTheDocument();
|
|
464
|
-
|
|
473
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
465
474
|
utils_1.fireEvent.click(utils_1.screen.getByLabelText('Show Field'));
|
|
466
|
-
});
|
|
475
|
+
}));
|
|
467
476
|
expect(utils_1.screen.getByLabelText('Conditional Field')).toBeInTheDocument();
|
|
468
477
|
expect(utils_1.screen.getByLabelText('Disableable Field')).toBeDisabled();
|
|
469
|
-
|
|
478
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
470
479
|
utils_1.fireEvent.click(utils_1.screen.getByLabelText('Enable Field'));
|
|
471
|
-
});
|
|
480
|
+
}));
|
|
472
481
|
expect(utils_1.screen.getByLabelText('Disableable Field')).not.toBeDisabled();
|
|
473
|
-
});
|
|
474
|
-
it('applies custom validation',
|
|
482
|
+
}));
|
|
483
|
+
it('applies custom validation', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
475
484
|
const fields = [
|
|
476
485
|
{
|
|
477
486
|
key: 'email',
|
|
@@ -480,40 +489,40 @@ describe('AkiformBuilder', () => {
|
|
|
480
489
|
validation: akival_1.akival.string().email('Invalid email format')
|
|
481
490
|
}
|
|
482
491
|
];
|
|
483
|
-
|
|
492
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
484
493
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: mockOnSubmit }));
|
|
485
|
-
});
|
|
486
|
-
|
|
494
|
+
}));
|
|
495
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
487
496
|
utils_1.fireEvent.change(utils_1.screen.getByRole('textbox', { name: /email/i }), {
|
|
488
497
|
target: { value: 'invalid-email' }
|
|
489
498
|
});
|
|
490
499
|
utils_1.fireEvent.submit(utils_1.screen.getByTestId('akiform-builder'));
|
|
491
|
-
});
|
|
492
|
-
|
|
500
|
+
}));
|
|
501
|
+
yield (0, utils_1.waitFor)(() => {
|
|
493
502
|
expect(utils_1.screen.getByText('Invalid email format')).toBeInTheDocument();
|
|
494
503
|
});
|
|
495
|
-
});
|
|
496
|
-
it('resets form using ref',
|
|
504
|
+
}));
|
|
505
|
+
it('resets form using ref', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
497
506
|
const ref = React.createRef();
|
|
498
|
-
|
|
507
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
499
508
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { ref: ref, fields: defaultFields, onSubmit: mockOnSubmit }));
|
|
500
|
-
});
|
|
501
|
-
|
|
509
|
+
}));
|
|
510
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
502
511
|
utils_1.fireEvent.change(utils_1.screen.getByLabelText('Name'), {
|
|
503
512
|
target: { value: 'John Doe' }
|
|
504
513
|
});
|
|
505
514
|
utils_1.fireEvent.change(utils_1.screen.getByLabelText('Age'), {
|
|
506
515
|
target: { value: '30' }
|
|
507
516
|
});
|
|
508
|
-
});
|
|
509
|
-
|
|
517
|
+
}));
|
|
518
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
510
519
|
var _a;
|
|
511
520
|
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.reset();
|
|
512
|
-
});
|
|
521
|
+
}));
|
|
513
522
|
expect(utils_1.screen.getByLabelText('Name')).toHaveValue('');
|
|
514
523
|
expect(utils_1.screen.getByLabelText('Age')).toHaveValue('');
|
|
515
|
-
});
|
|
516
|
-
it('displays error states',
|
|
524
|
+
}));
|
|
525
|
+
it('displays error states', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
517
526
|
const fields = [
|
|
518
527
|
{
|
|
519
528
|
key: 'name',
|
|
@@ -522,22 +531,22 @@ describe('AkiformBuilder', () => {
|
|
|
522
531
|
validation: akival_1.akival.string().required('Name is required')
|
|
523
532
|
}
|
|
524
533
|
];
|
|
525
|
-
|
|
534
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
526
535
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: mockOnSubmit }));
|
|
527
|
-
});
|
|
528
|
-
|
|
536
|
+
}));
|
|
537
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
529
538
|
utils_1.fireEvent.submit(utils_1.screen.getByTestId('akiform-builder'));
|
|
530
|
-
});
|
|
531
|
-
|
|
539
|
+
}));
|
|
540
|
+
yield (0, utils_1.waitFor)(() => {
|
|
532
541
|
expect(utils_1.screen.getByText('Name is required')).toBeInTheDocument();
|
|
533
542
|
});
|
|
534
|
-
});
|
|
535
|
-
it('handles form submission',
|
|
543
|
+
}));
|
|
544
|
+
it('handles form submission', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
536
545
|
const onSubmit = vi.fn();
|
|
537
|
-
|
|
546
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
538
547
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: defaultFields, onSubmit: onSubmit }));
|
|
539
|
-
});
|
|
540
|
-
|
|
548
|
+
}));
|
|
549
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
541
550
|
utils_1.fireEvent.change(utils_1.screen.getByLabelText('Name'), {
|
|
542
551
|
target: { value: 'John Doe' }
|
|
543
552
|
});
|
|
@@ -545,15 +554,15 @@ describe('AkiformBuilder', () => {
|
|
|
545
554
|
target: { value: '30' }
|
|
546
555
|
});
|
|
547
556
|
utils_1.fireEvent.submit(utils_1.screen.getByTestId('akiform-builder'));
|
|
548
|
-
});
|
|
549
|
-
|
|
557
|
+
}));
|
|
558
|
+
yield (0, utils_1.waitFor)(() => {
|
|
550
559
|
expect(onSubmit).toHaveBeenCalledWith(expect.objectContaining({
|
|
551
560
|
name: 'John Doe',
|
|
552
561
|
age: 30
|
|
553
562
|
}), expect.anything());
|
|
554
563
|
});
|
|
555
|
-
});
|
|
556
|
-
it('handles form submission with errors',
|
|
564
|
+
}));
|
|
565
|
+
it('handles form submission with errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
557
566
|
const fields = [
|
|
558
567
|
{
|
|
559
568
|
key: 'name',
|
|
@@ -563,35 +572,35 @@ describe('AkiformBuilder', () => {
|
|
|
563
572
|
}
|
|
564
573
|
];
|
|
565
574
|
const onSubmit = vi.fn();
|
|
566
|
-
|
|
575
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
567
576
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: onSubmit }));
|
|
568
|
-
});
|
|
569
|
-
|
|
577
|
+
}));
|
|
578
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
570
579
|
utils_1.fireEvent.submit(utils_1.screen.getByTestId('akiform-builder'));
|
|
571
|
-
});
|
|
572
|
-
|
|
580
|
+
}));
|
|
581
|
+
yield (0, utils_1.waitFor)(() => {
|
|
573
582
|
expect(utils_1.screen.getByText('Name is required')).toBeInTheDocument();
|
|
574
583
|
expect(onSubmit).not.toHaveBeenCalled();
|
|
575
584
|
});
|
|
576
|
-
});
|
|
577
|
-
it('handles form with initial values',
|
|
585
|
+
}));
|
|
586
|
+
it('handles form with initial values', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
578
587
|
const initialValues = { name: 'John Doe', age: 30 };
|
|
579
|
-
|
|
588
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
580
589
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: defaultFields, onSubmit: mockOnSubmit, initialValues: initialValues }));
|
|
581
|
-
});
|
|
582
|
-
|
|
590
|
+
}));
|
|
591
|
+
yield (0, utils_1.waitFor)(() => {
|
|
583
592
|
expect(utils_1.screen.getByLabelText('Name')).toHaveValue('John Doe');
|
|
584
593
|
expect(utils_1.screen.getByLabelText('Age')).toHaveValue('30');
|
|
585
594
|
});
|
|
586
|
-
});
|
|
587
|
-
it('handles form with custom layout',
|
|
588
|
-
|
|
595
|
+
}));
|
|
596
|
+
it('handles form with custom layout', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
597
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
589
598
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: defaultFields, onSubmit: mockOnSubmit, layout: "vertical" }));
|
|
590
|
-
});
|
|
599
|
+
}));
|
|
591
600
|
const form = utils_1.screen.getByTestId('akiform-builder');
|
|
592
601
|
expect(form).toHaveClass('akinon-form-vertical');
|
|
593
|
-
});
|
|
594
|
-
it('renders custom field correctly',
|
|
602
|
+
}));
|
|
603
|
+
it('renders custom field correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
595
604
|
const CustomComponent = ({ field }) => (React.createElement("div", { "data-testid": "custom-field" }, field.label));
|
|
596
605
|
const fields = [
|
|
597
606
|
{
|
|
@@ -603,30 +612,30 @@ describe('AkiformBuilder', () => {
|
|
|
603
612
|
render: ({ field }) => (React.createElement(CustomComponent, { field: field }))
|
|
604
613
|
}
|
|
605
614
|
];
|
|
606
|
-
|
|
615
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
607
616
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
608
|
-
});
|
|
617
|
+
}));
|
|
609
618
|
expect(utils_1.screen.getByTestId('custom-field')).toHaveTextContent('Custom Field');
|
|
610
619
|
expect(utils_1.screen.getByText('Help text')).toBeInTheDocument();
|
|
611
620
|
expect(utils_1.screen.getByText('Label description text')).toBeInTheDocument();
|
|
612
|
-
});
|
|
613
|
-
it('cleans up throttle timeout on unmount',
|
|
621
|
+
}));
|
|
622
|
+
it('cleans up throttle timeout on unmount', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
614
623
|
vi.useFakeTimers();
|
|
615
624
|
const { unmount } = (0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: defaultFields, onSubmit: mockOnSubmit, onValueChange: mockOnValueChange }));
|
|
616
|
-
|
|
625
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
617
626
|
utils_1.fireEvent.change(utils_1.screen.getByLabelText('Name'), {
|
|
618
627
|
target: { value: 'John Doe' }
|
|
619
628
|
});
|
|
620
|
-
});
|
|
629
|
+
}));
|
|
621
630
|
unmount();
|
|
622
631
|
// Advance timers and ensure onValueChange is not called
|
|
623
|
-
|
|
632
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
624
633
|
vi.advanceTimersByTime(akiform_builder_1.THROTTLE_DELAY + 100);
|
|
625
|
-
});
|
|
634
|
+
}));
|
|
626
635
|
expect(mockOnValueChange).not.toHaveBeenCalled();
|
|
627
636
|
vi.useRealTimers();
|
|
628
|
-
});
|
|
629
|
-
it('handles custom field with undefined render prop',
|
|
637
|
+
}));
|
|
638
|
+
it('handles custom field with undefined render prop', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
630
639
|
const fields = [
|
|
631
640
|
{
|
|
632
641
|
key: 'customField',
|
|
@@ -635,15 +644,15 @@ describe('AkiformBuilder', () => {
|
|
|
635
644
|
render: undefined
|
|
636
645
|
}
|
|
637
646
|
];
|
|
638
|
-
|
|
647
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
639
648
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
640
|
-
});
|
|
649
|
+
}));
|
|
641
650
|
// The custom field should not be rendered, but the form should not crash
|
|
642
651
|
expect(utils_1.screen.queryByLabelText('Custom Field')).not.toBeInTheDocument();
|
|
643
652
|
// The form should still be rendered
|
|
644
653
|
expect(utils_1.screen.getByTestId('akiform-builder')).toBeInTheDocument();
|
|
645
|
-
});
|
|
646
|
-
it('renders custom submit and reset button props',
|
|
654
|
+
}));
|
|
655
|
+
it('renders custom submit and reset button props', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
647
656
|
const submitButtonProps = {
|
|
648
657
|
className: 'custom-submit-btn',
|
|
649
658
|
children: 'submit button'
|
|
@@ -652,9 +661,9 @@ describe('AkiformBuilder', () => {
|
|
|
652
661
|
className: 'custom-reset-btn',
|
|
653
662
|
children: 'reset button'
|
|
654
663
|
};
|
|
655
|
-
|
|
664
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
656
665
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: defaultFields, onSubmit: mockOnSubmit, showResetButton: true, onReset: mockOnReset, submitButtonProps: submitButtonProps, resetButtonProps: resetButtonProps }));
|
|
657
|
-
});
|
|
666
|
+
}));
|
|
658
667
|
const submitButton = utils_1.screen
|
|
659
668
|
.getByText(submitButtonProps.children)
|
|
660
669
|
.closest('button');
|
|
@@ -665,51 +674,51 @@ describe('AkiformBuilder', () => {
|
|
|
665
674
|
expect(resetButton).toBeInTheDocument();
|
|
666
675
|
expect(submitButton).toHaveClass(submitButtonProps.className);
|
|
667
676
|
expect(resetButton).toHaveClass(resetButtonProps.className);
|
|
668
|
-
|
|
677
|
+
yield utils_1.userEvent.click(resetButton);
|
|
669
678
|
expect(mockOnReset).toHaveBeenCalled();
|
|
670
|
-
|
|
679
|
+
yield utils_1.userEvent.click(submitButton);
|
|
671
680
|
expect(mockOnSubmit).toHaveBeenCalled();
|
|
672
|
-
});
|
|
681
|
+
}));
|
|
673
682
|
});
|
|
674
683
|
describe('AkiformBuilder in controlled mode', () => {
|
|
675
|
-
it('uses provided values in controlled mode',
|
|
684
|
+
it('uses provided values in controlled mode', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
676
685
|
const fields = [
|
|
677
686
|
{ key: 'name', label: 'Name', type: 'text' },
|
|
678
687
|
{ key: 'age', label: 'Age', type: 'number' }
|
|
679
688
|
];
|
|
680
689
|
const controlledValues = { name: 'John Doe', age: 30 };
|
|
681
690
|
const onChangeMock = vi.fn();
|
|
682
|
-
|
|
691
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
683
692
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn(), controlled: true, values: controlledValues, onValueChange: onChangeMock }));
|
|
684
|
-
});
|
|
693
|
+
}));
|
|
685
694
|
expect(utils_1.screen.getByLabelText('Name')).toHaveValue('John Doe');
|
|
686
695
|
expect(utils_1.screen.getByLabelText('Age')).toHaveValue('30');
|
|
687
|
-
});
|
|
688
|
-
it('calls onValueChange when form values change in controlled mode',
|
|
696
|
+
}));
|
|
697
|
+
it('calls onValueChange when form values change in controlled mode', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
689
698
|
const fields = [
|
|
690
699
|
{ key: 'name', label: 'Name', type: 'text' }
|
|
691
700
|
];
|
|
692
701
|
const onChangeMock = vi.fn();
|
|
693
|
-
|
|
702
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
694
703
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn(), controlled: true, values: { name: '' }, onValueChange: onChangeMock }));
|
|
695
|
-
});
|
|
696
|
-
|
|
704
|
+
}));
|
|
705
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
697
706
|
utils_1.fireEvent.change(utils_1.screen.getByLabelText('Name'), {
|
|
698
707
|
target: { value: 'Jane Doe' }
|
|
699
708
|
});
|
|
700
|
-
});
|
|
701
|
-
|
|
709
|
+
}));
|
|
710
|
+
yield (0, utils_1.waitFor)(() => {
|
|
702
711
|
expect(onChangeMock).toHaveBeenCalledWith(expect.objectContaining({ name: 'Jane Doe' }));
|
|
703
712
|
});
|
|
704
|
-
});
|
|
705
|
-
it('calls onValueChange immediately in controlled mode',
|
|
713
|
+
}));
|
|
714
|
+
it('calls onValueChange immediately in controlled mode', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
706
715
|
const onValueChangeMock = vi.fn();
|
|
707
|
-
|
|
716
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
708
717
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: defaultFields, onSubmit: mockOnSubmit, controlled: true, values: { name: 'John Doe', age: 30 }, onValueChange: onValueChangeMock }));
|
|
709
|
-
});
|
|
718
|
+
}));
|
|
710
719
|
expect(onValueChangeMock).toHaveBeenCalledWith(expect.objectContaining({ name: 'John Doe', age: 30 }));
|
|
711
|
-
});
|
|
712
|
-
it('handles conditional rendering and disabling of fields',
|
|
720
|
+
}));
|
|
721
|
+
it('handles conditional rendering and disabling of fields', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
713
722
|
const fields = [
|
|
714
723
|
{ key: 'showField', label: 'Show Field', type: 'checkbox' },
|
|
715
724
|
{
|
|
@@ -727,25 +736,25 @@ describe('AkiformBuilder', () => {
|
|
|
727
736
|
}
|
|
728
737
|
];
|
|
729
738
|
const onValueChangeMock = vi.fn();
|
|
730
|
-
|
|
739
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
731
740
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn(), controlled: true, values: { showField: false, enableField: false }, onValueChange: onValueChangeMock }));
|
|
732
|
-
});
|
|
741
|
+
}));
|
|
733
742
|
expect(utils_1.screen.queryByLabelText('Conditional Field')).not.toBeInTheDocument();
|
|
734
743
|
expect(utils_1.screen.getByLabelText('Disableable Field')).toBeDisabled();
|
|
735
|
-
|
|
744
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
736
745
|
utils_1.fireEvent.click(utils_1.screen.getByLabelText('Show Field'));
|
|
737
746
|
utils_1.fireEvent.click(utils_1.screen.getByLabelText('Enable Field'));
|
|
738
|
-
});
|
|
747
|
+
}));
|
|
739
748
|
expect(utils_1.screen.getByLabelText('Conditional Field')).toBeInTheDocument();
|
|
740
749
|
expect(utils_1.screen.getByLabelText('Disableable Field')).not.toBeDisabled();
|
|
741
750
|
expect(onValueChangeMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
742
751
|
showField: true,
|
|
743
752
|
enableField: true
|
|
744
753
|
}));
|
|
745
|
-
});
|
|
754
|
+
}));
|
|
746
755
|
});
|
|
747
756
|
describe('FieldArrayComponent', () => {
|
|
748
|
-
it('renders field array with initial values',
|
|
757
|
+
it('renders field array with initial values', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
749
758
|
const fields = [
|
|
750
759
|
{
|
|
751
760
|
key: 'items',
|
|
@@ -763,14 +772,14 @@ describe('AkiformBuilder', () => {
|
|
|
763
772
|
{ name: 'Item 2', quantity: 2 }
|
|
764
773
|
]
|
|
765
774
|
};
|
|
766
|
-
|
|
775
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
767
776
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn(), initialValues: initialValues }));
|
|
768
|
-
});
|
|
769
|
-
|
|
777
|
+
}));
|
|
778
|
+
yield expandCollapsable();
|
|
770
779
|
expect(utils_1.screen.getAllByLabelText('Item Name')).toHaveLength(2);
|
|
771
780
|
expect(utils_1.screen.getAllByLabelText('Quantity')).toHaveLength(2);
|
|
772
|
-
});
|
|
773
|
-
it('adds and removes field array items',
|
|
781
|
+
}));
|
|
782
|
+
it('adds and removes field array items', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
774
783
|
const user = utils_1.userEvent.setup();
|
|
775
784
|
const fields = [
|
|
776
785
|
{
|
|
@@ -780,23 +789,23 @@ describe('AkiformBuilder', () => {
|
|
|
780
789
|
fields: [{ key: 'name', label: 'Item Name', type: 'text' }]
|
|
781
790
|
}
|
|
782
791
|
];
|
|
783
|
-
|
|
792
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
784
793
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
785
|
-
});
|
|
794
|
+
}));
|
|
786
795
|
// Add an item
|
|
787
|
-
|
|
788
|
-
|
|
796
|
+
yield user.click(utils_1.screen.getByTestId('items-add-button'));
|
|
797
|
+
yield expandCollapsable();
|
|
789
798
|
expect(utils_1.screen.getByLabelText('Item Name')).toBeInTheDocument();
|
|
790
799
|
// Add another item
|
|
791
|
-
|
|
792
|
-
|
|
800
|
+
yield user.click(utils_1.screen.getByLabelText('Add Items'));
|
|
801
|
+
yield expandCollapsable();
|
|
793
802
|
expect(utils_1.screen.getAllByLabelText('Item Name')).toHaveLength(2);
|
|
794
803
|
// Remove an item
|
|
795
|
-
|
|
796
|
-
|
|
804
|
+
yield user.click(utils_1.screen.getAllByLabelText('Remove Items')[0]);
|
|
805
|
+
yield expandCollapsable();
|
|
797
806
|
expect(utils_1.screen.getAllByLabelText('Item Name')).toHaveLength(1);
|
|
798
|
-
});
|
|
799
|
-
it('handles field array with conditional fields',
|
|
807
|
+
}));
|
|
808
|
+
it('handles field array with conditional fields', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
800
809
|
const user = utils_1.userEvent.setup();
|
|
801
810
|
const fields = [
|
|
802
811
|
{
|
|
@@ -817,28 +826,28 @@ describe('AkiformBuilder', () => {
|
|
|
817
826
|
}
|
|
818
827
|
];
|
|
819
828
|
const { rerender } = (0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
820
|
-
|
|
829
|
+
yield expandCollapsable();
|
|
821
830
|
// Add an item
|
|
822
|
-
|
|
823
|
-
|
|
831
|
+
yield user.click(utils_1.screen.getByLabelText('Add Items'));
|
|
832
|
+
yield expandCollapsable();
|
|
824
833
|
// Description should not be visible initially
|
|
825
834
|
expect(utils_1.screen.queryByLabelText('Description')).not.toBeInTheDocument();
|
|
826
835
|
// Enter a name longer than 5 characters
|
|
827
|
-
|
|
836
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
828
837
|
utils_1.fireEvent.change(utils_1.screen.getByLabelText('Item Name'), {
|
|
829
838
|
target: { value: 'Long Name' }
|
|
830
839
|
});
|
|
831
|
-
});
|
|
840
|
+
}));
|
|
832
841
|
// Force a re-render to trigger the conditional rendering
|
|
833
842
|
rerender(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
834
843
|
// Description should now be visible
|
|
835
|
-
|
|
844
|
+
yield (0, utils_1.waitFor)(() => {
|
|
836
845
|
expect(utils_1.screen.getByLabelText('Description')).toBeInTheDocument();
|
|
837
846
|
});
|
|
838
|
-
});
|
|
847
|
+
}));
|
|
839
848
|
});
|
|
840
849
|
describe('Edge cases and uncovered scenarios', () => {
|
|
841
|
-
it('handles field array with no fields',
|
|
850
|
+
it('handles field array with no fields', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
842
851
|
const fields = [
|
|
843
852
|
{
|
|
844
853
|
key: 'emptyFieldArray',
|
|
@@ -847,13 +856,13 @@ describe('AkiformBuilder', () => {
|
|
|
847
856
|
fields: []
|
|
848
857
|
}
|
|
849
858
|
];
|
|
850
|
-
|
|
859
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
851
860
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
852
|
-
});
|
|
861
|
+
}));
|
|
853
862
|
// The field array should be rendered with an "Add" button
|
|
854
863
|
expect(utils_1.screen.getByTestId('emptyFieldArray-add-button')).toBeInTheDocument();
|
|
855
|
-
});
|
|
856
|
-
it('handles form submission with field array',
|
|
864
|
+
}));
|
|
865
|
+
it('handles form submission with field array', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
857
866
|
const user = utils_1.userEvent.setup();
|
|
858
867
|
const fields = [
|
|
859
868
|
{
|
|
@@ -867,27 +876,27 @@ describe('AkiformBuilder', () => {
|
|
|
867
876
|
}
|
|
868
877
|
];
|
|
869
878
|
const onSubmitMock = vi.fn();
|
|
870
|
-
|
|
879
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
871
880
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: onSubmitMock }));
|
|
872
|
-
});
|
|
881
|
+
}));
|
|
873
882
|
// Add two items
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
883
|
+
yield user.click(utils_1.screen.getByTestId('items-add-button'));
|
|
884
|
+
yield user.click(utils_1.screen.getByLabelText('Add Items'));
|
|
885
|
+
yield expandCollapsable();
|
|
877
886
|
// Fill in the fields
|
|
878
887
|
const itemNames = utils_1.screen.getAllByLabelText('Item Name');
|
|
879
888
|
const quantities = utils_1.screen.getAllByLabelText('Quantity');
|
|
880
|
-
|
|
889
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
881
890
|
utils_1.fireEvent.change(itemNames[0], { target: { value: 'Item 1' } });
|
|
882
891
|
utils_1.fireEvent.change(quantities[0], { target: { value: '5' } });
|
|
883
892
|
utils_1.fireEvent.change(itemNames[1], { target: { value: 'Item 2' } });
|
|
884
893
|
utils_1.fireEvent.change(quantities[1], { target: { value: '10' } });
|
|
885
|
-
});
|
|
894
|
+
}));
|
|
886
895
|
// Submit the form
|
|
887
|
-
|
|
896
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
888
897
|
utils_1.fireEvent.submit(utils_1.screen.getByTestId('akiform-builder'));
|
|
889
|
-
});
|
|
890
|
-
|
|
898
|
+
}));
|
|
899
|
+
yield (0, utils_1.waitFor)(() => {
|
|
891
900
|
expect(onSubmitMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
892
901
|
items: [
|
|
893
902
|
{ name: 'Item 1', quantity: 5 },
|
|
@@ -895,8 +904,8 @@ describe('AkiformBuilder', () => {
|
|
|
895
904
|
]
|
|
896
905
|
}), expect.anything());
|
|
897
906
|
});
|
|
898
|
-
});
|
|
899
|
-
it('handles form with all field types',
|
|
907
|
+
}));
|
|
908
|
+
it('handles form with all field types', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
900
909
|
const fields = [
|
|
901
910
|
{ key: 'text', label: 'Text', type: 'text' },
|
|
902
911
|
{ key: 'number', label: 'Number', type: 'number' },
|
|
@@ -922,9 +931,9 @@ describe('AkiformBuilder', () => {
|
|
|
922
931
|
render: () => React.createElement("div", { "data-testid": "custom-field" }, "Custom Field")
|
|
923
932
|
}
|
|
924
933
|
];
|
|
925
|
-
|
|
934
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
926
935
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
927
|
-
});
|
|
936
|
+
}));
|
|
928
937
|
expect(utils_1.screen.getByLabelText('Text')).toBeInTheDocument();
|
|
929
938
|
expect(utils_1.screen.getByLabelText('Number')).toBeInTheDocument();
|
|
930
939
|
expect(utils_1.screen.getByLabelText('Select')).toBeInTheDocument();
|
|
@@ -933,27 +942,27 @@ describe('AkiformBuilder', () => {
|
|
|
933
942
|
expect(utils_1.screen.getByLabelText('Textarea')).toBeInTheDocument();
|
|
934
943
|
expect(utils_1.screen.getByTestId('fieldArray-add-button')).toBeInTheDocument(); // For field array
|
|
935
944
|
expect(utils_1.screen.getByTestId('custom-field')).toBeInTheDocument();
|
|
936
|
-
});
|
|
937
|
-
it('handles form with inline layout',
|
|
938
|
-
|
|
945
|
+
}));
|
|
946
|
+
it('handles form with inline layout', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
947
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
939
948
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: defaultFields, onSubmit: vi.fn(), layout: "inline" }));
|
|
940
|
-
});
|
|
949
|
+
}));
|
|
941
950
|
const form = utils_1.screen.getByTestId('akiform-builder');
|
|
942
951
|
expect(form).toHaveClass('akinon-form-inline');
|
|
943
|
-
});
|
|
944
|
-
it('handles form reset with custom reset handler',
|
|
952
|
+
}));
|
|
953
|
+
it('handles form reset with custom reset handler', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
945
954
|
const onResetMock = vi.fn();
|
|
946
|
-
|
|
955
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
947
956
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: defaultFields, onSubmit: vi.fn(), onReset: onResetMock, showResetButton: true }));
|
|
948
|
-
});
|
|
949
|
-
|
|
957
|
+
}));
|
|
958
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
950
959
|
utils_1.fireEvent.click(utils_1.screen.getByText('RESET'));
|
|
951
|
-
});
|
|
960
|
+
}));
|
|
952
961
|
expect(onResetMock).toHaveBeenCalled();
|
|
953
|
-
});
|
|
962
|
+
}));
|
|
954
963
|
});
|
|
955
964
|
describe('AkiformBuilder with FieldBuilder', () => {
|
|
956
|
-
it('renders form fields created with FieldBuilder',
|
|
965
|
+
it('renders form fields created with FieldBuilder', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
957
966
|
const fields = [
|
|
958
967
|
(0, field_builder_1.field)()
|
|
959
968
|
.key('name')
|
|
@@ -986,9 +995,9 @@ describe('AkiformBuilder', () => {
|
|
|
986
995
|
(0, field_builder_1.field)().key('birthdate').label('Birth Date').type('date').build(),
|
|
987
996
|
(0, field_builder_1.field)().key('description').label('Description').type('textarea').build()
|
|
988
997
|
];
|
|
989
|
-
|
|
998
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
990
999
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
991
|
-
});
|
|
1000
|
+
}));
|
|
992
1001
|
expect(utils_1.screen.getByText('Name')).toBeInTheDocument();
|
|
993
1002
|
expect(utils_1.screen.getByText('Label description text')).toBeInTheDocument();
|
|
994
1003
|
expect(utils_1.screen.getByText('Help text')).toBeInTheDocument();
|
|
@@ -997,8 +1006,8 @@ describe('AkiformBuilder', () => {
|
|
|
997
1006
|
expect(utils_1.screen.getByLabelText('Subscribe to newsletter')).toBeInTheDocument();
|
|
998
1007
|
expect(utils_1.screen.getByLabelText('Birth Date')).toBeInTheDocument();
|
|
999
1008
|
expect(utils_1.screen.getByLabelText('Description')).toBeInTheDocument();
|
|
1000
|
-
});
|
|
1001
|
-
it('handles form submission with fields created by FieldBuilder',
|
|
1009
|
+
}));
|
|
1010
|
+
it('handles form submission with fields created by FieldBuilder', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1002
1011
|
const fields = [
|
|
1003
1012
|
(0, field_builder_1.field)()
|
|
1004
1013
|
.key('name')
|
|
@@ -1014,10 +1023,10 @@ describe('AkiformBuilder', () => {
|
|
|
1014
1023
|
.build()
|
|
1015
1024
|
];
|
|
1016
1025
|
const onSubmitMock = vi.fn();
|
|
1017
|
-
|
|
1026
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1018
1027
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: onSubmitMock }));
|
|
1019
|
-
});
|
|
1020
|
-
|
|
1028
|
+
}));
|
|
1029
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1021
1030
|
utils_1.fireEvent.change(utils_1.screen.getByRole('textbox', { name: /name/i }), {
|
|
1022
1031
|
target: { value: 'John Doe' }
|
|
1023
1032
|
});
|
|
@@ -1025,15 +1034,15 @@ describe('AkiformBuilder', () => {
|
|
|
1025
1034
|
target: { value: '25' }
|
|
1026
1035
|
});
|
|
1027
1036
|
utils_1.fireEvent.submit(utils_1.screen.getByTestId('akiform-builder'));
|
|
1028
|
-
});
|
|
1029
|
-
|
|
1037
|
+
}));
|
|
1038
|
+
yield (0, utils_1.waitFor)(() => {
|
|
1030
1039
|
expect(onSubmitMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
1031
1040
|
name: 'John Doe',
|
|
1032
1041
|
age: 25
|
|
1033
1042
|
}), expect.anything());
|
|
1034
1043
|
});
|
|
1035
|
-
});
|
|
1036
|
-
it('handles form with custom field created by FieldBuilder',
|
|
1044
|
+
}));
|
|
1045
|
+
it('handles form with custom field created by FieldBuilder', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1037
1046
|
const CustomComponent = ({ field }) => (React.createElement("div", { "data-testid": "custom-field" }, field.label));
|
|
1038
1047
|
const fields = [
|
|
1039
1048
|
(0, field_builder_1.field)()
|
|
@@ -1045,14 +1054,14 @@ describe('AkiformBuilder', () => {
|
|
|
1045
1054
|
.render(({ field }) => React.createElement(CustomComponent, { field: field }))
|
|
1046
1055
|
.build()
|
|
1047
1056
|
];
|
|
1048
|
-
|
|
1057
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1049
1058
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
1050
|
-
});
|
|
1059
|
+
}));
|
|
1051
1060
|
expect(utils_1.screen.getByTestId('custom-field')).toHaveTextContent('Custom Field');
|
|
1052
1061
|
expect(utils_1.screen.getByText('Help text')).toBeInTheDocument();
|
|
1053
1062
|
expect(utils_1.screen.getByText('Label description text')).toBeInTheDocument();
|
|
1054
|
-
});
|
|
1055
|
-
it('handles form with field array created by FieldBuilder',
|
|
1063
|
+
}));
|
|
1064
|
+
it('handles form with field array created by FieldBuilder', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1056
1065
|
const user = utils_1.userEvent.setup();
|
|
1057
1066
|
const fields = [
|
|
1058
1067
|
(0, field_builder_1.field)()
|
|
@@ -1073,37 +1082,37 @@ describe('AkiformBuilder', () => {
|
|
|
1073
1082
|
.build()
|
|
1074
1083
|
];
|
|
1075
1084
|
const onSubmitMock = vi.fn();
|
|
1076
|
-
|
|
1085
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1077
1086
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: onSubmitMock }));
|
|
1078
|
-
});
|
|
1087
|
+
}));
|
|
1079
1088
|
// Add an address
|
|
1080
|
-
|
|
1081
|
-
|
|
1089
|
+
yield user.click(utils_1.screen.getByTestId('addresses-add-button'));
|
|
1090
|
+
yield expandCollapsable();
|
|
1082
1091
|
//Check rendered fields
|
|
1083
1092
|
expect(utils_1.screen.getByText('Street')).toBeInTheDocument();
|
|
1084
1093
|
expect(utils_1.screen.getByText('Help text')).toBeInTheDocument();
|
|
1085
1094
|
expect(utils_1.screen.getByText('Label description text')).toBeInTheDocument();
|
|
1086
1095
|
expect(utils_1.screen.getByLabelText('City')).toBeInTheDocument();
|
|
1087
1096
|
// Fill in the fields
|
|
1088
|
-
|
|
1097
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1089
1098
|
utils_1.fireEvent.change(utils_1.screen.getByPlaceholderText('Enter your street'), {
|
|
1090
1099
|
target: { value: '123 Main St' }
|
|
1091
1100
|
});
|
|
1092
1101
|
utils_1.fireEvent.change(utils_1.screen.getByLabelText('City'), {
|
|
1093
1102
|
target: { value: 'Anytown' }
|
|
1094
1103
|
});
|
|
1095
|
-
});
|
|
1104
|
+
}));
|
|
1096
1105
|
// Submit the form
|
|
1097
|
-
|
|
1106
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1098
1107
|
utils_1.fireEvent.submit(utils_1.screen.getByTestId('akiform-builder'));
|
|
1099
|
-
});
|
|
1100
|
-
|
|
1108
|
+
}));
|
|
1109
|
+
yield (0, utils_1.waitFor)(() => {
|
|
1101
1110
|
expect(onSubmitMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
1102
1111
|
addresses: [{ street: '123 Main St', city: 'Anytown' }]
|
|
1103
1112
|
}), expect.anything());
|
|
1104
1113
|
});
|
|
1105
|
-
});
|
|
1106
|
-
it('handles conditional rendering with FieldBuilder',
|
|
1114
|
+
}));
|
|
1115
|
+
it('handles conditional rendering with FieldBuilder', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1107
1116
|
const fields = [
|
|
1108
1117
|
(0, field_builder_1.field)().key('showField').label('Show Field').type('checkbox').build(),
|
|
1109
1118
|
(0, field_builder_1.field)()
|
|
@@ -1113,16 +1122,16 @@ describe('AkiformBuilder', () => {
|
|
|
1113
1122
|
.config({ visible: (values) => values.showField })
|
|
1114
1123
|
.build()
|
|
1115
1124
|
];
|
|
1116
|
-
|
|
1125
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1117
1126
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
1118
|
-
});
|
|
1127
|
+
}));
|
|
1119
1128
|
expect(utils_1.screen.queryByLabelText('Conditional Field')).not.toBeInTheDocument();
|
|
1120
|
-
|
|
1129
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1121
1130
|
utils_1.fireEvent.click(utils_1.screen.getByLabelText('Show Field'));
|
|
1122
|
-
});
|
|
1131
|
+
}));
|
|
1123
1132
|
expect(utils_1.screen.getByLabelText('Conditional Field')).toBeInTheDocument();
|
|
1124
|
-
});
|
|
1125
|
-
it('handles disabled fields with FieldBuilder',
|
|
1133
|
+
}));
|
|
1134
|
+
it('handles disabled fields with FieldBuilder', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1126
1135
|
const fields = [
|
|
1127
1136
|
(0, field_builder_1.field)()
|
|
1128
1137
|
.key('disabledField')
|
|
@@ -1131,14 +1140,14 @@ describe('AkiformBuilder', () => {
|
|
|
1131
1140
|
.config({ disabled: true })
|
|
1132
1141
|
.build()
|
|
1133
1142
|
];
|
|
1134
|
-
|
|
1143
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1135
1144
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
1136
|
-
});
|
|
1145
|
+
}));
|
|
1137
1146
|
expect(utils_1.screen.getByLabelText('Disabled Field')).toBeDisabled();
|
|
1138
|
-
});
|
|
1147
|
+
}));
|
|
1139
1148
|
});
|
|
1140
1149
|
describe('Accessibility features', () => {
|
|
1141
|
-
it('renders form with proper ARIA attributes',
|
|
1150
|
+
it('renders form with proper ARIA attributes', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1142
1151
|
const fields = [
|
|
1143
1152
|
{
|
|
1144
1153
|
key: 'name',
|
|
@@ -1148,9 +1157,9 @@ describe('AkiformBuilder', () => {
|
|
|
1148
1157
|
},
|
|
1149
1158
|
{ key: 'age', label: 'Age', type: 'number' }
|
|
1150
1159
|
];
|
|
1151
|
-
|
|
1160
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1152
1161
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
1153
|
-
});
|
|
1162
|
+
}));
|
|
1154
1163
|
const form = utils_1.screen.getByRole('form');
|
|
1155
1164
|
expect(form).toHaveAttribute('aria-label', 'Form');
|
|
1156
1165
|
const nameInput = utils_1.screen.getByRole('textbox', { name: /name/i });
|
|
@@ -1159,8 +1168,8 @@ describe('AkiformBuilder', () => {
|
|
|
1159
1168
|
const ageInput = utils_1.screen.getByRole('spinbutton', { name: /age/i });
|
|
1160
1169
|
expect(ageInput).toHaveAttribute('aria-required', 'false');
|
|
1161
1170
|
expect(ageInput).toHaveAttribute('aria-invalid', 'false');
|
|
1162
|
-
});
|
|
1163
|
-
it('updates aria-invalid attribute when form is submitted with errors',
|
|
1171
|
+
}));
|
|
1172
|
+
it('updates aria-invalid attribute when form is submitted with errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1164
1173
|
const fields = [
|
|
1165
1174
|
{
|
|
1166
1175
|
key: 'name',
|
|
@@ -1169,20 +1178,20 @@ describe('AkiformBuilder', () => {
|
|
|
1169
1178
|
validation: akival_1.akival.string().required('Name is required')
|
|
1170
1179
|
}
|
|
1171
1180
|
];
|
|
1172
|
-
|
|
1181
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1173
1182
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
1174
|
-
});
|
|
1183
|
+
}));
|
|
1175
1184
|
const nameInput = utils_1.screen.getByRole('textbox', { name: /name/i });
|
|
1176
1185
|
expect(nameInput).toHaveAttribute('aria-invalid', 'false');
|
|
1177
|
-
|
|
1186
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1178
1187
|
utils_1.fireEvent.submit(utils_1.screen.getByRole('form'));
|
|
1179
|
-
});
|
|
1180
|
-
|
|
1188
|
+
}));
|
|
1189
|
+
yield (0, utils_1.waitFor)(() => {
|
|
1181
1190
|
expect(nameInput).toHaveAttribute('aria-invalid', 'true');
|
|
1182
1191
|
expect(utils_1.screen.getByText('Name is required')).toBeInTheDocument();
|
|
1183
1192
|
});
|
|
1184
|
-
});
|
|
1185
|
-
it('renders field array with proper ARIA attributes',
|
|
1193
|
+
}));
|
|
1194
|
+
it('renders field array with proper ARIA attributes', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1186
1195
|
const user = utils_1.userEvent.setup();
|
|
1187
1196
|
const fields = [
|
|
1188
1197
|
{
|
|
@@ -1195,45 +1204,45 @@ describe('AkiformBuilder', () => {
|
|
|
1195
1204
|
]
|
|
1196
1205
|
}
|
|
1197
1206
|
];
|
|
1198
|
-
|
|
1207
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1199
1208
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
1200
|
-
});
|
|
1201
|
-
|
|
1202
|
-
|
|
1209
|
+
}));
|
|
1210
|
+
yield user.click(utils_1.screen.getByTestId('addresses-add-button'));
|
|
1211
|
+
yield expandCollapsable();
|
|
1203
1212
|
const fieldArrayGroup = utils_1.screen.getByRole('group', { name: 'Addresses' });
|
|
1204
1213
|
expect(fieldArrayGroup).toBeInTheDocument();
|
|
1205
1214
|
const addButton = utils_1.screen.getByLabelText('Add Addresses');
|
|
1206
1215
|
expect(addButton).toBeInTheDocument();
|
|
1207
|
-
|
|
1208
|
-
|
|
1216
|
+
yield user.click(addButton);
|
|
1217
|
+
yield expandCollapsable();
|
|
1209
1218
|
const removeButton = utils_1.screen.getAllByLabelText('Remove Addresses')[1];
|
|
1210
1219
|
expect(removeButton).toBeInTheDocument();
|
|
1211
|
-
});
|
|
1212
|
-
it('supports keyboard navigation',
|
|
1220
|
+
}));
|
|
1221
|
+
it('supports keyboard navigation', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1213
1222
|
const user = utils_1.userEvent.setup();
|
|
1214
1223
|
const fields = [
|
|
1215
1224
|
{ key: 'name', label: 'Name', type: 'text' },
|
|
1216
1225
|
{ key: 'age', label: 'Age', type: 'number' }
|
|
1217
1226
|
];
|
|
1218
|
-
|
|
1227
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1219
1228
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn(), showResetButton: true }));
|
|
1220
|
-
});
|
|
1229
|
+
}));
|
|
1221
1230
|
const nameInput = utils_1.screen.getByLabelText('Name');
|
|
1222
1231
|
const ageInput = utils_1.screen.getByLabelText('Age');
|
|
1223
1232
|
const submitButton = utils_1.screen.getByRole('button', { name: 'SUBMIT' });
|
|
1224
1233
|
const resetButton = utils_1.screen.getByRole('button', { name: 'RESET' });
|
|
1225
|
-
|
|
1234
|
+
yield user.tab();
|
|
1226
1235
|
expect(document.activeElement).toBe(nameInput);
|
|
1227
|
-
|
|
1236
|
+
yield user.tab();
|
|
1228
1237
|
expect(document.activeElement).toBe(ageInput);
|
|
1229
|
-
|
|
1238
|
+
yield user.tab();
|
|
1230
1239
|
expect(document.activeElement).toBe(submitButton);
|
|
1231
|
-
|
|
1240
|
+
yield user.tab();
|
|
1232
1241
|
expect(document.activeElement).toBe(resetButton);
|
|
1233
|
-
});
|
|
1242
|
+
}));
|
|
1234
1243
|
});
|
|
1235
1244
|
describe('AkiformBuilder with sections', () => {
|
|
1236
|
-
it('renders form with sections',
|
|
1245
|
+
it('renders form with sections', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1237
1246
|
const fields = [
|
|
1238
1247
|
(0, field_builder_1.field)()
|
|
1239
1248
|
.key('personalInfo')
|
|
@@ -1264,9 +1273,9 @@ describe('AkiformBuilder', () => {
|
|
|
1264
1273
|
])
|
|
1265
1274
|
.build()
|
|
1266
1275
|
];
|
|
1267
|
-
|
|
1276
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1268
1277
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
1269
|
-
});
|
|
1278
|
+
}));
|
|
1270
1279
|
expect(utils_1.screen.getByText('Personal Information')).toBeInTheDocument();
|
|
1271
1280
|
expect(utils_1.screen.getByText('Contact Information')).toBeInTheDocument();
|
|
1272
1281
|
expect(utils_1.screen.getByText('Name')).toBeInTheDocument();
|
|
@@ -1279,9 +1288,9 @@ describe('AkiformBuilder', () => {
|
|
|
1279
1288
|
expect(utils_1.screen.queryByLabelText('Email')).not.toBeInTheDocument();
|
|
1280
1289
|
// Expand the second section
|
|
1281
1290
|
const contactInfoSection = utils_1.screen.getByText('Contact Information');
|
|
1282
|
-
|
|
1291
|
+
yield utils_1.userEvent.click(contactInfoSection);
|
|
1283
1292
|
// Wait for the section to expand
|
|
1284
|
-
|
|
1293
|
+
yield (0, utils_1.waitFor)(() => {
|
|
1285
1294
|
expect(utils_1.screen.getByLabelText('Email')).toBeInTheDocument();
|
|
1286
1295
|
});
|
|
1287
1296
|
// Check if the Email field is now visible
|
|
@@ -1295,8 +1304,8 @@ describe('AkiformBuilder', () => {
|
|
|
1295
1304
|
// 'Email input visibility:',
|
|
1296
1305
|
// window.getComputedStyle(emailInput).display
|
|
1297
1306
|
// );
|
|
1298
|
-
});
|
|
1299
|
-
it('handles form submission with sections',
|
|
1307
|
+
}));
|
|
1308
|
+
it('handles form submission with sections', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1300
1309
|
const onSubmitMock = vi.fn();
|
|
1301
1310
|
const fields = [
|
|
1302
1311
|
(0, field_builder_1.field)()
|
|
@@ -1315,35 +1324,35 @@ describe('AkiformBuilder', () => {
|
|
|
1315
1324
|
.fields([(0, field_builder_1.field)().key('email').label('Email').type('text').build()])
|
|
1316
1325
|
.build()
|
|
1317
1326
|
];
|
|
1318
|
-
|
|
1327
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1319
1328
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: onSubmitMock }));
|
|
1320
|
-
});
|
|
1329
|
+
}));
|
|
1321
1330
|
// Expand both sections
|
|
1322
|
-
|
|
1323
|
-
|
|
1331
|
+
yield utils_1.userEvent.click(utils_1.screen.getByText('Personal Information'));
|
|
1332
|
+
yield utils_1.userEvent.click(utils_1.screen.getByText('Contact Information'));
|
|
1324
1333
|
// Fill in the form
|
|
1325
|
-
|
|
1334
|
+
yield utils_1.userEvent.type(utils_1.screen.getByLabelText('Name'), 'John Doe', {
|
|
1326
1335
|
delay: 1
|
|
1327
1336
|
});
|
|
1328
|
-
|
|
1329
|
-
|
|
1337
|
+
yield utils_1.userEvent.type(utils_1.screen.getByLabelText('Age'), '30', { delay: 1 });
|
|
1338
|
+
yield utils_1.userEvent.type(utils_1.screen.getByLabelText('Email'), 'john@example.com', {
|
|
1330
1339
|
delay: 1
|
|
1331
1340
|
});
|
|
1332
1341
|
// Wait for submit button to become interactable
|
|
1333
1342
|
const submitButton = utils_1.screen.getByRole('button', { name: /submit/i });
|
|
1334
|
-
|
|
1343
|
+
yield (0, utils_1.waitFor)(() => {
|
|
1335
1344
|
expect(submitButton).toBeEnabled();
|
|
1336
1345
|
});
|
|
1337
1346
|
// Submit the form
|
|
1338
|
-
|
|
1347
|
+
yield utils_1.userEvent.click(submitButton);
|
|
1339
1348
|
// Validate submission
|
|
1340
1349
|
expect(onSubmitMock).toHaveBeenCalledWith({
|
|
1341
1350
|
name: 'John Doe',
|
|
1342
1351
|
age: 30,
|
|
1343
1352
|
email: 'john@example.com'
|
|
1344
1353
|
}, expect.anything());
|
|
1345
|
-
});
|
|
1346
|
-
it('handles conditional rendering within sections',
|
|
1354
|
+
}));
|
|
1355
|
+
it('handles conditional rendering within sections', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1347
1356
|
const fields = [
|
|
1348
1357
|
(0, field_builder_1.field)()
|
|
1349
1358
|
.key('personalInfo')
|
|
@@ -1362,18 +1371,18 @@ describe('AkiformBuilder', () => {
|
|
|
1362
1371
|
.defaultExpanded(true)
|
|
1363
1372
|
.build()
|
|
1364
1373
|
];
|
|
1365
|
-
|
|
1374
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1366
1375
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
1367
|
-
});
|
|
1376
|
+
}));
|
|
1368
1377
|
expect(utils_1.screen.getByLabelText('Name')).toBeInTheDocument();
|
|
1369
1378
|
expect(utils_1.screen.getByLabelText('Show Age')).toBeInTheDocument();
|
|
1370
1379
|
expect(utils_1.screen.queryByLabelText('Age')).not.toBeInTheDocument();
|
|
1371
|
-
|
|
1372
|
-
expect(
|
|
1373
|
-
});
|
|
1380
|
+
yield utils_1.userEvent.click(utils_1.screen.getByLabelText('Show Age'));
|
|
1381
|
+
expect(yield utils_1.screen.findByLabelText('Age')).toBeInTheDocument();
|
|
1382
|
+
}));
|
|
1374
1383
|
});
|
|
1375
1384
|
describe('AkiformBuilder with tooltip', () => {
|
|
1376
|
-
it('renders form field with tooltip as TooltipProps',
|
|
1385
|
+
it('renders form field with tooltip as TooltipProps', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1377
1386
|
const fields = [
|
|
1378
1387
|
(0, field_builder_1.field)()
|
|
1379
1388
|
.key('name')
|
|
@@ -1382,21 +1391,21 @@ describe('AkiformBuilder', () => {
|
|
|
1382
1391
|
.tooltip({ title: 'Enter your full name', defaultOpen: true })
|
|
1383
1392
|
.build()
|
|
1384
1393
|
];
|
|
1385
|
-
|
|
1394
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1386
1395
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
1387
|
-
});
|
|
1396
|
+
}));
|
|
1388
1397
|
const tooltipTrigger = utils_1.screen.getByLabelText('Name');
|
|
1389
1398
|
expect(tooltipTrigger).toBeInTheDocument();
|
|
1390
1399
|
// Simulate hovering over the field to show the tooltip
|
|
1391
|
-
|
|
1400
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1392
1401
|
utils_1.fireEvent.mouseEnter(tooltipTrigger);
|
|
1393
|
-
});
|
|
1402
|
+
}));
|
|
1394
1403
|
// Wait for the tooltip to appear
|
|
1395
|
-
|
|
1404
|
+
yield (0, utils_1.waitFor)(() => {
|
|
1396
1405
|
expect(utils_1.screen.getByText('Enter your full name')).toBeInTheDocument();
|
|
1397
1406
|
});
|
|
1398
|
-
});
|
|
1399
|
-
it('renders form field with tooltip as string',
|
|
1407
|
+
}));
|
|
1408
|
+
it('renders form field with tooltip as string', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1400
1409
|
const fields = [
|
|
1401
1410
|
(0, field_builder_1.field)()
|
|
1402
1411
|
.key('email')
|
|
@@ -1405,19 +1414,19 @@ describe('AkiformBuilder', () => {
|
|
|
1405
1414
|
.tooltip({ title: 'Enter your full name', defaultOpen: true })
|
|
1406
1415
|
.build()
|
|
1407
1416
|
];
|
|
1408
|
-
|
|
1417
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1409
1418
|
(0, utils_1.render)(React.createElement(akiform_builder_1.AkiformBuilder, { fields: fields, onSubmit: vi.fn() }));
|
|
1410
|
-
});
|
|
1419
|
+
}));
|
|
1411
1420
|
const tooltipTrigger = utils_1.screen.getByLabelText('Email');
|
|
1412
1421
|
expect(tooltipTrigger).toBeInTheDocument();
|
|
1413
1422
|
// Simulate hovering over the field to show the tooltip
|
|
1414
|
-
|
|
1423
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1415
1424
|
utils_1.fireEvent.mouseEnter(tooltipTrigger);
|
|
1416
|
-
});
|
|
1425
|
+
}));
|
|
1417
1426
|
// Wait for the tooltip to appear
|
|
1418
|
-
|
|
1427
|
+
yield (0, utils_1.waitFor)(() => {
|
|
1419
1428
|
expect(utils_1.screen.getByText('Enter your full name')).toBeInTheDocument();
|
|
1420
1429
|
});
|
|
1421
|
-
});
|
|
1430
|
+
}));
|
|
1422
1431
|
});
|
|
1423
1432
|
});
|