@schema-engine/forms 0.5.0 → 0.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/README.md +3 -3
- package/dist/actions/index.js +4 -4
- package/dist/actions/plugins/index.js +3 -3
- package/dist/actions/plugins/registrations.js +3 -3
- package/dist/agent-tool/index.js +1 -1
- package/dist/{chunk-U2X3IYSD.js → chunk-6EYX257T.js} +1 -1
- package/dist/{chunk-HEAKWS27.js → chunk-A5VLMQAK.js} +693 -643
- package/dist/chunk-A5VLMQAK.js.map +7 -0
- package/dist/{chunk-5QXT7YAJ.js → chunk-CANRZY5A.js} +1 -1
- package/dist/{chunk-2VKEOE2L.js → chunk-GQHMU3AR.js} +12 -12
- package/dist/{chunk-WS7SLVXL.js → chunk-JA5ET6MC.js} +4 -4
- package/dist/{chunk-2PTM54FQ.js → chunk-KH6QWB5Y.js} +2 -2
- package/dist/chunk-PCL2KNHC.js.map +7 -0
- package/dist/{chunk-56CJ2UZ7.js → chunk-TSKELYW7.js} +2 -2
- package/dist/chunk-U3YHTQHR.js +215 -0
- package/dist/chunk-U3YHTQHR.js.map +7 -0
- package/dist/{chunk-XPQRHO5E.js → chunk-V5H7L5PJ.js} +1 -1
- package/dist/engine/build-form-engine.js +7 -7
- package/dist/engine/create-form-engine.js +8 -8
- package/dist/engine/form-engine.js +7 -7
- package/dist/engine/index.js +8 -8
- package/dist/engine/step-machine.js +1 -1
- package/dist/engine/submission-schema.js +1 -1
- package/dist/engine/value-validation.js +1 -1
- package/dist/index.js +26 -26
- package/dist/lib/validate-form.js +4 -4
- package/dist/recipes/index.js +1 -1
- package/dist/recipes/view-model.js +1 -1
- package/dist/runtime/create-form-runtime.js +7 -7
- package/dist/runtime/index.js +7 -7
- package/dist/schemas/base-field.js +2 -2
- package/dist/schemas/form-config-shape.js +2 -2
- package/dist/schemas/form-config.js +2 -2
- package/dist/schemas/index.js +5 -5
- package/dist/schemas/validation/dependencies.js +1 -1
- package/dist/schemas/validation/index.js +5 -5
- package/dist/schemas/validation/utils.js +1 -1
- package/dist/schemas/validation/validation-registry.js +1 -1
- package/dist/server-errors/from-json-api-errors.js +3 -3
- package/dist/server-errors/from-problem-details.js +3 -3
- package/dist/server-errors/index.js +6 -6
- package/dist/server-errors/shared.js +2 -2
- package/dist/state-container/create-form-state-container.js +5 -5
- package/dist/state-container/index.d.ts +1 -1
- package/dist/state-container/index.js +12 -12
- package/dist/state-container/selectors.js +1 -1
- package/dist/state-container/submission.js +1 -1
- package/dist/state-container/types.d.ts +1 -1
- package/dist/state-container/types.js +1 -1
- package/dist/testing/assert.d.ts +92 -0
- package/dist/testing/assert.js +42 -0
- package/dist/testing/assert.js.map +7 -0
- package/dist/testing/form-state-container-conformance.d.ts +15 -3
- package/dist/testing/form-state-container-conformance.js +4 -3
- package/dist/testing/index.d.ts +3 -2
- package/dist/testing/index.js +4 -3
- package/package.json +7 -13
- package/skill/SKILL.md +14 -14
- package/skill/reference/forms.md +7 -6
- package/dist/chunk-HEAKWS27.js.map +0 -7
- package/dist/chunk-PXWVKJGF.js.map +0 -7
- package/dist/{chunk-U2X3IYSD.js.map → chunk-6EYX257T.js.map} +0 -0
- package/dist/{chunk-5QXT7YAJ.js.map → chunk-CANRZY5A.js.map} +0 -0
- package/dist/{chunk-GY657L56.js → chunk-DP7SYLLI.js} +5 -5
- /package/dist/{chunk-GY657L56.js.map → chunk-DP7SYLLI.js.map} +0 -0
- /package/dist/{chunk-2VKEOE2L.js.map → chunk-GQHMU3AR.js.map} +0 -0
- /package/dist/{chunk-WS7SLVXL.js.map → chunk-JA5ET6MC.js.map} +0 -0
- /package/dist/{chunk-2PTM54FQ.js.map → chunk-KH6QWB5Y.js.map} +0 -0
- /package/dist/{chunk-PXWVKJGF.js → chunk-PCL2KNHC.js} +0 -0
- /package/dist/{chunk-56CJ2UZ7.js.map → chunk-TSKELYW7.js.map} +0 -0
- /package/dist/{chunk-XPQRHO5E.js.map → chunk-V5H7L5PJ.js.map} +0 -0
|
@@ -16,13 +16,31 @@ import {
|
|
|
16
16
|
} from "./chunk-CRQWKC67.js";
|
|
17
17
|
import {
|
|
18
18
|
FORM_ROOT
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-PCL2KNHC.js";
|
|
20
20
|
import {
|
|
21
21
|
toHydration
|
|
22
22
|
} from "./chunk-RB22U6HI.js";
|
|
23
|
+
import {
|
|
24
|
+
assertCallCount,
|
|
25
|
+
assertDefined,
|
|
26
|
+
assertDoesNotThrow,
|
|
27
|
+
assertEqual,
|
|
28
|
+
assertLength,
|
|
29
|
+
assertMatches,
|
|
30
|
+
assertNoProperty,
|
|
31
|
+
assertNotIncludes,
|
|
32
|
+
assertNotMatches,
|
|
33
|
+
assertNotSame,
|
|
34
|
+
assertSame,
|
|
35
|
+
assertThrows,
|
|
36
|
+
assertUndefined,
|
|
37
|
+
createSpy,
|
|
38
|
+
spyOn,
|
|
39
|
+
stubGlobal,
|
|
40
|
+
waitFor
|
|
41
|
+
} from "./chunk-U3YHTQHR.js";
|
|
23
42
|
|
|
24
43
|
// src/testing/form-state-container-conformance.ts
|
|
25
|
-
import { describe, expect, test, vi } from "vitest";
|
|
26
44
|
import * as z from "zod/mini";
|
|
27
45
|
function createGate() {
|
|
28
46
|
const waiting = /* @__PURE__ */ new Map();
|
|
@@ -263,20 +281,20 @@ var cases = [
|
|
|
263
281
|
run(createStore) {
|
|
264
282
|
const store = createStore(fixture().options);
|
|
265
283
|
const first = store.getSnapshot();
|
|
266
|
-
|
|
267
|
-
const listener =
|
|
284
|
+
assertSame(store.getSnapshot(), first);
|
|
285
|
+
const listener = createSpy();
|
|
268
286
|
const unsubscribe = store.subscribe(listener);
|
|
269
287
|
store.setValue("name", "Grace");
|
|
270
|
-
|
|
288
|
+
assertCallCount(listener, 1);
|
|
271
289
|
const second = store.getSnapshot();
|
|
272
|
-
|
|
273
|
-
|
|
290
|
+
assertNotSame(second, first);
|
|
291
|
+
assertSame(store.getSnapshot(), second);
|
|
274
292
|
store.setValue("name", "Grace");
|
|
275
|
-
|
|
276
|
-
|
|
293
|
+
assertCallCount(listener, 1);
|
|
294
|
+
assertSame(store.getSnapshot(), second);
|
|
277
295
|
unsubscribe();
|
|
278
296
|
store.setValue("name", "Hedy");
|
|
279
|
-
|
|
297
|
+
assertCallCount(listener, 1);
|
|
280
298
|
}
|
|
281
299
|
},
|
|
282
300
|
{
|
|
@@ -285,17 +303,17 @@ var cases = [
|
|
|
285
303
|
async run(createStore) {
|
|
286
304
|
const store = createStore(fixture().options);
|
|
287
305
|
const start = store.getSnapshot().generation;
|
|
288
|
-
|
|
306
|
+
assertSame(store.getServerSnapshot().generation, start);
|
|
289
307
|
store.setValue("name", "Grace");
|
|
290
308
|
store.blur("name");
|
|
291
309
|
await store.validate();
|
|
292
310
|
await store.submit();
|
|
293
|
-
|
|
311
|
+
assertSame(store.getSnapshot().generation, start);
|
|
294
312
|
store.reset();
|
|
295
|
-
|
|
313
|
+
assertSame(store.getSnapshot().generation, start + 1);
|
|
296
314
|
store.reset({ name: "Hedy" });
|
|
297
|
-
|
|
298
|
-
|
|
315
|
+
assertSame(store.getSnapshot().generation, start + 2);
|
|
316
|
+
assertSame(store.getServerSnapshot().generation, start);
|
|
299
317
|
}
|
|
300
318
|
},
|
|
301
319
|
{
|
|
@@ -303,13 +321,13 @@ var cases = [
|
|
|
303
321
|
name: "a reset of a pristine form still notifies, since the generation changed",
|
|
304
322
|
run(createStore) {
|
|
305
323
|
const store = createStore(fixture().options);
|
|
306
|
-
const listener =
|
|
324
|
+
const listener = createSpy();
|
|
307
325
|
store.subscribe(listener);
|
|
308
326
|
const before = store.getSnapshot();
|
|
309
327
|
store.reset();
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
328
|
+
assertCallCount(listener, 1);
|
|
329
|
+
assertNotSame(store.getSnapshot(), before);
|
|
330
|
+
assertEqual(store.getSnapshot().values, before.values);
|
|
313
331
|
}
|
|
314
332
|
},
|
|
315
333
|
{
|
|
@@ -318,13 +336,13 @@ var cases = [
|
|
|
318
336
|
run(createStore) {
|
|
319
337
|
const store = createStore(fixture().options);
|
|
320
338
|
const server = store.getServerSnapshot();
|
|
321
|
-
|
|
322
|
-
|
|
339
|
+
assertSame(store.getServerSnapshot(), server);
|
|
340
|
+
assertSame(server.values.name, "Ada");
|
|
323
341
|
store.setValue("name", "Grace");
|
|
324
342
|
store.blur("name");
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
343
|
+
assertSame(store.getServerSnapshot(), server);
|
|
344
|
+
assertSame(server.values.name, "Ada");
|
|
345
|
+
assertSame(store.getSnapshot().values.name, "Grace");
|
|
328
346
|
}
|
|
329
347
|
},
|
|
330
348
|
{
|
|
@@ -342,38 +360,38 @@ var cases = [
|
|
|
342
360
|
};
|
|
343
361
|
const store = createStore(fixture({ defaults }).options);
|
|
344
362
|
const snapshot = store.getSnapshot();
|
|
345
|
-
|
|
363
|
+
assertThrows(() => {
|
|
346
364
|
snapshot.values.name = "Eve";
|
|
347
|
-
}
|
|
348
|
-
|
|
365
|
+
}, TypeError);
|
|
366
|
+
assertThrows(() => {
|
|
349
367
|
snapshot.values.address.street = "Eve";
|
|
350
|
-
}
|
|
351
|
-
|
|
368
|
+
}, TypeError);
|
|
369
|
+
assertThrows(() => {
|
|
352
370
|
snapshot.errors.name = serverIssue("x");
|
|
353
|
-
}
|
|
354
|
-
|
|
371
|
+
}, TypeError);
|
|
372
|
+
assertThrows(() => {
|
|
355
373
|
snapshot.touched.name = true;
|
|
356
|
-
}
|
|
357
|
-
|
|
374
|
+
}, TypeError);
|
|
375
|
+
assertThrows(() => {
|
|
358
376
|
snapshot.dirty.name = true;
|
|
359
|
-
}
|
|
360
|
-
|
|
377
|
+
}, TypeError);
|
|
378
|
+
assertThrows(() => {
|
|
361
379
|
snapshot.rowIds.contacts = [];
|
|
362
|
-
}
|
|
363
|
-
|
|
380
|
+
}, TypeError);
|
|
381
|
+
assertThrows(() => {
|
|
364
382
|
snapshot.rowIds.contacts.push("x");
|
|
365
|
-
}
|
|
383
|
+
}, TypeError);
|
|
366
384
|
defaults.address.street = "changed after create";
|
|
367
|
-
|
|
385
|
+
assertSame(store.getSnapshot().values.address.street, "1 Main");
|
|
368
386
|
const branch = { street: "2 Side", country: "FR" };
|
|
369
387
|
store.setValue("address", branch);
|
|
370
388
|
branch.street = "changed after setValue";
|
|
371
|
-
|
|
389
|
+
assertSame(store.getSnapshot().values.address.street, "2 Side");
|
|
372
390
|
const given = { name: serverIssue("Taken") };
|
|
373
391
|
await serverAnswer(store, given);
|
|
374
392
|
given.name.message = "changed after the answer";
|
|
375
|
-
|
|
376
|
-
|
|
393
|
+
assertSame(errorsOf(store).name?.message, "Taken");
|
|
394
|
+
assertSame(Object.getPrototypeOf(store.getSnapshot().values), Object.prototype);
|
|
377
395
|
}
|
|
378
396
|
},
|
|
379
397
|
{
|
|
@@ -384,22 +402,22 @@ var cases = [
|
|
|
384
402
|
const before = store.getSnapshot();
|
|
385
403
|
store.setValue("name", "Grace");
|
|
386
404
|
const after = store.getSnapshot();
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
405
|
+
assertSame(after.values.address, before.values.address);
|
|
406
|
+
assertSame(after.values.contacts, before.values.contacts);
|
|
407
|
+
assertSame(after.errors, before.errors);
|
|
408
|
+
assertSame(after.touched, before.touched);
|
|
409
|
+
assertSame(after.rowIds, before.rowIds);
|
|
392
410
|
store.setValue("contacts.1.email", "new@example.com");
|
|
393
411
|
const rows = store.getSnapshot().values.contacts;
|
|
394
412
|
const earlier = after.values.contacts;
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
413
|
+
assertNotSame(rows, earlier);
|
|
414
|
+
assertSame(rows[0], earlier[0]);
|
|
415
|
+
assertNotSame(rows[1], earlier[1]);
|
|
416
|
+
assertSame(rows[2], earlier[2]);
|
|
399
417
|
const valuesBeforeBlur = store.getSnapshot().values;
|
|
400
418
|
store.blur("name");
|
|
401
|
-
|
|
402
|
-
|
|
419
|
+
assertSame(store.getSnapshot().values, valuesBeforeBlur);
|
|
420
|
+
assertSame(store.getSnapshot().values.contacts, rows);
|
|
403
421
|
}
|
|
404
422
|
},
|
|
405
423
|
{
|
|
@@ -411,11 +429,11 @@ var cases = [
|
|
|
411
429
|
store.blur("contacts.1.email");
|
|
412
430
|
store.setValue("address.street", "2 Side");
|
|
413
431
|
const { errors, touched, dirty } = store.getSnapshot();
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
432
|
+
assertEqual(Object.keys(errors).toSorted(), ["contacts.1.email", "nickname"]);
|
|
433
|
+
assertMatches(errors.nickname, { message: "nick", source: "server" });
|
|
434
|
+
assertEqual(touched, { "contacts.1.email": true });
|
|
435
|
+
assertEqual(dirty, { "address.street": true });
|
|
436
|
+
assertEqual(Object.keys(store.getSnapshot()).toSorted(), [
|
|
419
437
|
"dirty",
|
|
420
438
|
"errors",
|
|
421
439
|
"generation",
|
|
@@ -429,9 +447,9 @@ var cases = [
|
|
|
429
447
|
]);
|
|
430
448
|
store.setValue("name", "Grace");
|
|
431
449
|
const after = store.getSnapshot();
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
450
|
+
assertSame(after.errors, errors);
|
|
451
|
+
assertSame(after.touched, touched);
|
|
452
|
+
assertNotSame(after.dirty, dirty);
|
|
435
453
|
}
|
|
436
454
|
},
|
|
437
455
|
{
|
|
@@ -440,11 +458,11 @@ var cases = [
|
|
|
440
458
|
async run(createStore) {
|
|
441
459
|
const store = createStore(fixture().options);
|
|
442
460
|
await serverAnswer(store, { contacts: serverIssue("too few"), "contacts.0.email": serverIssue("row") });
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
461
|
+
assertEqual(Object.keys(errorsOf(store)).toSorted(), ["contacts", "contacts.0.email"]);
|
|
462
|
+
assertSame(fieldState(store, "contacts").error?.message, "too few");
|
|
463
|
+
assertSame(fieldState(store, "contacts.0.email").error?.message, "row");
|
|
464
|
+
assertUndefined(fieldState(store, "contacts.1.email").error);
|
|
465
|
+
assertSame(store.getSnapshot().isValid, false);
|
|
448
466
|
}
|
|
449
467
|
},
|
|
450
468
|
{
|
|
@@ -453,16 +471,16 @@ var cases = [
|
|
|
453
471
|
async run(createStore) {
|
|
454
472
|
const store = createStore(fixture().options);
|
|
455
473
|
await serverAnswer(store, { [FORM_ROOT]: serverIssue("Try again later") });
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
474
|
+
assertEqual(Object.keys(errorsOf(store)), [FORM_ROOT]);
|
|
475
|
+
assertMatches(errorsOf(store)[FORM_ROOT], { message: "Try again later" });
|
|
476
|
+
assertUndefined(fieldState(store, "name").error);
|
|
477
|
+
assertSame(fieldState(store, "contacts.0.email").invalid, false);
|
|
478
|
+
assertSame(store.getSnapshot().isValid, false);
|
|
479
|
+
assertEqual(await store.validate(["name"]), { outcome: "passed" });
|
|
480
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
463
481
|
store.setValue("name", "Grace");
|
|
464
|
-
|
|
465
|
-
|
|
482
|
+
assertEqual(errorsOf(store), {});
|
|
483
|
+
assertSame(store.getSnapshot().isValid, true);
|
|
466
484
|
}
|
|
467
485
|
},
|
|
468
486
|
{
|
|
@@ -479,7 +497,7 @@ var cases = [
|
|
|
479
497
|
nickname: serverIssue("other")
|
|
480
498
|
});
|
|
481
499
|
store.setValue("contacts.0.email", "new@example.com");
|
|
482
|
-
|
|
500
|
+
assertEqual(Object.keys(errorsOf(store)).toSorted(), ["contacts.1.email", "nickname"]);
|
|
483
501
|
}
|
|
484
502
|
},
|
|
485
503
|
{
|
|
@@ -488,12 +506,12 @@ var cases = [
|
|
|
488
506
|
run(createStore) {
|
|
489
507
|
const store = createStore(fixture().options);
|
|
490
508
|
store.blur("address");
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
509
|
+
assertSame(fieldState(store, "address.street").isTouched, true);
|
|
510
|
+
assertSame(fieldState(store, "address").isTouched, true);
|
|
511
|
+
assertSame(fieldState(store, "name").isTouched, false);
|
|
494
512
|
store.setValue("address.street", "2 Side");
|
|
495
|
-
|
|
496
|
-
|
|
513
|
+
assertSame(fieldState(store, "address").isDirty, true);
|
|
514
|
+
assertSame(fieldState(store, "address.country").isDirty, false);
|
|
497
515
|
}
|
|
498
516
|
},
|
|
499
517
|
{
|
|
@@ -501,7 +519,7 @@ var cases = [
|
|
|
501
519
|
name: "selectFieldState reports error, touched and dirty for a path",
|
|
502
520
|
async run(createStore) {
|
|
503
521
|
const store = createStore(fixture().options);
|
|
504
|
-
|
|
522
|
+
assertEqual(fieldState(store, "name"), {
|
|
505
523
|
error: void 0,
|
|
506
524
|
warning: void 0,
|
|
507
525
|
invalid: false,
|
|
@@ -515,14 +533,14 @@ var cases = [
|
|
|
515
533
|
store.setValue("name", "Grace");
|
|
516
534
|
store.blur("name");
|
|
517
535
|
await serverAnswer(store, { name: serverIssue("no") });
|
|
518
|
-
|
|
536
|
+
assertMatches(fieldState(store, "name"), {
|
|
519
537
|
error: { message: "no" },
|
|
520
538
|
invalid: true,
|
|
521
539
|
isTouched: true,
|
|
522
540
|
isDirty: true
|
|
523
541
|
});
|
|
524
542
|
store.setValue("address.street", "2 Side");
|
|
525
|
-
|
|
543
|
+
assertMatches(fieldState(store, "address"), { isDirty: true, isTouched: false });
|
|
526
544
|
}
|
|
527
545
|
},
|
|
528
546
|
{
|
|
@@ -531,14 +549,14 @@ var cases = [
|
|
|
531
549
|
async run(createStore) {
|
|
532
550
|
const store = createStore(fixture().options);
|
|
533
551
|
const before = store.getSnapshot();
|
|
534
|
-
|
|
535
|
-
|
|
552
|
+
assertSame(selectValue(before, "address"), before.values.address);
|
|
553
|
+
assertSame(selectValue(before, "contacts.1.email"), "b@example.com");
|
|
536
554
|
await serverAnswer(store, { contacts: serverIssue("array") });
|
|
537
555
|
store.setValue("name", "Grace");
|
|
538
556
|
const after = store.getSnapshot();
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
557
|
+
assertSame(selectValue(after, "address"), selectValue(before, "address"));
|
|
558
|
+
assertSame(selectFieldState(after, "contacts").error?.message, "array");
|
|
559
|
+
assertUndefined(selectFieldState(after, "contacts.0.email").error);
|
|
542
560
|
}
|
|
543
561
|
},
|
|
544
562
|
{
|
|
@@ -547,13 +565,13 @@ var cases = [
|
|
|
547
565
|
run(createStore) {
|
|
548
566
|
const store = createStore(fixture().options);
|
|
549
567
|
const before = store.getSnapshot();
|
|
550
|
-
|
|
551
|
-
|
|
568
|
+
assertSame(selectFieldState(before, "name"), selectFieldState(before, "name"));
|
|
569
|
+
assertSame(fieldState(store, "name"), selectFieldState(before, "name"));
|
|
552
570
|
store.blur("name");
|
|
553
571
|
const after = store.getSnapshot();
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
572
|
+
assertNotSame(selectFieldState(after, "name"), selectFieldState(before, "name"));
|
|
573
|
+
assertSame(selectFieldState(after, "name").isTouched, true);
|
|
574
|
+
assertSame(selectFieldState(before, "name").isTouched, false);
|
|
557
575
|
}
|
|
558
576
|
},
|
|
559
577
|
{
|
|
@@ -564,20 +582,20 @@ var cases = [
|
|
|
564
582
|
const file = new File(["x"], "a.txt");
|
|
565
583
|
const files = [file];
|
|
566
584
|
store.setValue("files", files);
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
const listener =
|
|
585
|
+
assertSame(store.getSnapshot().values.files, files);
|
|
586
|
+
assertSame(store.getValue("files"), files);
|
|
587
|
+
assertSame(Object.isFrozen(files), false);
|
|
588
|
+
const listener = createSpy();
|
|
571
589
|
store.subscribe(listener);
|
|
572
590
|
store.setValue("files", files);
|
|
573
|
-
|
|
591
|
+
assertCallCount(listener, 0);
|
|
574
592
|
store.setValue("files", [file]);
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
593
|
+
assertCallCount(listener, 1);
|
|
594
|
+
assertNotSame(store.getSnapshot().values.files, files);
|
|
595
|
+
assertSame(store.getSnapshot().values.files[0], file);
|
|
596
|
+
assertSame(store.getSnapshot().dirty.files, true);
|
|
579
597
|
store.setValue("profile", { avatar: [file] });
|
|
580
|
-
|
|
598
|
+
assertSame(store.getSnapshot().values.profile.avatar[0], file);
|
|
581
599
|
}
|
|
582
600
|
},
|
|
583
601
|
{
|
|
@@ -586,11 +604,11 @@ var cases = [
|
|
|
586
604
|
run(createStore) {
|
|
587
605
|
const store = createStore(fixture().options);
|
|
588
606
|
store.setValue("address", { street: "9 Elm" });
|
|
589
|
-
|
|
590
|
-
|
|
607
|
+
assertEqual(store.getSnapshot().values.address, { street: "9 Elm" });
|
|
608
|
+
assertUndefined(store.getValue("address.country"));
|
|
591
609
|
store.setValue("contacts", [{ email: "only@example.com" }]);
|
|
592
|
-
|
|
593
|
-
|
|
610
|
+
assertEqual(contacts(store), ["only@example.com"]);
|
|
611
|
+
assertLength(store.getSnapshot().rowIds.contacts, 1);
|
|
594
612
|
}
|
|
595
613
|
},
|
|
596
614
|
{
|
|
@@ -599,14 +617,14 @@ var cases = [
|
|
|
599
617
|
run(createStore) {
|
|
600
618
|
const store = createStore(fixture().options);
|
|
601
619
|
const before = store.getSnapshot();
|
|
602
|
-
const listener =
|
|
620
|
+
const listener = createSpy();
|
|
603
621
|
store.subscribe(listener);
|
|
604
622
|
store.setValue("address", { street: "1 Main", country: "IT" });
|
|
605
|
-
|
|
606
|
-
|
|
623
|
+
assertCallCount(listener, 0);
|
|
624
|
+
assertSame(store.getSnapshot(), before);
|
|
607
625
|
store.setValue("address", { street: "1 Main", country: "FR" });
|
|
608
626
|
const after = store.getSnapshot();
|
|
609
|
-
|
|
627
|
+
assertSame(after.values.contacts, before.values.contacts);
|
|
610
628
|
}
|
|
611
629
|
},
|
|
612
630
|
{
|
|
@@ -614,19 +632,19 @@ var cases = [
|
|
|
614
632
|
name: "notifies once per command even when the command starts a validation",
|
|
615
633
|
run(createStore) {
|
|
616
634
|
const change = createStore(fixture({ validationMode: "onChange" }).options);
|
|
617
|
-
const onChange =
|
|
635
|
+
const onChange = createSpy();
|
|
618
636
|
change.subscribe(onChange);
|
|
619
637
|
change.setValue("name", "");
|
|
620
|
-
|
|
621
|
-
|
|
638
|
+
assertCallCount(onChange, 1);
|
|
639
|
+
assertEqual(change.getSnapshot().validating, { name: true });
|
|
622
640
|
change.fieldArray("contacts").swap(0, 1);
|
|
623
|
-
|
|
641
|
+
assertCallCount(onChange, 2);
|
|
624
642
|
const blur = createStore(fixture({ validationMode: "onBlur" }).options);
|
|
625
|
-
const onBlur =
|
|
643
|
+
const onBlur = createSpy();
|
|
626
644
|
blur.subscribe(onBlur);
|
|
627
645
|
blur.blur("name");
|
|
628
|
-
|
|
629
|
-
|
|
646
|
+
assertCallCount(onBlur, 1);
|
|
647
|
+
assertEqual(blur.getSnapshot().validating, { name: true });
|
|
630
648
|
}
|
|
631
649
|
},
|
|
632
650
|
{
|
|
@@ -635,9 +653,9 @@ var cases = [
|
|
|
635
653
|
async run(createStore) {
|
|
636
654
|
const store = createStore(fixture({ defaults: { name: "", nickname: "" } }).options);
|
|
637
655
|
const watch = watchValidation(store);
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
656
|
+
assertEqual(await store.validate([]), { outcome: "passed" });
|
|
657
|
+
assertSame(watch.started, false);
|
|
658
|
+
assertSame(await store.checkValidity(), false);
|
|
641
659
|
}
|
|
642
660
|
},
|
|
643
661
|
{
|
|
@@ -648,10 +666,10 @@ var cases = [
|
|
|
648
666
|
const store = createStore(options);
|
|
649
667
|
gate.hold("x");
|
|
650
668
|
store.fieldArray("invites").append({ code: "x", label: "first" });
|
|
651
|
-
await
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
669
|
+
await waitFor(() => assertSame(errorsOf(store).invites?.message, "Add two invites"));
|
|
670
|
+
assertSame(gate.pending("x"), 0);
|
|
671
|
+
assertUndefined(errorsOf(store)["invites.0.code"]);
|
|
672
|
+
assertSame(isValidating(store), false);
|
|
655
673
|
}
|
|
656
674
|
},
|
|
657
675
|
{
|
|
@@ -663,10 +681,10 @@ var cases = [
|
|
|
663
681
|
store.setValue("name", "");
|
|
664
682
|
store.blur("name");
|
|
665
683
|
await settle();
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
684
|
+
assertSame(watch.started, false);
|
|
685
|
+
assertEqual(errorsOf(store), {});
|
|
686
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
687
|
+
assertSame(errorsOf(store).name?.message, "Name is required");
|
|
670
688
|
}
|
|
671
689
|
},
|
|
672
690
|
{
|
|
@@ -677,11 +695,11 @@ var cases = [
|
|
|
677
695
|
const watch = watchValidation(store);
|
|
678
696
|
store.blur("name");
|
|
679
697
|
await settle();
|
|
680
|
-
|
|
681
|
-
|
|
698
|
+
assertSame(watch.started, false);
|
|
699
|
+
assertEqual(errorsOf(store), {});
|
|
682
700
|
store.setValue("name", "Ada");
|
|
683
701
|
store.setValue("name", "");
|
|
684
|
-
await
|
|
702
|
+
await waitFor(() => assertSame(errorsOf(store).name?.message, "Name is required"));
|
|
685
703
|
}
|
|
686
704
|
},
|
|
687
705
|
{
|
|
@@ -692,10 +710,10 @@ var cases = [
|
|
|
692
710
|
const watch = watchValidation(store);
|
|
693
711
|
store.setValue("name", "");
|
|
694
712
|
await settle();
|
|
695
|
-
|
|
696
|
-
|
|
713
|
+
assertSame(watch.started, false);
|
|
714
|
+
assertEqual(errorsOf(store), {});
|
|
697
715
|
store.blur("name");
|
|
698
|
-
await
|
|
716
|
+
await waitFor(() => assertSame(errorsOf(store).name?.message, "Name is required"));
|
|
699
717
|
}
|
|
700
718
|
},
|
|
701
719
|
{
|
|
@@ -704,13 +722,13 @@ var cases = [
|
|
|
704
722
|
async run(createStore) {
|
|
705
723
|
const onChange = createStore(fixture({ validationMode: "all" }).options);
|
|
706
724
|
onChange.setValue("name", "");
|
|
707
|
-
await
|
|
725
|
+
await waitFor(() => assertDefined(errorsOf(onChange).name));
|
|
708
726
|
onChange.setValue("name", "Ada");
|
|
709
|
-
await
|
|
727
|
+
await waitFor(() => assertUndefined(errorsOf(onChange).name));
|
|
710
728
|
const onBlur = createStore(fixture({ validationMode: "all", defaults: { name: "" } }).options);
|
|
711
|
-
|
|
729
|
+
assertEqual(errorsOf(onBlur), {});
|
|
712
730
|
onBlur.blur("name");
|
|
713
|
-
await
|
|
731
|
+
await waitFor(() => assertSame(errorsOf(onBlur).name?.message, "Name is required"));
|
|
714
732
|
}
|
|
715
733
|
},
|
|
716
734
|
{
|
|
@@ -721,8 +739,8 @@ var cases = [
|
|
|
721
739
|
fixture({ validationMode: "onChange", defaults: { name: "", nickname: "ada" } }).options
|
|
722
740
|
);
|
|
723
741
|
store.setValue("nickname", "");
|
|
724
|
-
await
|
|
725
|
-
|
|
742
|
+
await waitFor(() => assertSame(errorsOf(store).nickname?.message, "Nickname is required"));
|
|
743
|
+
assertUndefined(errorsOf(store).name);
|
|
726
744
|
}
|
|
727
745
|
},
|
|
728
746
|
{
|
|
@@ -731,11 +749,11 @@ var cases = [
|
|
|
731
749
|
async run(createStore) {
|
|
732
750
|
const store = createStore(fixture({ validationMode: "onSubmit", reValidateMode: "onChange" }).options);
|
|
733
751
|
store.setValue("name", "");
|
|
734
|
-
|
|
752
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
735
753
|
store.setValue("name", "Ada");
|
|
736
|
-
await
|
|
754
|
+
await waitFor(() => assertUndefined(errorsOf(store).name));
|
|
737
755
|
store.setValue("name", "");
|
|
738
|
-
await
|
|
756
|
+
await waitFor(() => assertSame(errorsOf(store).name?.message, "Name is required"));
|
|
739
757
|
}
|
|
740
758
|
},
|
|
741
759
|
{
|
|
@@ -748,10 +766,10 @@ var cases = [
|
|
|
748
766
|
const changeWatch = watchValidation(onBlur);
|
|
749
767
|
onBlur.setValue("name", "Ada");
|
|
750
768
|
await settle();
|
|
751
|
-
|
|
752
|
-
|
|
769
|
+
assertSame(changeWatch.started, false);
|
|
770
|
+
assertDefined(errorsOf(onBlur).name);
|
|
753
771
|
onBlur.blur("name");
|
|
754
|
-
await
|
|
772
|
+
await waitFor(() => assertUndefined(errorsOf(onBlur).name));
|
|
755
773
|
const onSubmit = createStore(fixture({ validationMode: "onSubmit", reValidateMode: "onSubmit" }).options);
|
|
756
774
|
onSubmit.setValue("name", "");
|
|
757
775
|
await onSubmit.validate();
|
|
@@ -759,8 +777,8 @@ var cases = [
|
|
|
759
777
|
onSubmit.setValue("name", "Ada");
|
|
760
778
|
onSubmit.blur("name");
|
|
761
779
|
await settle();
|
|
762
|
-
|
|
763
|
-
|
|
780
|
+
assertSame(submitWatch.started, false);
|
|
781
|
+
assertDefined(errorsOf(onSubmit).name);
|
|
764
782
|
}
|
|
765
783
|
},
|
|
766
784
|
{
|
|
@@ -769,14 +787,14 @@ var cases = [
|
|
|
769
787
|
async run(createStore) {
|
|
770
788
|
const store = createStore(fixture({ validationMode: "onSubmit", reValidateMode: "onChange" }).options);
|
|
771
789
|
store.setValue("name", "");
|
|
772
|
-
|
|
790
|
+
assertEqual(await store.validate(["name"]), { outcome: "invalid" });
|
|
773
791
|
const watch = watchValidation(store);
|
|
774
792
|
store.setValue("nickname", "");
|
|
775
793
|
await settle();
|
|
776
|
-
|
|
777
|
-
|
|
794
|
+
assertSame(watch.started, false);
|
|
795
|
+
assertUndefined(errorsOf(store).nickname);
|
|
778
796
|
store.setValue("name", "Ada");
|
|
779
|
-
await
|
|
797
|
+
await waitFor(() => assertUndefined(errorsOf(store).name));
|
|
780
798
|
}
|
|
781
799
|
},
|
|
782
800
|
{
|
|
@@ -784,23 +802,23 @@ var cases = [
|
|
|
784
802
|
name: "a passing validate starts re-validation of the paths it checked, and no others, and reset ends it",
|
|
785
803
|
async run(createStore) {
|
|
786
804
|
const store = createStore(fixture({ validationMode: "onSubmit", reValidateMode: "onChange" }).options);
|
|
787
|
-
|
|
805
|
+
assertEqual(await store.validate(["nickname"]), { outcome: "passed" });
|
|
788
806
|
const other = watchValidation(store);
|
|
789
807
|
store.setValue("name", "");
|
|
790
808
|
await settle();
|
|
791
|
-
|
|
792
|
-
|
|
809
|
+
assertSame(other.started, false);
|
|
810
|
+
assertEqual(errorsOf(store), {});
|
|
793
811
|
store.setValue("name", "Ada");
|
|
794
|
-
|
|
812
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
795
813
|
store.setValue("name", "");
|
|
796
|
-
await
|
|
797
|
-
|
|
814
|
+
await waitFor(() => assertSame(errorsOf(store).name?.type, "required"));
|
|
815
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
798
816
|
store.reset();
|
|
799
817
|
const afterReset = watchValidation(store);
|
|
800
818
|
store.setValue("name", "");
|
|
801
819
|
await settle();
|
|
802
|
-
|
|
803
|
-
|
|
820
|
+
assertSame(afterReset.started, false);
|
|
821
|
+
assertEqual(errorsOf(store), {});
|
|
804
822
|
}
|
|
805
823
|
},
|
|
806
824
|
{
|
|
@@ -810,12 +828,12 @@ var cases = [
|
|
|
810
828
|
const store = createStore(fixture().options);
|
|
811
829
|
store.setValue("name", "");
|
|
812
830
|
const before = store.getSnapshot();
|
|
813
|
-
const listener =
|
|
831
|
+
const listener = createSpy();
|
|
814
832
|
store.subscribe(listener);
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
833
|
+
assertSame(await store.checkValidity(), false);
|
|
834
|
+
assertSame(store.getSnapshot(), before);
|
|
835
|
+
assertCallCount(listener, 0);
|
|
836
|
+
assertEqual(errorsOf(store), {});
|
|
819
837
|
}
|
|
820
838
|
},
|
|
821
839
|
{
|
|
@@ -824,14 +842,14 @@ var cases = [
|
|
|
824
842
|
run(createStore) {
|
|
825
843
|
const store = createStore(fixture().options);
|
|
826
844
|
store.setValue("name", "Grace");
|
|
827
|
-
|
|
845
|
+
assertEqual(store.getSnapshot().touched, {});
|
|
828
846
|
store.blur("name");
|
|
829
|
-
|
|
847
|
+
assertEqual(store.getSnapshot().touched, { name: true });
|
|
830
848
|
const touched = store.getSnapshot().touched;
|
|
831
849
|
store.blur("name");
|
|
832
|
-
|
|
850
|
+
assertSame(store.getSnapshot().touched, touched);
|
|
833
851
|
store.reset();
|
|
834
|
-
|
|
852
|
+
assertEqual(store.getSnapshot().touched, {});
|
|
835
853
|
}
|
|
836
854
|
},
|
|
837
855
|
{
|
|
@@ -839,19 +857,19 @@ var cases = [
|
|
|
839
857
|
name: "dirty follows the difference from the defaults, and appending a row does not make the rows before it dirty",
|
|
840
858
|
run(createStore) {
|
|
841
859
|
const store = createStore(fixture().options);
|
|
842
|
-
|
|
860
|
+
assertEqual(store.getSnapshot().dirty, {});
|
|
843
861
|
store.setValue("address.street", "2 Side");
|
|
844
|
-
|
|
862
|
+
assertEqual(marked(store.getSnapshot().dirty), ["address.street"]);
|
|
845
863
|
store.setValue("address.street", "1 Main");
|
|
846
|
-
|
|
864
|
+
assertEqual(store.getSnapshot().dirty, {});
|
|
847
865
|
store.setValue("contacts.1.email", "x@example.com");
|
|
848
|
-
|
|
866
|
+
assertEqual(marked(store.getSnapshot().dirty), ["contacts.1.email"]);
|
|
849
867
|
store.setValue("contacts.1.email", "b@example.com");
|
|
850
868
|
store.fieldArray("contacts").append({ email: "x@example.com" });
|
|
851
|
-
|
|
869
|
+
assertEqual(marked(store.getSnapshot().dirty), ["contacts", "contacts.3.email"]);
|
|
852
870
|
store.setValue("name", "Grace");
|
|
853
871
|
store.reset();
|
|
854
|
-
|
|
872
|
+
assertEqual(store.getSnapshot().dirty, {});
|
|
855
873
|
}
|
|
856
874
|
},
|
|
857
875
|
{
|
|
@@ -862,13 +880,13 @@ var cases = [
|
|
|
862
880
|
await serverAnswer(store, { nickname: serverIssue("no") });
|
|
863
881
|
store.setValue("name", "");
|
|
864
882
|
store.blur("name");
|
|
865
|
-
|
|
883
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
866
884
|
store.reset();
|
|
867
885
|
const snapshot = store.getSnapshot();
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
886
|
+
assertSame(snapshot.values.name, "Ada");
|
|
887
|
+
assertEqual(snapshot.errors, {});
|
|
888
|
+
assertEqual(snapshot.touched, {});
|
|
889
|
+
assertEqual(snapshot.dirty, {});
|
|
872
890
|
}
|
|
873
891
|
},
|
|
874
892
|
{
|
|
@@ -878,12 +896,12 @@ var cases = [
|
|
|
878
896
|
const store = createStore(fixture().options);
|
|
879
897
|
store.setValue("name", "Grace");
|
|
880
898
|
store.reset({ name: "Hedy" });
|
|
881
|
-
|
|
882
|
-
|
|
899
|
+
assertEqual(store.getSnapshot().values, { name: "Hedy" });
|
|
900
|
+
assertEqual(store.getSnapshot().dirty, {});
|
|
883
901
|
store.setValue("name", "Ada");
|
|
884
|
-
|
|
902
|
+
assertEqual(store.getSnapshot().dirty, { name: true });
|
|
885
903
|
store.reset();
|
|
886
|
-
|
|
904
|
+
assertSame(store.getValue("name"), "Hedy");
|
|
887
905
|
}
|
|
888
906
|
},
|
|
889
907
|
{
|
|
@@ -897,17 +915,17 @@ var cases = [
|
|
|
897
915
|
});
|
|
898
916
|
store.blur("contacts.1.email");
|
|
899
917
|
const [first, second, third] = ids(store);
|
|
900
|
-
const listener =
|
|
918
|
+
const listener = createSpy(() => {
|
|
901
919
|
const snapshot = store.getSnapshot();
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
920
|
+
assertEqual(snapshot.rowIds.contacts, [second, first, third]);
|
|
921
|
+
assertEqual(contacts(store), ["b@example.com", "a@example.com", "c@example.com"]);
|
|
922
|
+
assertSame(snapshot.errors["contacts.0.email"]?.message, "one");
|
|
923
|
+
assertSame(snapshot.errors["contacts.1.email"]?.message, "zero");
|
|
924
|
+
assertEqual(marked(snapshot.touched), ["contacts.0.email"]);
|
|
907
925
|
});
|
|
908
926
|
store.subscribe(listener);
|
|
909
927
|
store.fieldArray("contacts").swap(0, 1);
|
|
910
|
-
|
|
928
|
+
assertCallCount(listener, 1);
|
|
911
929
|
}
|
|
912
930
|
},
|
|
913
931
|
{
|
|
@@ -920,23 +938,26 @@ var cases = [
|
|
|
920
938
|
await serverAnswer(store, { "contacts.2.email": serverIssue("two") });
|
|
921
939
|
store.blur("contacts.2.email");
|
|
922
940
|
array.move(2, 0);
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
941
|
+
assertEqual(ids(store), [third, first, second]);
|
|
942
|
+
assertSame(errorsOf(store)["contacts.0.email"]?.message, "two");
|
|
943
|
+
assertEqual(marked(store.getSnapshot().touched), ["contacts.0.email"]);
|
|
926
944
|
array.prepend({ email: "new@example.com" });
|
|
927
|
-
|
|
928
|
-
|
|
945
|
+
assertEqual(ids(store).slice(1), [third, first, second]);
|
|
946
|
+
assertEqual(Object.keys(errorsOf(store)), ["contacts.1.email"]);
|
|
929
947
|
array.insert(1, { email: "mid@example.com" });
|
|
930
|
-
|
|
931
|
-
|
|
948
|
+
assertEqual(Object.keys(errorsOf(store)), ["contacts.2.email"]);
|
|
949
|
+
assertEqual(ids(store).slice(2), [third, first, second]);
|
|
932
950
|
array.remove(0);
|
|
933
|
-
|
|
934
|
-
|
|
951
|
+
assertEqual(Object.keys(errorsOf(store)), ["contacts.1.email"]);
|
|
952
|
+
assertEqual(marked(store.getSnapshot().touched), ["contacts.1.email"]);
|
|
935
953
|
array.remove(1);
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
954
|
+
assertEqual(errorsOf(store), {});
|
|
955
|
+
assertEqual(store.getSnapshot().touched, {});
|
|
956
|
+
assertEqual(contacts(store), ["mid@example.com", "a@example.com", "b@example.com"]);
|
|
957
|
+
assertEqual(
|
|
958
|
+
toFieldArrayValue(ids(store), array).fields.map(({ id }) => id),
|
|
959
|
+
ids(store)
|
|
960
|
+
);
|
|
940
961
|
}
|
|
941
962
|
},
|
|
942
963
|
{
|
|
@@ -946,10 +967,10 @@ var cases = [
|
|
|
946
967
|
const store = createStore(fixture().options);
|
|
947
968
|
const before = ids(store);
|
|
948
969
|
store.fieldArray("contacts").append([{ email: "x@example.com" }, { email: "y@example.com" }]);
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
970
|
+
assertEqual(ids(store).slice(0, 3), before);
|
|
971
|
+
assertLength(ids(store), 5);
|
|
972
|
+
assertSame(new Set(ids(store)).size, 5);
|
|
973
|
+
assertEqual(contacts(store).slice(3), ["x@example.com", "y@example.com"]);
|
|
953
974
|
}
|
|
954
975
|
},
|
|
955
976
|
{
|
|
@@ -965,16 +986,16 @@ var cases = [
|
|
|
965
986
|
});
|
|
966
987
|
store.blur("contacts.0.email");
|
|
967
988
|
array.update(1, { email: "u@example.com" });
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
989
|
+
assertSame(ids(store)[0], before[0]);
|
|
990
|
+
assertNotSame(ids(store)[1], before[1]);
|
|
991
|
+
assertSame(ids(store)[2], before[2]);
|
|
992
|
+
assertEqual(Object.keys(errorsOf(store)), ["contacts.0.email"]);
|
|
993
|
+
assertEqual(marked(store.getSnapshot().touched), ["contacts.0.email"]);
|
|
973
994
|
array.replace([{ email: "r@example.com" }]);
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
995
|
+
assertLength(ids(store), 1);
|
|
996
|
+
assertNotIncludes(before, ids(store)[0]);
|
|
997
|
+
assertEqual(errorsOf(store), {});
|
|
998
|
+
assertEqual(store.getSnapshot().touched, {});
|
|
978
999
|
}
|
|
979
1000
|
},
|
|
980
1001
|
{
|
|
@@ -984,7 +1005,7 @@ var cases = [
|
|
|
984
1005
|
const store = createStore(fixture().options);
|
|
985
1006
|
const array = store.fieldArray("contacts");
|
|
986
1007
|
const before = store.getSnapshot();
|
|
987
|
-
const listener =
|
|
1008
|
+
const listener = createSpy();
|
|
988
1009
|
store.subscribe(listener);
|
|
989
1010
|
array.swap(0, 5);
|
|
990
1011
|
array.move(-1, 0);
|
|
@@ -994,15 +1015,15 @@ var cases = [
|
|
|
994
1015
|
array.insert(1.5, { email: "z@example.com" });
|
|
995
1016
|
array.remove(7);
|
|
996
1017
|
array.remove([]);
|
|
997
|
-
|
|
998
|
-
|
|
1018
|
+
assertCallCount(listener, 0);
|
|
1019
|
+
assertSame(store.getSnapshot(), before);
|
|
999
1020
|
array.insert(3, { email: "end@example.com" });
|
|
1000
|
-
|
|
1021
|
+
assertLength(contacts(store), 4);
|
|
1001
1022
|
array.remove([0, 0, 9]);
|
|
1002
|
-
|
|
1023
|
+
assertEqual(contacts(store), ["b@example.com", "c@example.com", "end@example.com"]);
|
|
1003
1024
|
array.remove();
|
|
1004
|
-
|
|
1005
|
-
|
|
1025
|
+
assertEqual(contacts(store), []);
|
|
1026
|
+
assertEqual(store.getSnapshot().rowIds.contacts, []);
|
|
1006
1027
|
}
|
|
1007
1028
|
},
|
|
1008
1029
|
{
|
|
@@ -1033,17 +1054,17 @@ var cases = [
|
|
|
1033
1054
|
store.blur("groups.0.members.1.label");
|
|
1034
1055
|
store.blur("tags.2");
|
|
1035
1056
|
store.fieldArray("groups").swap(0, 1);
|
|
1036
|
-
|
|
1037
|
-
|
|
1057
|
+
assertEqual(Object.keys(errorsOf(store)).toSorted(), ["groups.1.members.1.label", "tags.1"]);
|
|
1058
|
+
assertEqual(marked(store.getSnapshot().touched).toSorted(), ["groups.1.members.1.label", "tags.2"]);
|
|
1038
1059
|
store.fieldArray("groups.1.members").remove(0);
|
|
1039
|
-
|
|
1060
|
+
assertEqual(Object.keys(errorsOf(store)).toSorted(), ["groups.1.members.0.label", "tags.1"]);
|
|
1040
1061
|
store.fieldArray("tags").remove(0);
|
|
1041
|
-
|
|
1042
|
-
|
|
1062
|
+
assertEqual(Object.keys(errorsOf(store)).toSorted(), ["groups.1.members.0.label", "tags.0"]);
|
|
1063
|
+
assertEqual(marked(store.getSnapshot().touched).toSorted(), ["groups.1.members.0.label", "tags.1"]);
|
|
1043
1064
|
store.setValue("groups", [{ title: "only", members: [] }]);
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1065
|
+
assertEqual(Object.keys(errorsOf(store)), ["tags.0"]);
|
|
1066
|
+
assertEqual(marked(store.getSnapshot().touched), ["tags.1"]);
|
|
1067
|
+
assertEqual(store.getSnapshot().rowIds["groups.0.members"], []);
|
|
1047
1068
|
}
|
|
1048
1069
|
},
|
|
1049
1070
|
{
|
|
@@ -1058,17 +1079,17 @@ var cases = [
|
|
|
1058
1079
|
const hydration = JSON.parse(JSON.stringify(toHydration(server.getSnapshot())));
|
|
1059
1080
|
const client = createStore(fixture({ snapshot: hydration }).options);
|
|
1060
1081
|
const was = server.getSnapshot();
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1082
|
+
assertEqual(client.getSnapshot().values, was.values);
|
|
1083
|
+
assertEqual(client.getSnapshot().rowIds, was.rowIds);
|
|
1084
|
+
assertEqual(client.getSnapshot().dirty, was.dirty);
|
|
1085
|
+
assertEqual(client.getServerSnapshot().rowIds, was.rowIds);
|
|
1065
1086
|
client.fieldArray("contacts").append({ email: "new@example.com" });
|
|
1066
1087
|
client.fieldArray("contacts").remove(0);
|
|
1067
1088
|
const adopted = Object.values(was.rowIds).flat();
|
|
1068
1089
|
const minted = ids(client).filter((id) => !adopted.includes(id));
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1090
|
+
assertLength(minted, 1);
|
|
1091
|
+
assertEqual(ids(client).slice(0, 2), was.rowIds.contacts.slice(1));
|
|
1092
|
+
assertSame(new Set(ids(client)).size, ids(client).length);
|
|
1072
1093
|
}
|
|
1073
1094
|
},
|
|
1074
1095
|
{
|
|
@@ -1079,19 +1100,19 @@ var cases = [
|
|
|
1079
1100
|
await serverAnswer(store, { "contacts.2.email": serverIssue("two") });
|
|
1080
1101
|
store.blur("contacts.2.email");
|
|
1081
1102
|
store.setValue("contacts", [{ email: "a@example.com" }]);
|
|
1082
|
-
|
|
1083
|
-
|
|
1103
|
+
assertEqual(errorsOf(store), {});
|
|
1104
|
+
assertEqual(store.getSnapshot().touched, {});
|
|
1084
1105
|
const checked = createStore(fixture().options);
|
|
1085
1106
|
checked.setValue("contacts.2.email", "");
|
|
1086
|
-
|
|
1107
|
+
assertEqual(await checked.validate(["contacts.2.email"]), { outcome: "invalid" });
|
|
1087
1108
|
checked.setValue("contacts", [{ email: "a@example.com" }]);
|
|
1088
1109
|
checked.fieldArray("contacts").append({ email: "fresh@example.com" });
|
|
1089
1110
|
checked.fieldArray("contacts").append({ email: "" });
|
|
1090
|
-
|
|
1111
|
+
assertEqual(errorsOf(checked), {});
|
|
1091
1112
|
const watch = watchValidation(checked);
|
|
1092
1113
|
checked.setValue("contacts.2.email", "changed@example.com");
|
|
1093
1114
|
await settle();
|
|
1094
|
-
|
|
1115
|
+
assertSame(watch.started, false);
|
|
1095
1116
|
}
|
|
1096
1117
|
},
|
|
1097
1118
|
{
|
|
@@ -1101,9 +1122,9 @@ var cases = [
|
|
|
1101
1122
|
const store = createStore(fixture().options);
|
|
1102
1123
|
const before = ids(store);
|
|
1103
1124
|
store.setValue("contacts", [{ email: "1" }, { email: "2" }, { email: "3" }]);
|
|
1104
|
-
|
|
1125
|
+
assertEqual(ids(store), before);
|
|
1105
1126
|
store.setValue("contacts", [{ email: "1" }]);
|
|
1106
|
-
|
|
1127
|
+
assertEqual(ids(store), before.slice(0, 1));
|
|
1107
1128
|
}
|
|
1108
1129
|
},
|
|
1109
1130
|
{
|
|
@@ -1128,20 +1149,20 @@ var cases = [
|
|
|
1128
1149
|
answer.setServerErrors({ slug: { message: "Taken" } });
|
|
1129
1150
|
gate.settle("free", false);
|
|
1130
1151
|
store.reportNative({ slug: { type: "patternMismatch", params: { pattern: "[0-9]+" } } });
|
|
1131
|
-
|
|
1152
|
+
assertEqual(await store.validate(["slug"]), { outcome: "invalid" });
|
|
1132
1153
|
const shown = errorsOf(store).slug;
|
|
1133
|
-
|
|
1154
|
+
assertEqual(shown.all, [
|
|
1134
1155
|
{ type: "server", message: "Taken", source: "server" },
|
|
1135
1156
|
{ type: "gate", source: "validation", ruleId: "first" },
|
|
1136
1157
|
{ type: "gate", source: "validation", ruleId: "second" },
|
|
1137
1158
|
{ type: "patternMismatch", source: "native", params: { pattern: "[0-9]+" } }
|
|
1138
1159
|
]);
|
|
1139
1160
|
const { all, ...fields } = shown;
|
|
1140
|
-
|
|
1161
|
+
assertEqual(fields, all[0]);
|
|
1141
1162
|
answer.setServerErrors({});
|
|
1142
1163
|
const withoutServer = errorsOf(store).slug;
|
|
1143
|
-
|
|
1144
|
-
|
|
1164
|
+
assertSame(withoutServer.type, "gate");
|
|
1165
|
+
assertLength(withoutServer.all, 3);
|
|
1145
1166
|
}
|
|
1146
1167
|
},
|
|
1147
1168
|
{
|
|
@@ -1150,20 +1171,20 @@ var cases = [
|
|
|
1150
1171
|
async run(createStore) {
|
|
1151
1172
|
const store = createStore(fixture({ validationMode: "onSubmit" }).options);
|
|
1152
1173
|
store.reportNative({ name: { type: "valueMissing", message: "Fill in" } });
|
|
1153
|
-
|
|
1154
|
-
|
|
1174
|
+
assertEqual(await store.validate(["name"]), { outcome: "invalid" });
|
|
1175
|
+
assertMatches(errorsOf(store).name, { source: "native", type: "valueMissing", message: "Fill in" });
|
|
1155
1176
|
store.reportNative({ name: null });
|
|
1156
|
-
await
|
|
1157
|
-
|
|
1177
|
+
await waitFor(() => assertEqual(errorsOf(store), {}));
|
|
1178
|
+
assertEqual(await store.validate(["name"]), { outcome: "passed" });
|
|
1158
1179
|
const quiet = createStore(fixture({ validationMode: "onSubmit" }).options);
|
|
1159
1180
|
quiet.blur("name");
|
|
1160
1181
|
quiet.reportNative({ name: { type: "valueMissing" } });
|
|
1161
|
-
|
|
1182
|
+
assertEqual(errorsOf(quiet), {});
|
|
1162
1183
|
const onChange = createStore(fixture({ validationMode: "onChange" }).options);
|
|
1163
1184
|
onChange.setValue("nickname", "nick");
|
|
1164
1185
|
onChange.reportNative({ nickname: { type: "valueMissing", message: "Fill in this field" } });
|
|
1165
|
-
await
|
|
1166
|
-
|
|
1186
|
+
await waitFor(() => assertSame(errorsOf(onChange).nickname?.source, "native"));
|
|
1187
|
+
assertSame(errorsOf(onChange).nickname.message, "Fill in this field");
|
|
1167
1188
|
}
|
|
1168
1189
|
},
|
|
1169
1190
|
{
|
|
@@ -1173,15 +1194,15 @@ var cases = [
|
|
|
1173
1194
|
const store = createStore(fixture().options);
|
|
1174
1195
|
store.reportNative({ name: { type: "valueMissing" } });
|
|
1175
1196
|
const before = store.getSnapshot();
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1197
|
+
assertSame(await store.checkValidity(), false);
|
|
1198
|
+
assertSame(store.getSnapshot(), before);
|
|
1199
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
1179
1200
|
store.reportNative({ name: null });
|
|
1180
|
-
|
|
1181
|
-
|
|
1201
|
+
assertSame(await store.checkValidity(), true);
|
|
1202
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
1182
1203
|
await serverAnswer(store, { name: { message: "Taken" } });
|
|
1183
|
-
|
|
1184
|
-
|
|
1204
|
+
assertSame(await store.checkValidity(), false);
|
|
1205
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
1185
1206
|
}
|
|
1186
1207
|
},
|
|
1187
1208
|
{
|
|
@@ -1191,11 +1212,11 @@ var cases = [
|
|
|
1191
1212
|
const store = createStore(fixture().options);
|
|
1192
1213
|
const answer = await passedSubmission(store);
|
|
1193
1214
|
answer.setServerErrors({ [FORM_ROOT]: { message: "Service unavailable" } });
|
|
1194
|
-
|
|
1195
|
-
|
|
1215
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
1216
|
+
assertEqual(await store.validate(["name"]), { outcome: "passed" });
|
|
1196
1217
|
answer.setServerErrors({});
|
|
1197
|
-
|
|
1198
|
-
|
|
1218
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
1219
|
+
assertEqual(errorsOf(store), {});
|
|
1199
1220
|
}
|
|
1200
1221
|
},
|
|
1201
1222
|
{
|
|
@@ -1209,15 +1230,15 @@ var cases = [
|
|
|
1209
1230
|
"address.street": { type: "taken" }
|
|
1210
1231
|
});
|
|
1211
1232
|
const { errors } = store.getSnapshot();
|
|
1212
|
-
|
|
1213
|
-
|
|
1233
|
+
assertMatches(errors.name, { type: "server", message: "Taken", source: "server" });
|
|
1234
|
+
assertEqual(errors.nickname, {
|
|
1214
1235
|
type: "server",
|
|
1215
1236
|
source: "server",
|
|
1216
1237
|
all: [{ type: "server", source: "server" }]
|
|
1217
1238
|
});
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1239
|
+
assertMatches(errors["address.street"], { type: "taken", source: "server" });
|
|
1240
|
+
assertUndefined(errors["address.street"].message);
|
|
1241
|
+
assertEqual(await store.validate(["nickname"]), { outcome: "invalid" });
|
|
1221
1242
|
}
|
|
1222
1243
|
},
|
|
1223
1244
|
{
|
|
@@ -1228,16 +1249,16 @@ var cases = [
|
|
|
1228
1249
|
const answer = await passedSubmission(store);
|
|
1229
1250
|
answer.setServerErrors({ name: { message: "Taken" }, nickname: { message: "Taken" } });
|
|
1230
1251
|
const before = store.getSnapshot();
|
|
1231
|
-
const listener =
|
|
1252
|
+
const listener = createSpy();
|
|
1232
1253
|
store.subscribe(listener);
|
|
1233
1254
|
answer.setServerErrors({ name: { message: "Taken" }, nickname: { message: "Taken" } });
|
|
1234
|
-
|
|
1235
|
-
|
|
1255
|
+
assertCallCount(listener, 0);
|
|
1256
|
+
assertSame(store.getSnapshot(), before);
|
|
1236
1257
|
answer.setServerErrors({ name: { message: "Taken" }, nickname: { message: "Other" } });
|
|
1237
1258
|
const after = store.getSnapshot();
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1259
|
+
assertSame(after.errors.name, before.errors.name);
|
|
1260
|
+
assertNotSame(after.errors.nickname, before.errors.nickname);
|
|
1261
|
+
assertSame(selectFieldState(after, "name"), selectFieldState(before, "name"));
|
|
1241
1262
|
}
|
|
1242
1263
|
},
|
|
1243
1264
|
{
|
|
@@ -1248,14 +1269,17 @@ var cases = [
|
|
|
1248
1269
|
await store.validate(["name"]);
|
|
1249
1270
|
const first = store.getSnapshot();
|
|
1250
1271
|
await store.validate(["name"]);
|
|
1251
|
-
|
|
1252
|
-
|
|
1272
|
+
assertSame(store.getSnapshot().errors.name, first.errors.name);
|
|
1273
|
+
assertSame(selectFieldState(store.getSnapshot(), "name"), selectFieldState(first, "name"));
|
|
1253
1274
|
store.blur("nickname");
|
|
1254
1275
|
store.reportNative({ nickname: { type: "valueMissing" } });
|
|
1255
1276
|
store.reset();
|
|
1256
1277
|
store.setValue("nickname", "");
|
|
1257
|
-
|
|
1258
|
-
|
|
1278
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
1279
|
+
assertEqual(
|
|
1280
|
+
errorsOf(store).nickname.all.map(({ source }) => source),
|
|
1281
|
+
["validation"]
|
|
1282
|
+
);
|
|
1259
1283
|
}
|
|
1260
1284
|
},
|
|
1261
1285
|
{
|
|
@@ -1264,15 +1288,17 @@ var cases = [
|
|
|
1264
1288
|
run(createStore) {
|
|
1265
1289
|
const store = createStore(fixture().options);
|
|
1266
1290
|
const commands = store.fieldArray("contacts");
|
|
1267
|
-
|
|
1291
|
+
assertSame(store.fieldArray("contacts"), commands);
|
|
1268
1292
|
const rows = store.getSnapshot().rowIds.contacts;
|
|
1269
|
-
|
|
1293
|
+
assertSame(toFieldArrayValue(rows, commands), toFieldArrayValue(rows, commands));
|
|
1270
1294
|
store.setValue("name", "Grace");
|
|
1271
|
-
|
|
1295
|
+
assertSame(
|
|
1296
|
+
toFieldArrayValue(store.getSnapshot().rowIds.contacts, commands),
|
|
1272
1297
|
toFieldArrayValue(rows, commands)
|
|
1273
1298
|
);
|
|
1274
1299
|
commands.append({ email: "x@example.com" });
|
|
1275
|
-
|
|
1300
|
+
assertNotSame(
|
|
1301
|
+
toFieldArrayValue(store.getSnapshot().rowIds.contacts, commands),
|
|
1276
1302
|
toFieldArrayValue(rows, commands)
|
|
1277
1303
|
);
|
|
1278
1304
|
}
|
|
@@ -1283,23 +1309,24 @@ var cases = [
|
|
|
1283
1309
|
run(createStore) {
|
|
1284
1310
|
const good = toHydration(createStore(fixture().options).getSnapshot());
|
|
1285
1311
|
const start = (hydration) => () => createStore(fixture({ snapshot: hydration }).options);
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1312
|
+
assertThrows(start({ ...good, rowIds: { ...good.rowIds, contacts: ["a", "b"] } }));
|
|
1313
|
+
assertThrows(start({ ...good, rowIds: { ...good.rowIds, invites: ["k", "k"] } }));
|
|
1314
|
+
assertThrows(start({ ...good, rowIds: { ...good.rowIds, name: ["x"] } }));
|
|
1315
|
+
assertThrows(start({ ...good, rowIds: { ...good.rowIds, contacts: ["a", "b", 7] } }));
|
|
1316
|
+
assertThrows(start({ ...good, rowIds: { contacts: good.rowIds.contacts } }));
|
|
1317
|
+
assertThrows(start({ ...good, rowIds: { ...good.rowIds, invites: good.rowIds.contacts } }));
|
|
1318
|
+
assertThrows(start({ values: good.values }));
|
|
1319
|
+
assertThrows(start("nothing"));
|
|
1320
|
+
assertThrows(start(null));
|
|
1321
|
+
assertDoesNotThrow(start(good));
|
|
1296
1322
|
}
|
|
1297
1323
|
},
|
|
1298
1324
|
{
|
|
1299
1325
|
rule: "array reindexing",
|
|
1300
1326
|
name: "containers built from the same defaults mint the same row ids",
|
|
1301
1327
|
run(createStore) {
|
|
1302
|
-
|
|
1328
|
+
assertEqual(
|
|
1329
|
+
createStore(fixture().options).getSnapshot().rowIds,
|
|
1303
1330
|
createStore(fixture().options).getSnapshot().rowIds
|
|
1304
1331
|
);
|
|
1305
1332
|
}
|
|
@@ -1311,26 +1338,25 @@ var cases = [
|
|
|
1311
1338
|
const store = createStore(fixture().options);
|
|
1312
1339
|
const answer = await passedSubmission(store);
|
|
1313
1340
|
const values = store.getSnapshot().values;
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1341
|
+
assertThrows(() => answer.setServerErrors({ __secret: { message: "x" } }), /reserved segment '__secret'/);
|
|
1342
|
+
assertThrows(() => answer.setServerErrors({ "contacts.__proto__.email": { message: "x" } }), /reserved/);
|
|
1343
|
+
assertThrows(() => store.blur(FORM_ROOT), /reserved/);
|
|
1344
|
+
assertThrows(() => store.setValue("__x", 1), /reserved/);
|
|
1345
|
+
assertThrows(() => store.reportNative({ __x: { type: "valueMissing" } }), /reserved/);
|
|
1346
|
+
assertThrows(
|
|
1347
|
+
() => answer.setServerErrors({ "contacts.4.email": { message: "bounced" } }),
|
|
1320
1348
|
/'contacts.4.email' names row '4' of 'contacts', which has 3 rows/
|
|
1321
1349
|
);
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
);
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
expect(store.getSnapshot().errors).toEqual({});
|
|
1330
|
-
expect(
|
|
1350
|
+
assertThrows(() => answer.setServerErrors({ "contacts.x": { message: "x" } }), /names row 'x'/);
|
|
1351
|
+
assertThrows(() => answer.setServerErrors({ "contacts.-1.email": { message: "x" } }), /names row '-1'/);
|
|
1352
|
+
assertThrows(() => answer.setServerErrors({ "contacts.1e-7.email": { message: "x" } }), /names row '1e-7'/);
|
|
1353
|
+
assertThrows(() => answer.setServerErrors({ "contacts.01.email": { message: "x" } }), /names row '01'/);
|
|
1354
|
+
assertSame(store.getSnapshot().values, values);
|
|
1355
|
+
assertEqual(store.getSnapshot().errors, {});
|
|
1356
|
+
assertDoesNotThrow(
|
|
1331
1357
|
() => answer.setServerErrors({ "nothing.here": { message: "fine" }, [FORM_ROOT]: { message: "form" } })
|
|
1332
|
-
)
|
|
1333
|
-
|
|
1358
|
+
);
|
|
1359
|
+
assertEqual(Object.keys(errorsOf(store)), [FORM_ROOT]);
|
|
1334
1360
|
}
|
|
1335
1361
|
},
|
|
1336
1362
|
{
|
|
@@ -1342,12 +1368,12 @@ var cases = [
|
|
|
1342
1368
|
gate.hold("taken");
|
|
1343
1369
|
store.setValue("slug", "taken");
|
|
1344
1370
|
const run = store.validate(["slug"]);
|
|
1345
|
-
await
|
|
1346
|
-
|
|
1371
|
+
await waitFor(() => assertSame(gate.pending("taken"), 1));
|
|
1372
|
+
assertSame(isValidating(store), true);
|
|
1347
1373
|
gate.settle("taken", false);
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1374
|
+
assertEqual(await run, { outcome: "invalid" });
|
|
1375
|
+
assertSame(errorsOf(store).slug?.type, "gate");
|
|
1376
|
+
assertSame(isValidating(store), false);
|
|
1351
1377
|
}
|
|
1352
1378
|
},
|
|
1353
1379
|
{
|
|
@@ -1359,13 +1385,13 @@ var cases = [
|
|
|
1359
1385
|
gate.hold("taken");
|
|
1360
1386
|
store.setValue("slug", "other");
|
|
1361
1387
|
store.setValue("slug", "taken");
|
|
1362
|
-
await
|
|
1388
|
+
await waitFor(() => assertSame(gate.pending("taken"), 1));
|
|
1363
1389
|
store.reset();
|
|
1364
|
-
|
|
1390
|
+
assertSame(store.getValue("slug"), "taken");
|
|
1365
1391
|
gate.settle("taken", false);
|
|
1366
|
-
await
|
|
1392
|
+
await waitFor(() => assertSame(isValidating(store), false));
|
|
1367
1393
|
await settle();
|
|
1368
|
-
|
|
1394
|
+
assertEqual(errorsOf(store), {});
|
|
1369
1395
|
}
|
|
1370
1396
|
},
|
|
1371
1397
|
{
|
|
@@ -1384,14 +1410,14 @@ var cases = [
|
|
|
1384
1410
|
const store = createStore(options);
|
|
1385
1411
|
gate.hold("one");
|
|
1386
1412
|
store.blur("invites.0.code");
|
|
1387
|
-
await
|
|
1413
|
+
await waitFor(() => assertSame(gate.pending("one"), 1));
|
|
1388
1414
|
store.fieldArray("invites").swap(0, 1);
|
|
1389
1415
|
gate.settle("one", false);
|
|
1390
|
-
await
|
|
1416
|
+
await waitFor(() => assertSame(isValidating(store), false));
|
|
1391
1417
|
await settle();
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1418
|
+
assertSame(store.getValue("invites.1.label"), "first");
|
|
1419
|
+
assertEqual(Object.keys(errorsOf(store)), ["invites.1.code"]);
|
|
1420
|
+
assertEqual(marked(store.getSnapshot().touched), ["invites.1.code"]);
|
|
1395
1421
|
}
|
|
1396
1422
|
},
|
|
1397
1423
|
{
|
|
@@ -1410,12 +1436,12 @@ var cases = [
|
|
|
1410
1436
|
const store = createStore(options);
|
|
1411
1437
|
gate.hold("one");
|
|
1412
1438
|
store.blur("invites.0.code");
|
|
1413
|
-
await
|
|
1439
|
+
await waitFor(() => assertSame(gate.pending("one"), 1));
|
|
1414
1440
|
store.fieldArray("invites").remove(0);
|
|
1415
1441
|
gate.settle("one", false);
|
|
1416
|
-
await
|
|
1442
|
+
await waitFor(() => assertSame(isValidating(store), false));
|
|
1417
1443
|
await settle();
|
|
1418
|
-
|
|
1444
|
+
assertEqual(errorsOf(store), {});
|
|
1419
1445
|
}
|
|
1420
1446
|
},
|
|
1421
1447
|
{
|
|
@@ -1426,16 +1452,16 @@ var cases = [
|
|
|
1426
1452
|
const store = createStore(options);
|
|
1427
1453
|
gate.hold("taken");
|
|
1428
1454
|
const run = store.validate(["slug"]);
|
|
1429
|
-
await
|
|
1455
|
+
await waitFor(() => assertSame(gate.pending("taken"), 1));
|
|
1430
1456
|
store.setValue("slug", "other");
|
|
1431
1457
|
store.reset();
|
|
1432
1458
|
const watch = watchValidation(store);
|
|
1433
1459
|
gate.settle("taken", false);
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1460
|
+
assertEqual(await run, { outcome: "overtaken" });
|
|
1461
|
+
assertSame(watch.started, false);
|
|
1462
|
+
assertSame(gate.pending("taken"), 0);
|
|
1463
|
+
assertEqual(errorsOf(store), {});
|
|
1464
|
+
assertSame(isValidating(store), false);
|
|
1439
1465
|
}
|
|
1440
1466
|
},
|
|
1441
1467
|
{
|
|
@@ -1449,12 +1475,12 @@ var cases = [
|
|
|
1449
1475
|
const store = createStore(options);
|
|
1450
1476
|
gate.hold("one");
|
|
1451
1477
|
store.blur("invites.0.code");
|
|
1452
|
-
await
|
|
1478
|
+
await waitFor(() => assertSame(gate.pending("one"), 1));
|
|
1453
1479
|
store.fieldArray("invites").replace([{ code: "one", label: "second" }]);
|
|
1454
1480
|
gate.settle("one", false);
|
|
1455
|
-
await
|
|
1481
|
+
await waitFor(() => assertSame(isValidating(store), false));
|
|
1456
1482
|
await settle();
|
|
1457
|
-
|
|
1483
|
+
assertEqual(errorsOf(store), {});
|
|
1458
1484
|
}
|
|
1459
1485
|
},
|
|
1460
1486
|
{
|
|
@@ -1473,13 +1499,13 @@ var cases = [
|
|
|
1473
1499
|
const store = createStore(options);
|
|
1474
1500
|
gate.hold("one");
|
|
1475
1501
|
store.blur("groups.0.members.1.code");
|
|
1476
|
-
await
|
|
1502
|
+
await waitFor(() => assertSame(gate.pending("one"), 1));
|
|
1477
1503
|
store.fieldArray("groups").swap(0, 1);
|
|
1478
1504
|
store.fieldArray("groups.1.members").remove(0);
|
|
1479
1505
|
gate.settle("one", false);
|
|
1480
|
-
await
|
|
1506
|
+
await waitFor(() => assertSame(isValidating(store), false));
|
|
1481
1507
|
await settle();
|
|
1482
|
-
|
|
1508
|
+
assertEqual(Object.keys(errorsOf(store)), ["groups.1.members.0.code"]);
|
|
1483
1509
|
}
|
|
1484
1510
|
},
|
|
1485
1511
|
{
|
|
@@ -1490,13 +1516,13 @@ var cases = [
|
|
|
1490
1516
|
const store = createStore(options);
|
|
1491
1517
|
gate.hold("one", "two");
|
|
1492
1518
|
const run = store.validate(["invites"]);
|
|
1493
|
-
await
|
|
1519
|
+
await waitFor(() => assertSame(gate.pending("one"), 1));
|
|
1494
1520
|
store.fieldArray("invites").swap(0, 1);
|
|
1495
1521
|
gate.settle("one", false);
|
|
1496
1522
|
gate.settle("two", true);
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1523
|
+
assertEqual(await run, { outcome: "invalid" });
|
|
1524
|
+
assertEqual(Object.keys(errorsOf(store)), ["invites.1.code"]);
|
|
1525
|
+
assertSame(isValidating(store), false);
|
|
1500
1526
|
}
|
|
1501
1527
|
},
|
|
1502
1528
|
{
|
|
@@ -1508,11 +1534,11 @@ var cases = [
|
|
|
1508
1534
|
gate.hold("taken");
|
|
1509
1535
|
store.setValue("slug", "taken");
|
|
1510
1536
|
const run = store.validate(["slug"]);
|
|
1511
|
-
await
|
|
1537
|
+
await waitFor(() => assertSame(gate.pending("taken"), 1));
|
|
1512
1538
|
store.setValue("slug", "free");
|
|
1513
1539
|
gate.settle("taken", false);
|
|
1514
|
-
|
|
1515
|
-
|
|
1540
|
+
assertEqual(await run, { outcome: "passed" });
|
|
1541
|
+
assertUndefined(errorsOf(store).slug);
|
|
1516
1542
|
}
|
|
1517
1543
|
},
|
|
1518
1544
|
{
|
|
@@ -1525,14 +1551,14 @@ var cases = [
|
|
|
1525
1551
|
gate.hold("a", "b");
|
|
1526
1552
|
store.setValue("slug", "a");
|
|
1527
1553
|
const run = store.validate(["slug"]);
|
|
1528
|
-
await
|
|
1554
|
+
await waitFor(() => assertSame(gate.pending("a"), 1));
|
|
1529
1555
|
store.setValue("slug", "b");
|
|
1530
1556
|
gate.settle("a", true);
|
|
1531
|
-
await
|
|
1557
|
+
await waitFor(() => assertSame(gate.pending("b"), 1));
|
|
1532
1558
|
store.setValue("slug", "taken");
|
|
1533
1559
|
gate.settle("b", true);
|
|
1534
|
-
|
|
1535
|
-
|
|
1560
|
+
assertEqual(await run, { outcome: "overtaken" });
|
|
1561
|
+
assertEqual(await store.validate(["slug"]), { outcome: "invalid" });
|
|
1536
1562
|
}
|
|
1537
1563
|
},
|
|
1538
1564
|
{
|
|
@@ -1544,13 +1570,13 @@ var cases = [
|
|
|
1544
1570
|
gate.hold("taken");
|
|
1545
1571
|
const validated = store.validate(["slug"]);
|
|
1546
1572
|
const submitted = store.submit();
|
|
1547
|
-
await
|
|
1573
|
+
await waitFor(() => assertSame(gate.pending("taken"), 2));
|
|
1548
1574
|
store.reset();
|
|
1549
1575
|
gate.settle("taken", false);
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1576
|
+
assertEqual(await validated, { outcome: "overtaken" });
|
|
1577
|
+
assertEqual(await submitted, { outcome: "overtaken" });
|
|
1578
|
+
assertEqual(errorsOf(store), {});
|
|
1579
|
+
assertEqual(await store.validate(["slug"]), { outcome: "invalid" });
|
|
1554
1580
|
}
|
|
1555
1581
|
},
|
|
1556
1582
|
{
|
|
@@ -1561,11 +1587,11 @@ var cases = [
|
|
|
1561
1587
|
const store = createStore(options);
|
|
1562
1588
|
gate.hold("one");
|
|
1563
1589
|
const run = store.validate(["invites.0.code"]);
|
|
1564
|
-
await
|
|
1590
|
+
await waitFor(() => assertSame(gate.pending("one"), 1));
|
|
1565
1591
|
store.fieldArray("invites").swap(0, 1);
|
|
1566
1592
|
gate.settle("one", false);
|
|
1567
|
-
|
|
1568
|
-
|
|
1593
|
+
assertEqual(await run, { outcome: "invalid" });
|
|
1594
|
+
assertEqual(Object.keys(errorsOf(store)), ["invites.1.code"]);
|
|
1569
1595
|
}
|
|
1570
1596
|
},
|
|
1571
1597
|
{
|
|
@@ -1576,22 +1602,22 @@ var cases = [
|
|
|
1576
1602
|
const store = createStore(options);
|
|
1577
1603
|
gate.hold("two");
|
|
1578
1604
|
const removed = store.validate(["invites.1.code"]);
|
|
1579
|
-
await
|
|
1605
|
+
await waitFor(() => assertSame(gate.pending("two"), 1));
|
|
1580
1606
|
store.fieldArray("invites").remove(1);
|
|
1581
1607
|
gate.settle("two", false);
|
|
1582
|
-
|
|
1583
|
-
|
|
1608
|
+
assertEqual(await removed, { outcome: "overtaken" });
|
|
1609
|
+
assertEqual(errorsOf(store), {});
|
|
1584
1610
|
const other = createStore(fixture().options);
|
|
1585
1611
|
const held = fixture();
|
|
1586
1612
|
held.gate.hold("one");
|
|
1587
1613
|
const reset = createStore(held.options);
|
|
1588
1614
|
const overtaken = reset.validate(["invites.0.code"]);
|
|
1589
|
-
await
|
|
1615
|
+
await waitFor(() => assertSame(held.gate.pending("one"), 1));
|
|
1590
1616
|
reset.reset();
|
|
1591
1617
|
held.gate.settle("one", false);
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1618
|
+
assertEqual(await overtaken, { outcome: "overtaken" });
|
|
1619
|
+
assertEqual(errorsOf(reset), {});
|
|
1620
|
+
assertEqual(await other.validate(), { outcome: "passed" });
|
|
1595
1621
|
}
|
|
1596
1622
|
},
|
|
1597
1623
|
{
|
|
@@ -1604,15 +1630,15 @@ var cases = [
|
|
|
1604
1630
|
const answer = await passedSubmission(store);
|
|
1605
1631
|
gate.hold("pending");
|
|
1606
1632
|
const first = store.checkValidity();
|
|
1607
|
-
await
|
|
1633
|
+
await waitFor(() => assertSame(gate.pending("pending"), 1));
|
|
1608
1634
|
answer.setServerErrors({ "invites.0.code": { type: "late" } });
|
|
1609
1635
|
gate.settle("pending", true);
|
|
1610
|
-
|
|
1611
|
-
|
|
1636
|
+
assertSame(await first, true);
|
|
1637
|
+
assertSame(await store.checkValidity(), false);
|
|
1612
1638
|
store.setValue("invites.0.code", "other");
|
|
1613
|
-
|
|
1639
|
+
assertSame(await store.checkValidity(), true);
|
|
1614
1640
|
store.reportNative({ "invites.0.code": { type: "valueMissing" } });
|
|
1615
|
-
|
|
1641
|
+
assertSame(await store.checkValidity(), false);
|
|
1616
1642
|
}
|
|
1617
1643
|
},
|
|
1618
1644
|
{
|
|
@@ -1623,11 +1649,11 @@ var cases = [
|
|
|
1623
1649
|
const run = store.submit();
|
|
1624
1650
|
store.setValue("nickname", "ada2");
|
|
1625
1651
|
const submitted = passedOf(await run);
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1652
|
+
assertSame(submitted.values.nickname, "ada2");
|
|
1653
|
+
assertEqual(submitted.values, store.getSnapshot().values);
|
|
1654
|
+
assertSame(Object.isFrozen(submitted.values), true);
|
|
1629
1655
|
submitted.setServerErrors({ nickname: { type: "taken" } });
|
|
1630
|
-
|
|
1656
|
+
assertSame(errorsOf(store).nickname?.type, "taken");
|
|
1631
1657
|
}
|
|
1632
1658
|
},
|
|
1633
1659
|
{
|
|
@@ -1636,13 +1662,13 @@ var cases = [
|
|
|
1636
1662
|
async run(createStore) {
|
|
1637
1663
|
const store = createStore(fixture().options);
|
|
1638
1664
|
store.setValue("name", "");
|
|
1639
|
-
|
|
1665
|
+
assertEqual(await store.submit(), { outcome: "invalid" });
|
|
1640
1666
|
store.setValue("name", "Grace");
|
|
1641
1667
|
const submitted = await passedSubmission(store);
|
|
1642
|
-
|
|
1668
|
+
assertSame(submitted.values.name, "Grace");
|
|
1643
1669
|
store.setValue("nickname", "changed");
|
|
1644
1670
|
submitted.setServerErrors({ name: { type: "taken" }, nickname: { type: "taken" } });
|
|
1645
|
-
|
|
1671
|
+
assertEqual(Object.keys(errorsOf(store)), ["name"]);
|
|
1646
1672
|
}
|
|
1647
1673
|
},
|
|
1648
1674
|
{
|
|
@@ -1653,11 +1679,11 @@ var cases = [
|
|
|
1653
1679
|
const older = store.submit();
|
|
1654
1680
|
const newer = store.submit();
|
|
1655
1681
|
store.setValue("name", "Grace");
|
|
1656
|
-
|
|
1682
|
+
assertEqual(await older, { outcome: "overtaken" });
|
|
1657
1683
|
const submitted = passedOf(await newer);
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1684
|
+
assertSame(submitted.values.name, "Grace");
|
|
1685
|
+
assertSame(Object.isFrozen(submitted.values), true);
|
|
1686
|
+
assertSame(submitted.values, submitted.values);
|
|
1661
1687
|
}
|
|
1662
1688
|
},
|
|
1663
1689
|
{
|
|
@@ -1668,37 +1694,37 @@ var cases = [
|
|
|
1668
1694
|
const store = createStore(options);
|
|
1669
1695
|
gate.hold("one");
|
|
1670
1696
|
store.blur("invites.0.code");
|
|
1671
|
-
await
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1697
|
+
await waitFor(() => assertSame(gate.pending("one"), 1));
|
|
1698
|
+
assertEqual(store.getSnapshot().validating, { "invites.0.code": true });
|
|
1699
|
+
assertSame(isValidating(store), true);
|
|
1700
|
+
assertSame(fieldState(store, "invites.0.code").isValidating, true);
|
|
1701
|
+
assertSame(fieldState(store, "invites.1.code").isValidating, false);
|
|
1676
1702
|
store.fieldArray("invites").swap(0, 1);
|
|
1677
|
-
|
|
1703
|
+
assertEqual(store.getSnapshot().validating, { "invites.1.code": true });
|
|
1678
1704
|
gate.settle("one", true);
|
|
1679
|
-
await
|
|
1705
|
+
await waitFor(() => assertSame(isValidating(store), false));
|
|
1680
1706
|
await settle();
|
|
1681
|
-
|
|
1707
|
+
assertEqual(store.getSnapshot().validating, {});
|
|
1682
1708
|
const racing = fixture();
|
|
1683
1709
|
racing.gate.hold("a");
|
|
1684
1710
|
const second = createStore(racing.options);
|
|
1685
1711
|
second.setValue("slug", "a");
|
|
1686
1712
|
const older = second.validate(["slug"]);
|
|
1687
|
-
await
|
|
1713
|
+
await waitFor(() => assertSame(racing.gate.pending("a"), 1));
|
|
1688
1714
|
second.setValue("slug", "b");
|
|
1689
|
-
|
|
1690
|
-
|
|
1715
|
+
assertEqual(await second.validate(["slug"]), { outcome: "passed" });
|
|
1716
|
+
assertEqual(second.getSnapshot().validating, {});
|
|
1691
1717
|
racing.gate.settle("a", true);
|
|
1692
|
-
|
|
1718
|
+
assertEqual(await older, { outcome: "passed" });
|
|
1693
1719
|
}
|
|
1694
1720
|
},
|
|
1695
1721
|
{
|
|
1696
1722
|
rule: "pending per field",
|
|
1697
1723
|
name: "a superseded async check leaves no issue and no pending mark: pending is state, never an issue",
|
|
1698
1724
|
async run(createStore) {
|
|
1699
|
-
|
|
1725
|
+
const restoreFetch = stubGlobal(
|
|
1700
1726
|
"fetch",
|
|
1701
|
-
|
|
1727
|
+
createSpy(async () => new Response(JSON.stringify({ valid: true })))
|
|
1702
1728
|
);
|
|
1703
1729
|
try {
|
|
1704
1730
|
const store = createStore(
|
|
@@ -1716,14 +1742,14 @@ var cases = [
|
|
|
1716
1742
|
);
|
|
1717
1743
|
store.setValue("handle", "a");
|
|
1718
1744
|
store.setValue("handle", "ab");
|
|
1719
|
-
await
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1745
|
+
await waitFor(() => assertSame(isValidating(store), false), { timeout: 2e3 });
|
|
1746
|
+
assertEqual(errorsOf(store), {});
|
|
1747
|
+
assertEqual(store.getSnapshot().warnings, {});
|
|
1748
|
+
assertEqual(store.getSnapshot().validating, {});
|
|
1749
|
+
assertNotMatches(JSON.stringify(store.getSnapshot()), /pending/i);
|
|
1750
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
1725
1751
|
} finally {
|
|
1726
|
-
|
|
1752
|
+
restoreFetch();
|
|
1727
1753
|
}
|
|
1728
1754
|
}
|
|
1729
1755
|
},
|
|
@@ -1734,18 +1760,18 @@ var cases = [
|
|
|
1734
1760
|
const store = createStore(fixture().options);
|
|
1735
1761
|
const old = await passedSubmission(store);
|
|
1736
1762
|
old.setServerErrors({ name: { type: "old" } });
|
|
1737
|
-
|
|
1763
|
+
assertSame(errorsOf(store).name?.type, "old");
|
|
1738
1764
|
const submission = await passedSubmission(store);
|
|
1739
|
-
|
|
1765
|
+
assertEqual(errorsOf(store), {});
|
|
1740
1766
|
store.setValue("name", "Grace");
|
|
1741
1767
|
submission.setServerErrors({ name: { type: "taken" }, nickname: { type: "blocked" } });
|
|
1742
|
-
|
|
1768
|
+
assertEqual(Object.keys(errorsOf(store)), ["nickname"]);
|
|
1743
1769
|
store.setValue("nickname", "other");
|
|
1744
|
-
|
|
1770
|
+
assertEqual(errorsOf(store), {});
|
|
1745
1771
|
const formWide = await passedSubmission(store);
|
|
1746
1772
|
store.setValue("slug", "changed");
|
|
1747
1773
|
formWide.setServerErrors({ [FORM_ROOT]: { type: "invalid_credentials" } });
|
|
1748
|
-
|
|
1774
|
+
assertEqual(errorsOf(store), {});
|
|
1749
1775
|
}
|
|
1750
1776
|
},
|
|
1751
1777
|
{
|
|
@@ -1759,12 +1785,12 @@ var cases = [
|
|
|
1759
1785
|
"contacts.0.email": { type: "bounced" },
|
|
1760
1786
|
"contacts.2.email": { type: "blocked" }
|
|
1761
1787
|
});
|
|
1762
|
-
|
|
1788
|
+
assertEqual(Object.keys(errorsOf(store)).toSorted(), ["contacts.1.email", "contacts.2.email"]);
|
|
1763
1789
|
store.fieldArray("contacts").remove(2);
|
|
1764
1790
|
const again = await passedSubmission(store);
|
|
1765
1791
|
store.fieldArray("contacts").remove(0);
|
|
1766
1792
|
again.setServerErrors({ "contacts.0.email": { type: "bounced" } });
|
|
1767
|
-
|
|
1793
|
+
assertEqual(errorsOf(store), {});
|
|
1768
1794
|
}
|
|
1769
1795
|
},
|
|
1770
1796
|
{
|
|
@@ -1775,13 +1801,13 @@ var cases = [
|
|
|
1775
1801
|
const stale = await passedSubmission(store);
|
|
1776
1802
|
store.setValue("password", "b");
|
|
1777
1803
|
stale.setServerErrors({ confirm: { type: "mismatch" } });
|
|
1778
|
-
|
|
1804
|
+
assertEqual(errorsOf(store), {});
|
|
1779
1805
|
store.setValue("password", "a");
|
|
1780
1806
|
const fresh = await passedSubmission(store);
|
|
1781
1807
|
fresh.setServerErrors({ confirm: { type: "mismatch" } });
|
|
1782
|
-
|
|
1808
|
+
assertSame(errorsOf(store).confirm?.type, "mismatch");
|
|
1783
1809
|
store.setValue("password", "b");
|
|
1784
|
-
|
|
1810
|
+
assertEqual(errorsOf(store), {});
|
|
1785
1811
|
}
|
|
1786
1812
|
},
|
|
1787
1813
|
{
|
|
@@ -1792,14 +1818,14 @@ var cases = [
|
|
|
1792
1818
|
const beforeReset = await passedSubmission(store);
|
|
1793
1819
|
store.reset();
|
|
1794
1820
|
beforeReset.setServerErrors({ name: { type: "taken" } });
|
|
1795
|
-
|
|
1821
|
+
assertEqual(errorsOf(store), {});
|
|
1796
1822
|
const first = await passedSubmission(store);
|
|
1797
1823
|
const second = await passedSubmission(store);
|
|
1798
1824
|
first.setServerErrors({ name: { type: "taken" } });
|
|
1799
|
-
|
|
1825
|
+
assertEqual(errorsOf(store), {});
|
|
1800
1826
|
second.setServerErrors({ name: { type: "taken" } });
|
|
1801
|
-
|
|
1802
|
-
|
|
1827
|
+
assertSame(errorsOf(store).name?.type, "taken");
|
|
1828
|
+
assertEqual(second.values, store.getSnapshot().values);
|
|
1803
1829
|
}
|
|
1804
1830
|
},
|
|
1805
1831
|
{
|
|
@@ -1815,8 +1841,8 @@ var cases = [
|
|
|
1815
1841
|
],
|
|
1816
1842
|
nickname: []
|
|
1817
1843
|
});
|
|
1818
|
-
|
|
1819
|
-
|
|
1844
|
+
assertEqual(Object.keys(errorsOf(store)), ["name"]);
|
|
1845
|
+
assertEqual(errorsOf(store).name.all, [
|
|
1820
1846
|
{ type: "taken", source: "server", message: "Already registered" },
|
|
1821
1847
|
{ type: "blocked_domain", source: "server", params: { domain: "example.com" } }
|
|
1822
1848
|
]);
|
|
@@ -1829,15 +1855,15 @@ var cases = [
|
|
|
1829
1855
|
const store = createStore(fixture({ validationMode: "onChange" }).options);
|
|
1830
1856
|
store.setValue("nickname", "bad");
|
|
1831
1857
|
store.reportNative({ nickname: { type: "typeMismatch" } });
|
|
1832
|
-
await
|
|
1833
|
-
|
|
1858
|
+
await waitFor(() => assertSame(errorsOf(store).nickname?.source, "native"));
|
|
1859
|
+
assertSame(await store.checkValidity(), false);
|
|
1834
1860
|
store.setValue("nickname", "good");
|
|
1835
|
-
await
|
|
1836
|
-
|
|
1861
|
+
await waitFor(() => assertUndefined(errorsOf(store).nickname));
|
|
1862
|
+
assertSame(await store.checkValidity(), true);
|
|
1837
1863
|
store.setValue("nickname", "bad");
|
|
1838
1864
|
await settle();
|
|
1839
|
-
|
|
1840
|
-
|
|
1865
|
+
assertUndefined(errorsOf(store).nickname);
|
|
1866
|
+
assertEqual(await store.validate(["nickname"]), { outcome: "passed" });
|
|
1841
1867
|
}
|
|
1842
1868
|
},
|
|
1843
1869
|
{
|
|
@@ -1847,17 +1873,17 @@ var cases = [
|
|
|
1847
1873
|
const store = createStore(fixture({ validationMode: "onChange" }).options);
|
|
1848
1874
|
store.setValue("nickname", "nick");
|
|
1849
1875
|
store.reportNative({ nickname: { type: "badInput" } });
|
|
1850
|
-
await
|
|
1851
|
-
await
|
|
1876
|
+
await waitFor(() => assertSame(errorsOf(store).nickname?.source, "native"));
|
|
1877
|
+
await waitFor(() => assertSame(isValidating(store), false));
|
|
1852
1878
|
await settle();
|
|
1853
1879
|
const watch = watchValidation(store);
|
|
1854
1880
|
const before = store.getSnapshot();
|
|
1855
1881
|
store.reportNative({ nickname: { type: "badInput" } });
|
|
1856
1882
|
store.setValue("nickname", "nick");
|
|
1857
1883
|
await settle();
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1884
|
+
assertSame(watch.started, false);
|
|
1885
|
+
assertSame(store.getSnapshot(), before);
|
|
1886
|
+
assertSame(await store.checkValidity(), false);
|
|
1861
1887
|
}
|
|
1862
1888
|
},
|
|
1863
1889
|
{
|
|
@@ -1865,23 +1891,23 @@ var cases = [
|
|
|
1865
1891
|
name: "reportNative binds facts to the values held now, validates only paths already checked, and is no user change",
|
|
1866
1892
|
async run(createStore) {
|
|
1867
1893
|
const store = createStore(fixture({ validationMode: "onChange" }).options);
|
|
1868
|
-
const listener =
|
|
1894
|
+
const listener = createSpy();
|
|
1869
1895
|
store.subscribe(listener);
|
|
1870
1896
|
store.reportNative({ nickname: { type: "valueMissing" } });
|
|
1871
1897
|
await settle();
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1898
|
+
assertEqual(errorsOf(store), {});
|
|
1899
|
+
assertEqual(store.getSnapshot().dirty, {});
|
|
1900
|
+
assertEqual(store.getSnapshot().touched, {});
|
|
1901
|
+
assertCallCount(listener, 0);
|
|
1902
|
+
assertSame(await store.checkValidity(), false);
|
|
1903
|
+
assertEqual(await store.validate(["name"]), { outcome: "passed" });
|
|
1878
1904
|
store.reportNative({ name: { type: "typeMismatch", params: { type: "email" } }, nickname: null });
|
|
1879
|
-
await
|
|
1880
|
-
|
|
1905
|
+
await waitFor(() => assertSame(errorsOf(store).name?.type, "typeMismatch"));
|
|
1906
|
+
assertSame(await store.checkValidity(), false);
|
|
1881
1907
|
store.reportNative({ name: null });
|
|
1882
|
-
await
|
|
1883
|
-
|
|
1884
|
-
|
|
1908
|
+
await waitFor(() => assertUndefined(errorsOf(store).name));
|
|
1909
|
+
assertSame(await store.checkValidity(), true);
|
|
1910
|
+
assertEqual(store.getSnapshot().dirty, {});
|
|
1885
1911
|
}
|
|
1886
1912
|
},
|
|
1887
1913
|
{
|
|
@@ -1891,7 +1917,7 @@ var cases = [
|
|
|
1891
1917
|
const store = createStore(fixture({ validationMode: "onChange" }).options);
|
|
1892
1918
|
store.setValue("nickname", "x");
|
|
1893
1919
|
store.reportNative({ nickname: { type: "typeMismatch" } });
|
|
1894
|
-
await
|
|
1920
|
+
await waitFor(() => assertSame(errorsOf(store).nickname?.source, "native"));
|
|
1895
1921
|
store.reset();
|
|
1896
1922
|
store.reportNative({
|
|
1897
1923
|
nickname: { type: "valueMissing" },
|
|
@@ -1899,11 +1925,11 @@ var cases = [
|
|
|
1899
1925
|
"nothing.here": { type: "valueMissing" }
|
|
1900
1926
|
});
|
|
1901
1927
|
await settle();
|
|
1902
|
-
|
|
1903
|
-
|
|
1928
|
+
assertEqual(errorsOf(store), {});
|
|
1929
|
+
assertSame(store.getSnapshot().isValid, true);
|
|
1904
1930
|
store.fieldArray("contacts").remove(2);
|
|
1905
|
-
|
|
1906
|
-
|
|
1931
|
+
assertDoesNotThrow(() => store.reportNative({ "contacts.2.email": { type: "valueMissing" } }));
|
|
1932
|
+
assertSame(await store.checkValidity(), false);
|
|
1907
1933
|
}
|
|
1908
1934
|
},
|
|
1909
1935
|
{
|
|
@@ -1914,11 +1940,11 @@ var cases = [
|
|
|
1914
1940
|
store.blur("contacts.1.label");
|
|
1915
1941
|
store.reportNative({ "contacts.1.label": { type: "typeMismatch" } });
|
|
1916
1942
|
store.fieldArray("contacts").swap(1, 2);
|
|
1917
|
-
|
|
1918
|
-
|
|
1943
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
1944
|
+
assertEqual(Object.keys(errorsOf(store)), ["contacts.2.label"]);
|
|
1919
1945
|
store.fieldArray("contacts").remove(2);
|
|
1920
|
-
|
|
1921
|
-
|
|
1946
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
1947
|
+
assertEqual(errorsOf(store), {});
|
|
1922
1948
|
}
|
|
1923
1949
|
},
|
|
1924
1950
|
{
|
|
@@ -1927,15 +1953,15 @@ var cases = [
|
|
|
1927
1953
|
async run(createStore) {
|
|
1928
1954
|
const store = createStore(fixture().options);
|
|
1929
1955
|
store.reportNative({ name: { type: "valueMissing" }, nickname: { type: "valueMissing" } });
|
|
1930
|
-
|
|
1956
|
+
assertSame(await store.checkValidity(), false);
|
|
1931
1957
|
store.reportNative({ nickname: null });
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1958
|
+
assertSame(await store.checkValidity(), false);
|
|
1959
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
1960
|
+
assertEqual(Object.keys(errorsOf(store)), ["name"]);
|
|
1935
1961
|
store.reportNative({ name: null });
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1962
|
+
assertSame(await store.checkValidity(), true);
|
|
1963
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
1964
|
+
assertEqual(errorsOf(store), {});
|
|
1939
1965
|
}
|
|
1940
1966
|
},
|
|
1941
1967
|
{
|
|
@@ -1943,19 +1969,19 @@ var cases = [
|
|
|
1943
1969
|
name: "one call reports several controls in one commit, and ignores the rows that do not exist",
|
|
1944
1970
|
async run(createStore) {
|
|
1945
1971
|
const store = createStore(fixture().options);
|
|
1946
|
-
const listener =
|
|
1972
|
+
const listener = createSpy();
|
|
1947
1973
|
store.subscribe(listener);
|
|
1948
1974
|
store.reportNative({
|
|
1949
1975
|
name: { type: "valueMissing" },
|
|
1950
1976
|
nickname: { type: "valueMissing" },
|
|
1951
1977
|
"contacts.9.email": { type: "valueMissing" }
|
|
1952
1978
|
});
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1979
|
+
assertCallCount(listener, 0);
|
|
1980
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
1981
|
+
assertEqual(Object.keys(errorsOf(store)).toSorted(), ["name", "nickname"]);
|
|
1956
1982
|
store.reportNative({ name: null, nickname: null });
|
|
1957
|
-
await
|
|
1958
|
-
|
|
1983
|
+
await waitFor(() => assertEqual(errorsOf(store), {}));
|
|
1984
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
1959
1985
|
}
|
|
1960
1986
|
},
|
|
1961
1987
|
{
|
|
@@ -1964,14 +1990,17 @@ var cases = [
|
|
|
1964
1990
|
async run(createStore) {
|
|
1965
1991
|
const store = createStore(fixture().options);
|
|
1966
1992
|
store.fieldArray("contacts").remove([0, 1, 2]);
|
|
1967
|
-
|
|
1993
|
+
assertThrows(() => store.blur("contacts.0.label"), /names row/);
|
|
1968
1994
|
store.setValue("contacts", null);
|
|
1969
1995
|
store.reportNative({
|
|
1970
1996
|
"contacts.0.label": { type: "valueMissing" },
|
|
1971
1997
|
"contacts.1.label": { type: "valueMissing" }
|
|
1972
1998
|
});
|
|
1973
1999
|
await store.validate();
|
|
1974
|
-
|
|
2000
|
+
assertEqual(
|
|
2001
|
+
Object.keys(errorsOf(store)).filter((path) => path.endsWith(".label")),
|
|
2002
|
+
[]
|
|
2003
|
+
);
|
|
1975
2004
|
store.setValue("contacts", []);
|
|
1976
2005
|
const allowed = ["first"];
|
|
1977
2006
|
const answer = await passedSubmission(store);
|
|
@@ -1981,9 +2010,9 @@ var cases = [
|
|
|
1981
2010
|
await store.validate(["nickname"]);
|
|
1982
2011
|
allowed.push("second");
|
|
1983
2012
|
fact.params.list.push("b");
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
2013
|
+
assertEqual(errorsOf(store).name.params, { allowed: ["first"] });
|
|
2014
|
+
assertEqual(errorsOf(store).nickname.params, { list: ["a"] });
|
|
2015
|
+
assertSame(Object.isFrozen(errorsOf(store).name.params.allowed), true);
|
|
1987
2016
|
}
|
|
1988
2017
|
},
|
|
1989
2018
|
{
|
|
@@ -1994,14 +2023,14 @@ var cases = [
|
|
|
1994
2023
|
const store = createStore(options);
|
|
1995
2024
|
gate.hold("two");
|
|
1996
2025
|
const run = store.validate(["invites.1.code"]);
|
|
1997
|
-
await
|
|
1998
|
-
|
|
2026
|
+
await waitFor(() => assertSame(gate.pending("two"), 1));
|
|
2027
|
+
assertEqual(store.getSnapshot().validating, { "invites.1.code": true });
|
|
1999
2028
|
store.setValue("invites", []);
|
|
2000
|
-
|
|
2029
|
+
assertEqual(store.getSnapshot().validating, {});
|
|
2001
2030
|
gate.settle("two", true);
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2031
|
+
assertEqual(await run, { outcome: "overtaken" });
|
|
2032
|
+
assertEqual(store.getSnapshot().validating, {});
|
|
2033
|
+
assertSame(isValidating(store), false);
|
|
2005
2034
|
}
|
|
2006
2035
|
},
|
|
2007
2036
|
{
|
|
@@ -2009,22 +2038,22 @@ var cases = [
|
|
|
2009
2038
|
name: "a field a constraint hides takes no part: it does not block, count or show, however it was recorded",
|
|
2010
2039
|
async run(createStore) {
|
|
2011
2040
|
const store = createStore(businessForm());
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2041
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
2042
|
+
assertSame(await store.checkValidity(), true);
|
|
2043
|
+
assertEqual(errorsOf(store), {});
|
|
2015
2044
|
store.setValue("kind", "business");
|
|
2016
|
-
|
|
2017
|
-
|
|
2045
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
2046
|
+
assertMatches(errorsOf(store).company, { type: "required", ruleId: "company-required" });
|
|
2018
2047
|
store.setValue("kind", "person");
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2048
|
+
assertEqual(errorsOf(store), {});
|
|
2049
|
+
assertSame(store.getSnapshot().isValid, true);
|
|
2050
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
2022
2051
|
await serverAnswer(store, { company: { type: "taken" } });
|
|
2023
2052
|
store.blur("company");
|
|
2024
2053
|
store.reportNative({ company: { type: "valueMissing" } });
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2054
|
+
assertSame(store.getSnapshot().isValid, true);
|
|
2055
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
2056
|
+
assertSame(await store.checkValidity(), true);
|
|
2028
2057
|
}
|
|
2029
2058
|
},
|
|
2030
2059
|
{
|
|
@@ -2032,16 +2061,16 @@ var cases = [
|
|
|
2032
2061
|
name: "a step its constraints hide is skipped: its fields take no part, its values are kept and the submitted values leave them out",
|
|
2033
2062
|
async run(createStore) {
|
|
2034
2063
|
const store = createStore(stepsForm({ hasCompany: false, wantsInvoice: "no", company: "", vat: "" }));
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2064
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
2065
|
+
assertSame(await store.checkValidity(), true);
|
|
2066
|
+
assertEqual(errorsOf(store), {});
|
|
2038
2067
|
const submitted = await store.submit();
|
|
2039
|
-
|
|
2040
|
-
if (submitted.outcome === "passed")
|
|
2041
|
-
|
|
2068
|
+
assertSame(submitted.outcome, "passed");
|
|
2069
|
+
if (submitted.outcome === "passed") assertEqual(submitted.values, { hasCompany: false });
|
|
2070
|
+
assertMatches(store.getSnapshot().values, { wantsInvoice: "no", company: "" });
|
|
2042
2071
|
store.setValue("hasCompany", true);
|
|
2043
|
-
|
|
2044
|
-
|
|
2072
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
2073
|
+
assertEqual(Object.keys(errorsOf(store)), ["company"]);
|
|
2045
2074
|
}
|
|
2046
2075
|
},
|
|
2047
2076
|
{
|
|
@@ -2049,15 +2078,15 @@ var cases = [
|
|
|
2049
2078
|
name: "a value that takes no part is absent for the constraints after it, in order: a skipped step cannot keep a later field shown",
|
|
2050
2079
|
async run(createStore) {
|
|
2051
2080
|
const store = createStore(stepsForm({ hasCompany: false, wantsInvoice: "yes", company: "", vat: "" }));
|
|
2052
|
-
|
|
2053
|
-
|
|
2081
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
2082
|
+
assertSame(await store.checkValidity(), true);
|
|
2054
2083
|
store.setValue("hasCompany", true);
|
|
2055
2084
|
store.setValue("company", "Acme");
|
|
2056
|
-
|
|
2057
|
-
|
|
2085
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
2086
|
+
assertEqual(Object.keys(errorsOf(store)), ["vat"]);
|
|
2058
2087
|
store.setValue("hasCompany", false);
|
|
2059
|
-
|
|
2060
|
-
|
|
2088
|
+
assertEqual(errorsOf(store), {});
|
|
2089
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
2061
2090
|
}
|
|
2062
2091
|
},
|
|
2063
2092
|
{
|
|
@@ -2065,16 +2094,16 @@ var cases = [
|
|
|
2065
2094
|
name: "a path that takes part again is re-validated when it was checked before, and waits for its timing otherwise",
|
|
2066
2095
|
async run(createStore) {
|
|
2067
2096
|
const checked = createStore(businessForm({ kind: "business", company: "" }));
|
|
2068
|
-
|
|
2097
|
+
assertEqual(await checked.validate(), { outcome: "invalid" });
|
|
2069
2098
|
checked.setValue("kind", "person");
|
|
2070
|
-
|
|
2099
|
+
assertEqual(errorsOf(checked), {});
|
|
2071
2100
|
checked.setValue("kind", "business");
|
|
2072
|
-
await
|
|
2101
|
+
await waitFor(() => assertSame(errorsOf(checked).company?.type, "required"));
|
|
2073
2102
|
const untouched = createStore(businessForm());
|
|
2074
2103
|
untouched.setValue("kind", "business");
|
|
2075
2104
|
await settle();
|
|
2076
|
-
|
|
2077
|
-
|
|
2105
|
+
assertEqual(errorsOf(untouched), {});
|
|
2106
|
+
assertSame(untouched.getSnapshot().isValid, true);
|
|
2078
2107
|
}
|
|
2079
2108
|
},
|
|
2080
2109
|
{
|
|
@@ -2103,13 +2132,13 @@ var cases = [
|
|
|
2103
2132
|
{ locked: "", mode: "view", frozen: "", extra: { note: "" }, later: "" }
|
|
2104
2133
|
)
|
|
2105
2134
|
);
|
|
2106
|
-
|
|
2107
|
-
|
|
2135
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
2136
|
+
assertEqual(Object.keys(errorsOf(store)), ["later"]);
|
|
2108
2137
|
store.setValue("later", "x");
|
|
2109
|
-
|
|
2138
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
2110
2139
|
store.setValue("mode", "edit");
|
|
2111
|
-
|
|
2112
|
-
|
|
2140
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
2141
|
+
assertEqual(Object.keys(errorsOf(store)).toSorted(), ["extra.note", "frozen"]);
|
|
2113
2142
|
}
|
|
2114
2143
|
},
|
|
2115
2144
|
{
|
|
@@ -2133,23 +2162,26 @@ var cases = [
|
|
|
2133
2162
|
{ tag: "AB1234" }
|
|
2134
2163
|
)
|
|
2135
2164
|
);
|
|
2136
|
-
|
|
2165
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
2137
2166
|
const { all } = errorsOf(store).tag;
|
|
2138
|
-
|
|
2139
|
-
[
|
|
2140
|
-
[
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2167
|
+
assertEqual(
|
|
2168
|
+
all.map(({ type, ruleId }) => [type, ruleId]),
|
|
2169
|
+
[
|
|
2170
|
+
["pattern", "tag-letters"],
|
|
2171
|
+
["pattern", "tag-short"],
|
|
2172
|
+
["minLength", void 0]
|
|
2173
|
+
]
|
|
2174
|
+
);
|
|
2175
|
+
assertEqual(all[0], {
|
|
2144
2176
|
type: "pattern",
|
|
2145
2177
|
source: "validation",
|
|
2146
2178
|
ruleId: "tag-letters",
|
|
2147
2179
|
params: { pattern: "^[a-z]+$" },
|
|
2148
2180
|
message: "Letters only"
|
|
2149
2181
|
});
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2182
|
+
assertEqual(all[2].params, { minLength: 8 });
|
|
2183
|
+
assertUndefined(all[2].message);
|
|
2184
|
+
assertSame(Object.isFrozen(all[2].params), true);
|
|
2153
2185
|
}
|
|
2154
2186
|
},
|
|
2155
2187
|
{
|
|
@@ -2169,13 +2201,16 @@ var cases = [
|
|
|
2169
2201
|
const store = createStore(options);
|
|
2170
2202
|
gate.hold("ab");
|
|
2171
2203
|
const run = store.validate();
|
|
2172
|
-
await
|
|
2204
|
+
await waitFor(() => assertSame(gate.pending("ab"), 1));
|
|
2173
2205
|
gate.settle("ab", false);
|
|
2174
|
-
|
|
2206
|
+
assertEqual(await run, { outcome: "invalid" });
|
|
2175
2207
|
const first = errorsOf(store).slug;
|
|
2176
|
-
|
|
2208
|
+
assertEqual(
|
|
2209
|
+
first.all.map(({ type }) => type),
|
|
2210
|
+
["gate", "minLength"]
|
|
2211
|
+
);
|
|
2177
2212
|
await store.validate();
|
|
2178
|
-
|
|
2213
|
+
assertSame(errorsOf(store).slug, first);
|
|
2179
2214
|
}
|
|
2180
2215
|
},
|
|
2181
2216
|
{
|
|
@@ -2201,7 +2236,7 @@ var cases = [
|
|
|
2201
2236
|
() => void 0,
|
|
2202
2237
|
(error) => error
|
|
2203
2238
|
);
|
|
2204
|
-
|
|
2239
|
+
assertMatches(rejected, {
|
|
2205
2240
|
name: "FormValidationFailure",
|
|
2206
2241
|
path: "secret",
|
|
2207
2242
|
ruleType: "boom",
|
|
@@ -2211,23 +2246,24 @@ var cases = [
|
|
|
2211
2246
|
() => void 0,
|
|
2212
2247
|
(error) => error
|
|
2213
2248
|
);
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
const logged =
|
|
2249
|
+
assertMatches(check, { path: "secret", ruleType: "boom" });
|
|
2250
|
+
assertSame(isValidating(store), false);
|
|
2251
|
+
const logged = spyOn(logger, "error");
|
|
2217
2252
|
try {
|
|
2218
2253
|
const automatic = createStore(options);
|
|
2219
2254
|
automatic.setValue("secret", "x");
|
|
2220
2255
|
automatic.setValue("secret", "");
|
|
2221
|
-
await
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2256
|
+
await waitFor(() => assertDefined(errorsOf(automatic).secret));
|
|
2257
|
+
const report = logged.spy.calls.find(
|
|
2258
|
+
([message]) => typeof message === "string" && message.includes("'secret'")
|
|
2259
|
+
);
|
|
2260
|
+
assertMatches(report?.[1], { error: { path: "secret", ruleType: "boom", ruleId: "secret-boom" } });
|
|
2261
|
+
assertEqual(errorsOf(automatic).secret?.all, [
|
|
2226
2262
|
{ type: "required", source: "validation", ruleId: "secret-required" }
|
|
2227
2263
|
]);
|
|
2228
|
-
|
|
2264
|
+
assertSame(automatic.getSnapshot().isValid, false);
|
|
2229
2265
|
} finally {
|
|
2230
|
-
logged.
|
|
2266
|
+
logged.restore();
|
|
2231
2267
|
}
|
|
2232
2268
|
}
|
|
2233
2269
|
},
|
|
@@ -2258,8 +2294,8 @@ var cases = [
|
|
|
2258
2294
|
)
|
|
2259
2295
|
);
|
|
2260
2296
|
store.setValue("password", "abcde");
|
|
2261
|
-
await
|
|
2262
|
-
|
|
2297
|
+
await waitFor(() => assertDefined(store.getSnapshot().warnings.password));
|
|
2298
|
+
assertEqual(store.getSnapshot().warnings.password, {
|
|
2263
2299
|
type: "minLength",
|
|
2264
2300
|
source: "validation",
|
|
2265
2301
|
ruleId: "password-strength",
|
|
@@ -2275,19 +2311,19 @@ var cases = [
|
|
|
2275
2311
|
}
|
|
2276
2312
|
]
|
|
2277
2313
|
});
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2314
|
+
assertEqual(errorsOf(store), {});
|
|
2315
|
+
assertSame(store.getSnapshot().isValid, true);
|
|
2316
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
2317
|
+
assertSame(await store.checkValidity(), true);
|
|
2282
2318
|
const field = fieldState(store, "password");
|
|
2283
|
-
|
|
2284
|
-
|
|
2319
|
+
assertMatches(field, { invalid: false, error: void 0 });
|
|
2320
|
+
assertSame(fieldState(store, "password").warning, field.warning);
|
|
2285
2321
|
store.setValue("password", "abcdefgh");
|
|
2286
|
-
await
|
|
2322
|
+
await waitFor(() => assertEqual(store.getSnapshot().warnings, {}));
|
|
2287
2323
|
store.setValue("password", "a");
|
|
2288
|
-
await
|
|
2289
|
-
|
|
2290
|
-
|
|
2324
|
+
await waitFor(() => assertSame(errorsOf(store).password?.message, "Too short"));
|
|
2325
|
+
assertSame(store.getSnapshot().warnings.password?.message, "Weak");
|
|
2326
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
2291
2327
|
}
|
|
2292
2328
|
},
|
|
2293
2329
|
{
|
|
@@ -2308,10 +2344,10 @@ var cases = [
|
|
|
2308
2344
|
{ kind: "business", company: "" }
|
|
2309
2345
|
)
|
|
2310
2346
|
);
|
|
2311
|
-
|
|
2312
|
-
|
|
2347
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
2348
|
+
assertSame(store.getSnapshot().warnings.company?.type, "required");
|
|
2313
2349
|
store.setValue("kind", "person");
|
|
2314
|
-
|
|
2350
|
+
assertEqual(store.getSnapshot().warnings, {});
|
|
2315
2351
|
}
|
|
2316
2352
|
},
|
|
2317
2353
|
{
|
|
@@ -2319,8 +2355,8 @@ var cases = [
|
|
|
2319
2355
|
name: "an async rule reports the endpoint text on its own channel, never library text, and an outage is a failure to run and is not cached",
|
|
2320
2356
|
async run(createStore) {
|
|
2321
2357
|
let reply = () => new Response(JSON.stringify({ valid: false }));
|
|
2322
|
-
const fetchSpy =
|
|
2323
|
-
|
|
2358
|
+
const fetchSpy = createSpy(async () => reply());
|
|
2359
|
+
const restoreFetch = stubGlobal("fetch", fetchSpy);
|
|
2324
2360
|
try {
|
|
2325
2361
|
const options = custom(
|
|
2326
2362
|
[
|
|
@@ -2340,37 +2376,37 @@ var cases = [
|
|
|
2340
2376
|
{ handle: "ada" }
|
|
2341
2377
|
);
|
|
2342
2378
|
const store = createStore(options);
|
|
2343
|
-
|
|
2344
|
-
|
|
2379
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
2380
|
+
assertEqual(errorsOf(store).handle.all, [
|
|
2345
2381
|
{ type: "async", source: "validation", ruleId: "handle-free" }
|
|
2346
2382
|
]);
|
|
2347
2383
|
reply = () => new Response(JSON.stringify({ valid: false, message: "Handle is taken" }));
|
|
2348
2384
|
store.setValue("handle", "ada2");
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2385
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
2386
|
+
assertSame(errorsOf(store).handle.message, "Handle is taken");
|
|
2387
|
+
assertNotMatches(JSON.stringify(store.getSnapshot()), /Invalid input|secret|\/check/);
|
|
2352
2388
|
reply = () => new Response("no", { status: 503 });
|
|
2353
2389
|
store.setValue("handle", "ada3");
|
|
2354
2390
|
const down = await store.validate().then(
|
|
2355
2391
|
() => void 0,
|
|
2356
2392
|
(error) => error
|
|
2357
2393
|
);
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
const calls = fetchSpy.
|
|
2394
|
+
assertMatches(down, { name: "FormValidationFailure", path: "handle", ruleType: "async" });
|
|
2395
|
+
assertSame(down.cause.name, "ValidationUnavailable");
|
|
2396
|
+
const calls = fetchSpy.calls.length;
|
|
2361
2397
|
reply = () => new Response(JSON.stringify({ valid: true }));
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
fetchSpy.
|
|
2398
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
2399
|
+
assertSame(fetchSpy.calls.length, calls + 1);
|
|
2400
|
+
fetchSpy.implement(async () => {
|
|
2365
2401
|
throw new Error("offline");
|
|
2366
2402
|
});
|
|
2367
2403
|
const offline = await createStore({ ...options, defaults: { handle: "zed" } }).validate().then(
|
|
2368
2404
|
() => void 0,
|
|
2369
2405
|
(error) => error
|
|
2370
2406
|
);
|
|
2371
|
-
|
|
2407
|
+
assertSame(offline.cause.name, "ValidationUnavailable");
|
|
2372
2408
|
} finally {
|
|
2373
|
-
|
|
2409
|
+
restoreFetch();
|
|
2374
2410
|
}
|
|
2375
2411
|
}
|
|
2376
2412
|
},
|
|
@@ -2379,30 +2415,30 @@ var cases = [
|
|
|
2379
2415
|
name: "a submission ends passed, invalid, or overtaken",
|
|
2380
2416
|
async run(createStore) {
|
|
2381
2417
|
const store = createStore(fixture().options);
|
|
2382
|
-
|
|
2418
|
+
assertSame((await store.submit()).outcome, "passed");
|
|
2383
2419
|
store.setValue("name", "");
|
|
2384
|
-
|
|
2420
|
+
assertEqual(await store.submit(), { outcome: "invalid" });
|
|
2385
2421
|
const edit = fixture();
|
|
2386
2422
|
const edited = createStore(edit.options);
|
|
2387
2423
|
edit.gate.settle("taken", false);
|
|
2388
2424
|
edit.gate.hold("a", "b");
|
|
2389
2425
|
edited.setValue("slug", "a");
|
|
2390
2426
|
const outrun = edited.submit();
|
|
2391
|
-
await
|
|
2427
|
+
await waitFor(() => assertSame(edit.gate.pending("a"), 1));
|
|
2392
2428
|
edited.setValue("slug", "b");
|
|
2393
2429
|
edit.gate.settle("a", true);
|
|
2394
|
-
await
|
|
2430
|
+
await waitFor(() => assertSame(edit.gate.pending("b"), 1));
|
|
2395
2431
|
edited.setValue("slug", "taken");
|
|
2396
2432
|
edit.gate.settle("b", true);
|
|
2397
|
-
|
|
2433
|
+
assertEqual(await outrun, { outcome: "overtaken" });
|
|
2398
2434
|
const hold = fixture();
|
|
2399
2435
|
const reset = createStore(hold.options);
|
|
2400
2436
|
hold.gate.hold("free");
|
|
2401
2437
|
const cleared = reset.submit();
|
|
2402
|
-
await
|
|
2438
|
+
await waitFor(() => assertSame(hold.gate.pending("free"), 1));
|
|
2403
2439
|
reset.reset();
|
|
2404
2440
|
hold.gate.settle("free", true);
|
|
2405
|
-
|
|
2441
|
+
assertEqual(await cleared, { outcome: "overtaken" });
|
|
2406
2442
|
}
|
|
2407
2443
|
},
|
|
2408
2444
|
{
|
|
@@ -2411,13 +2447,14 @@ var cases = [
|
|
|
2411
2447
|
async run(createStore) {
|
|
2412
2448
|
const store = createStore(fixture().options);
|
|
2413
2449
|
const before = store.getSnapshot();
|
|
2414
|
-
|
|
2450
|
+
assertThrows(
|
|
2451
|
+
() => store.reportNative({ name: { type: "valueMissing" }, __x: { type: "valueMissing" } }),
|
|
2415
2452
|
/reserved/
|
|
2416
2453
|
);
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2454
|
+
assertThrows(() => store.reportNative({ "a.constructor": null }), /'constructor'/);
|
|
2455
|
+
assertSame(await store.checkValidity(), true);
|
|
2456
|
+
assertSame(store.getSnapshot(), before);
|
|
2457
|
+
assertThrows(() => store.setValue("prototype.x", 1), /__.*constructor.*prototype/s);
|
|
2421
2458
|
}
|
|
2422
2459
|
},
|
|
2423
2460
|
{
|
|
@@ -2426,18 +2463,24 @@ var cases = [
|
|
|
2426
2463
|
async run(createStore) {
|
|
2427
2464
|
const store = createStore(fixture({ validationMode: "onChange" }).options);
|
|
2428
2465
|
store.setValue("nickname", "");
|
|
2429
|
-
|
|
2466
|
+
assertSame(store.getSnapshot().validating.nickname, true);
|
|
2430
2467
|
store.reportNative({ nickname: { type: "valueMissing" } });
|
|
2431
|
-
await
|
|
2432
|
-
() =>
|
|
2468
|
+
await waitFor(
|
|
2469
|
+
() => assertEqual(
|
|
2470
|
+
errorsOf(store).nickname?.all.map(({ source }) => source),
|
|
2471
|
+
["validation", "native"]
|
|
2472
|
+
)
|
|
2433
2473
|
);
|
|
2434
|
-
|
|
2474
|
+
assertSame(isValidating(store), false);
|
|
2435
2475
|
const touched = createStore(fixture({ validationMode: "onTouched" }).options);
|
|
2436
2476
|
touched.blur("name");
|
|
2437
2477
|
touched.setValue("name", "");
|
|
2438
2478
|
touched.reportNative({ name: { type: "valueMissing" } });
|
|
2439
|
-
await
|
|
2440
|
-
() =>
|
|
2479
|
+
await waitFor(
|
|
2480
|
+
() => assertEqual(
|
|
2481
|
+
errorsOf(touched).name?.all.map(({ source }) => source),
|
|
2482
|
+
["validation", "native"]
|
|
2483
|
+
)
|
|
2441
2484
|
);
|
|
2442
2485
|
}
|
|
2443
2486
|
},
|
|
@@ -2448,17 +2491,17 @@ var cases = [
|
|
|
2448
2491
|
const store = createStore(fixture().options);
|
|
2449
2492
|
const first = store.submit();
|
|
2450
2493
|
const second = store.submit();
|
|
2451
|
-
|
|
2452
|
-
|
|
2494
|
+
assertEqual(await first, { outcome: "overtaken" });
|
|
2495
|
+
assertSame((await second).outcome, "passed");
|
|
2453
2496
|
}
|
|
2454
2497
|
},
|
|
2455
2498
|
{
|
|
2456
2499
|
rule: "validator failures",
|
|
2457
2500
|
name: "a failure says why a rule did not run: the service was unavailable, or the rule threw",
|
|
2458
2501
|
async run(createStore) {
|
|
2459
|
-
|
|
2502
|
+
const restoreFetch = stubGlobal(
|
|
2460
2503
|
"fetch",
|
|
2461
|
-
|
|
2504
|
+
createSpy(async () => new Response("no", { status: 500 }))
|
|
2462
2505
|
);
|
|
2463
2506
|
try {
|
|
2464
2507
|
const unavailable = createStore(
|
|
@@ -2477,7 +2520,7 @@ var cases = [
|
|
|
2477
2520
|
() => void 0,
|
|
2478
2521
|
(error) => error
|
|
2479
2522
|
);
|
|
2480
|
-
|
|
2523
|
+
assertMatches(down, { path: "handle", ruleType: "async", reason: "unavailable" });
|
|
2481
2524
|
const threw = createStore(
|
|
2482
2525
|
custom([{ $type: "input", name: "secret", rules: [{ $type: "boom" }] }], { secret: "" })
|
|
2483
2526
|
);
|
|
@@ -2485,9 +2528,9 @@ var cases = [
|
|
|
2485
2528
|
() => void 0,
|
|
2486
2529
|
(error) => error
|
|
2487
2530
|
);
|
|
2488
|
-
|
|
2531
|
+
assertMatches(exploded, { path: "secret", ruleType: "boom", reason: "error" });
|
|
2489
2532
|
} finally {
|
|
2490
|
-
|
|
2533
|
+
restoreFetch();
|
|
2491
2534
|
}
|
|
2492
2535
|
}
|
|
2493
2536
|
},
|
|
@@ -2531,19 +2574,19 @@ var cases = [
|
|
|
2531
2574
|
);
|
|
2532
2575
|
const store = createStore(options);
|
|
2533
2576
|
const submitted = await passedSubmission(store);
|
|
2534
|
-
|
|
2577
|
+
assertEqual(submitted.values, {
|
|
2535
2578
|
kind: "person",
|
|
2536
2579
|
rows: [{ role: "office" }, { role: "home", fax: "2" }],
|
|
2537
2580
|
tenant: "t1",
|
|
2538
2581
|
context: { source: "email" }
|
|
2539
2582
|
});
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2583
|
+
assertSame(Object.isFrozen(submitted.values), true);
|
|
2584
|
+
assertNoProperty(store.getSnapshot().values, "tenant");
|
|
2585
|
+
assertEqual(store.getSnapshot().dirty, {});
|
|
2543
2586
|
store.setValue("kind", "business");
|
|
2544
2587
|
const next = await passedSubmission(store);
|
|
2545
|
-
|
|
2546
|
-
|
|
2588
|
+
assertMatches(next.values, { company: "Acme", tenant: "t1" });
|
|
2589
|
+
assertNoProperty(next.values, "locked");
|
|
2547
2590
|
}
|
|
2548
2591
|
},
|
|
2549
2592
|
{
|
|
@@ -2551,19 +2594,19 @@ var cases = [
|
|
|
2551
2594
|
name: "blur marks the path touched in one notification and validates by mode; written first, the value ends as one command would leave it",
|
|
2552
2595
|
async run(createStore) {
|
|
2553
2596
|
const quiet = createStore(fixture().options);
|
|
2554
|
-
const listener =
|
|
2597
|
+
const listener = createSpy();
|
|
2555
2598
|
quiet.subscribe(listener);
|
|
2556
2599
|
quiet.blur("name");
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2600
|
+
assertCallCount(listener, 1);
|
|
2601
|
+
assertEqual(quiet.getSnapshot().touched, { name: true });
|
|
2602
|
+
assertSame(quiet.getValue("name"), "Ada");
|
|
2603
|
+
assertEqual(quiet.getSnapshot().dirty, {});
|
|
2561
2604
|
const store = createStore(fixture({ validationMode: "onBlur" }).options);
|
|
2562
2605
|
store.setValue("name", "");
|
|
2563
2606
|
store.blur("name");
|
|
2564
|
-
await
|
|
2565
|
-
|
|
2566
|
-
|
|
2607
|
+
await waitFor(() => assertSame(errorsOf(store).name?.type, "required"));
|
|
2608
|
+
assertSame(store.getSnapshot().dirty.name, true);
|
|
2609
|
+
assertSame(store.getSnapshot().touched.name, true);
|
|
2567
2610
|
}
|
|
2568
2611
|
},
|
|
2569
2612
|
{
|
|
@@ -2572,19 +2615,23 @@ var cases = [
|
|
|
2572
2615
|
run(createStore) {
|
|
2573
2616
|
const store = createStore(fixture().options);
|
|
2574
2617
|
const before = store.getSnapshot();
|
|
2575
|
-
|
|
2618
|
+
assertThrows(
|
|
2619
|
+
() => store.setValue("contacts.3.email", "x"),
|
|
2576
2620
|
/'contacts.3.email' names row '3' of 'contacts'/
|
|
2577
2621
|
);
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2622
|
+
assertThrows(() => store.setValue("contacts.-1.email", "x"), /names row '-1'/);
|
|
2623
|
+
assertThrows(() => store.blur("contacts.5.email"), /names row '5'/);
|
|
2624
|
+
assertThrows(() => store.setValue("name.3.x", "x"), /names row '3' of 'name'/);
|
|
2625
|
+
assertThrows(() => store.setValue("name.03.x", "x"), /names row '03' of 'name'/);
|
|
2626
|
+
assertThrows(() => store.setValue("__secret", 1), /reserved segment/);
|
|
2627
|
+
assertSame(store.getSnapshot(), before);
|
|
2584
2628
|
store.fieldArray("contacts").append({ email: "d@example.com" });
|
|
2585
2629
|
store.setValue("contacts.3.email", "e@example.com");
|
|
2586
|
-
|
|
2587
|
-
|
|
2630
|
+
assertLength(store.getSnapshot().rowIds.contacts, 4);
|
|
2631
|
+
assertSame(
|
|
2632
|
+
store.getSnapshot().rowIds.contacts.every((id) => typeof id === "string"),
|
|
2633
|
+
true
|
|
2634
|
+
);
|
|
2588
2635
|
}
|
|
2589
2636
|
},
|
|
2590
2637
|
{
|
|
@@ -2597,13 +2644,13 @@ var cases = [
|
|
|
2597
2644
|
store.setValue("name", "x");
|
|
2598
2645
|
store.setValue("name", "");
|
|
2599
2646
|
await settle();
|
|
2600
|
-
|
|
2647
|
+
assertSame(watch.started, false);
|
|
2601
2648
|
store.blur("name");
|
|
2602
|
-
await
|
|
2649
|
+
await waitFor(() => assertSame(errorsOf(store).name?.type, "required"));
|
|
2603
2650
|
store.setValue("name", "Ada");
|
|
2604
|
-
await
|
|
2651
|
+
await waitFor(() => assertUndefined(errorsOf(store).name));
|
|
2605
2652
|
store.setValue("name", "");
|
|
2606
|
-
await
|
|
2653
|
+
await waitFor(() => assertSame(errorsOf(store).name?.type, "required"));
|
|
2607
2654
|
}
|
|
2608
2655
|
},
|
|
2609
2656
|
{
|
|
@@ -2646,15 +2693,18 @@ var cases = [
|
|
|
2646
2693
|
{ tag: "abc", other: "z", count: 3, rows: [{ x: "" }] }
|
|
2647
2694
|
)
|
|
2648
2695
|
);
|
|
2649
|
-
|
|
2696
|
+
assertEqual(await store.validate(), { outcome: "invalid" });
|
|
2650
2697
|
const errors = errorsOf(store);
|
|
2651
|
-
|
|
2698
|
+
assertEqual(errors.tag.all, [
|
|
2652
2699
|
{ type: "maxLength", source: "validation", params: { maxLength: 2 } },
|
|
2653
2700
|
{ type: "relate", source: "validation", ruleId: "same", params: { assert: "allEqual" } }
|
|
2654
2701
|
]);
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2702
|
+
assertEqual(
|
|
2703
|
+
errors.count.all.map(({ params }) => params),
|
|
2704
|
+
[{ min: 5 }, { max: 1 }]
|
|
2705
|
+
);
|
|
2706
|
+
assertEqual(errors.rows.params, { minItems: 2 });
|
|
2707
|
+
assertNotMatches(JSON.stringify(errors), /Too (small|big)|Invalid input/);
|
|
2658
2708
|
}
|
|
2659
2709
|
},
|
|
2660
2710
|
{
|
|
@@ -2669,12 +2719,12 @@ var cases = [
|
|
|
2669
2719
|
"address.nowhere": { type: "valueMissing" },
|
|
2670
2720
|
"contacts.0.nothing": { type: "valueMissing" }
|
|
2671
2721
|
});
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2722
|
+
assertEqual(await store.validate(), { outcome: "passed" });
|
|
2723
|
+
assertSame(await store.checkValidity(), true);
|
|
2724
|
+
assertEqual(errorsOf(store), {});
|
|
2725
|
+
assertSame(store.getSnapshot().isValid, true);
|
|
2726
|
+
assertSame((await store.submit()).outcome, "passed");
|
|
2727
|
+
assertEqual(before.errors, {});
|
|
2678
2728
|
}
|
|
2679
2729
|
},
|
|
2680
2730
|
{
|
|
@@ -2690,8 +2740,8 @@ var cases = [
|
|
|
2690
2740
|
name: { type: "taken" },
|
|
2691
2741
|
"contacts.1": { type: "row_error" }
|
|
2692
2742
|
});
|
|
2693
|
-
|
|
2694
|
-
|
|
2743
|
+
assertEqual(Object.keys(errorsOf(store)).toSorted(), [FORM_ROOT, "contacts.1", "name"]);
|
|
2744
|
+
assertEqual(errorsOf(store)[FORM_ROOT].all, [
|
|
2695
2745
|
{ type: "server", source: "server", message: "Try later" },
|
|
2696
2746
|
{
|
|
2697
2747
|
type: "unknown_field",
|
|
@@ -2703,18 +2753,18 @@ var cases = [
|
|
|
2703
2753
|
]);
|
|
2704
2754
|
const alone = await passedSubmission(store);
|
|
2705
2755
|
alone.setServerErrors({ ghost: { type: "unknown_field" } });
|
|
2706
|
-
|
|
2707
|
-
|
|
2756
|
+
assertEqual(Object.keys(errorsOf(store)), [FORM_ROOT]);
|
|
2757
|
+
assertSame(errorsOf(store)[FORM_ROOT].type, "unknown_field");
|
|
2708
2758
|
}
|
|
2709
2759
|
}
|
|
2710
2760
|
];
|
|
2711
2761
|
var formStateContainerCases = cases;
|
|
2712
|
-
function formStateContainerConformance(createStore) {
|
|
2713
|
-
describe("form state container conformance", () => {
|
|
2762
|
+
function formStateContainerConformance(createStore, runner) {
|
|
2763
|
+
runner.describe("form state container conformance", () => {
|
|
2714
2764
|
for (const rule of new Set(cases.map((entry) => entry.rule))) {
|
|
2715
|
-
describe(rule, () => {
|
|
2765
|
+
runner.describe(rule, () => {
|
|
2716
2766
|
for (const entry of cases.filter((candidate) => candidate.rule === rule)) {
|
|
2717
|
-
test(entry.name, () => entry.run(createStore));
|
|
2767
|
+
runner.test(entry.name, () => entry.run(createStore));
|
|
2718
2768
|
}
|
|
2719
2769
|
});
|
|
2720
2770
|
}
|