Skip to content

Commit 93fb420

Browse files
committed
chore: remove half of the tests, too big a PR
1 parent 52618b2 commit 93fb420

File tree

2 files changed

+0
-286
lines changed

2 files changed

+0
-286
lines changed

src/tests/jsonLogic.test.js

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
multiRuleSchema,
77
schemaSelfContainedValueForMaximumMinimumValues,
88
schemaSelfContainedValueForTitleWithNoTemplate,
9-
schemaWhereValidationAndComputedValueIsAppliedOnNormalThenStatement,
109
schemaWithChecksAndThenValidationsOnThen,
1110
schemaWithComputedAttributeThatDoesntExist,
1211
schemaWithComputedAttributeThatDoesntExistDescription,
@@ -17,21 +16,18 @@ import {
1716
schemaWithDeepVarThatDoesNotExist,
1817
schemaWithDeepVarThatDoesNotExistOnFieldset,
1918
schemaWithGreaterThanChecksForThreeFields,
20-
schemaWithIfStatementWithComputedValuesAndValidationChecks,
2119
schemaWithInlineMultipleRulesForComputedAttributes,
2220
schemaWithInlineRuleForComputedAttributeWithCopy,
2321
schemaWithInlinedRuleOnComputedAttributeThatReferencesUnknownVar,
2422
schemaWithJSFLogicAndInlineRule,
2523
schemaWithMissingComputedValue,
2624
schemaWithMissingRule,
2725
schemaWithMissingValueInlineRule,
28-
schemaWithMultipleComputedValueChecks,
2926
schemaWithNativeAndJSONLogicChecks,
3027
schemaWithNonRequiredField,
3128
schemaWithPropertiesCheckAndValidationsInAIf,
3229
schemaWithPropertyThatDoesNotExistInThatLevelButDoesInFieldset,
3330
schemaWithTwoRules,
34-
schemaWithTwoValidationsWhereOneOfThemIsAppliedConditionally,
3531
schemaWithValidationThatDoesNotExistOnProperty,
3632
schemaWithVarThatDoesNotExist,
3733
} from './jsonLogicFixtures';
@@ -396,72 +392,6 @@ describe('cross-value validations', () => {
396392
undefined
397393
);
398394
});
399-
400-
it('Handle multiple computedValue checks by ANDing them together', () => {
401-
const { handleValidation } = createHeadlessForm(schemaWithMultipleComputedValueChecks, {
402-
strictInputType: false,
403-
});
404-
expect(handleValidation({}).formErrors).toEqual({
405-
field_a: 'Required field',
406-
field_b: 'Required field',
407-
});
408-
expect(handleValidation({ field_a: 10, field_b: 8 }).formErrors).toEqual({
409-
field_c: 'Required field',
410-
});
411-
expect(handleValidation({ field_a: 10, field_b: 8, field_c: 0 }).formErrors).toEqual({
412-
field_c: 'Must be two times B',
413-
});
414-
expect(handleValidation({ field_a: 10, field_b: 8, field_c: 17 }).formErrors).toEqual(
415-
undefined
416-
);
417-
});
418-
419-
it('Handle having a true condition with both validations and computedValue checks', () => {
420-
const { handleValidation } = createHeadlessForm(
421-
schemaWithIfStatementWithComputedValuesAndValidationChecks,
422-
{ strictInputType: false }
423-
);
424-
expect(handleValidation({ field_a: 1, field_b: 1 }).formErrors).toEqual(undefined);
425-
expect(handleValidation({ field_a: 10, field_b: 20 }).formErrors).toEqual(undefined);
426-
expect(handleValidation({ field_a: 10, field_b: 9 }).formErrors).toEqual({
427-
field_c: 'Required field',
428-
});
429-
expect(handleValidation({ field_a: 10, field_b: 9, field_c: 10 }).formErrors).toEqual(
430-
undefined
431-
);
432-
});
433-
434-
it('Apply validations and computed values on normal if statement.', () => {
435-
const { fields, handleValidation } = createHeadlessForm(
436-
schemaWhereValidationAndComputedValueIsAppliedOnNormalThenStatement,
437-
{ strictInputType: false }
438-
);
439-
expect(handleValidation({ field_a: 0, field_b: 0 }).formErrors).toEqual(undefined);
440-
expect(handleValidation({ field_a: 20, field_b: 0 }).formErrors).toEqual({
441-
field_b: 'Must be greater than Field A + 10',
442-
});
443-
const [, fieldB] = fields;
444-
expect(fieldB.label).toEqual('Must be greater than 30.');
445-
expect(handleValidation({ field_a: 20, field_b: 31 }).formErrors).toEqual(undefined);
446-
});
447-
448-
it('When we have a required validation on a top level property and another validation is added, both should be accounted for.', () => {
449-
const { handleValidation } = createHeadlessForm(
450-
schemaWithTwoValidationsWhereOneOfThemIsAppliedConditionally,
451-
{ strictInputType: false }
452-
);
453-
expect(handleValidation({ field_a: 10, field_b: 0 }).formErrors).toEqual({
454-
field_b: 'Must be greater than A',
455-
});
456-
expect(handleValidation({ field_a: 10, field_b: 20 }).formErrors).toEqual(undefined);
457-
expect(handleValidation({ field_a: 20, field_b: 10 }).formErrors).toEqual({
458-
field_b: 'Must be greater than A',
459-
});
460-
expect(handleValidation({ field_a: 20, field_b: 21 }).formErrors).toEqual({
461-
field_b: 'Must be greater than two times A',
462-
});
463-
expect(handleValidation({ field_a: 20, field_b: 41 }).formErrors).toEqual();
464-
});
465395
});
466396

467397
describe('Multiple validations', () => {

src/tests/jsonLogicFixtures.js

Lines changed: 0 additions & 216 deletions
Original file line numberDiff line numberDiff line change
@@ -451,222 +451,6 @@ export const schemaWithComputedValueChecksInIf = {
451451
},
452452
};
453453

454-
export const schemaWithMultipleComputedValueChecks = {
455-
properties: {
456-
field_a: {
457-
type: 'number',
458-
},
459-
field_b: {
460-
type: 'number',
461-
},
462-
field_c: {
463-
type: 'number',
464-
},
465-
},
466-
required: ['field_a', 'field_b'],
467-
'x-jsf-logic': {
468-
validations: {
469-
double_b: {
470-
errorMessage: 'Must be two times B',
471-
rule: {
472-
'>': [{ var: 'field_c' }, { '*': [{ var: 'field_b' }, 2] }],
473-
},
474-
},
475-
},
476-
computedValues: {
477-
a_times_two: {
478-
rule: {
479-
'*': [{ var: 'field_a' }, 2],
480-
},
481-
},
482-
mod_by_five: {
483-
rule: {
484-
'%': [{ var: 'field_b' }, 5],
485-
},
486-
},
487-
},
488-
allOf: [
489-
{
490-
if: {
491-
computedValues: {
492-
a_times_two: {
493-
const: 20,
494-
},
495-
mod_by_five: {
496-
const: 3,
497-
},
498-
},
499-
},
500-
then: {
501-
required: ['field_c'],
502-
properties: {
503-
field_c: {
504-
'x-jsf-logic-validations': ['double_b'],
505-
title: 'Adding a title.',
506-
},
507-
},
508-
},
509-
else: {
510-
properties: {
511-
field_c: false,
512-
},
513-
},
514-
},
515-
],
516-
},
517-
};
518-
519-
export const schemaWithIfStatementWithComputedValuesAndValidationChecks = {
520-
properties: {
521-
field_a: {
522-
type: 'number',
523-
},
524-
field_b: {
525-
type: 'number',
526-
},
527-
field_c: {
528-
type: 'number',
529-
},
530-
},
531-
required: ['field_a', 'field_b'],
532-
'x-jsf-logic': {
533-
validations: {
534-
greater_than_b: {
535-
rule: {
536-
'>': [{ var: 'field_a' }, { var: 'field_b' }],
537-
},
538-
},
539-
},
540-
computedValues: {
541-
a_times_two: {
542-
rule: {
543-
'*': [{ var: 'field_a' }, 2],
544-
},
545-
},
546-
},
547-
allOf: [
548-
{
549-
if: {
550-
computedValues: {
551-
a_times_two: {
552-
const: 20,
553-
},
554-
},
555-
validations: {
556-
greater_than_b: {
557-
const: true,
558-
},
559-
},
560-
},
561-
then: {
562-
required: ['field_c'],
563-
},
564-
else: {
565-
properties: {
566-
field_c: false,
567-
},
568-
},
569-
},
570-
],
571-
},
572-
};
573-
574-
export const schemaWhereValidationAndComputedValueIsAppliedOnNormalThenStatement = {
575-
properties: {
576-
field_a: {
577-
type: 'number',
578-
},
579-
field_b: {
580-
type: 'number',
581-
},
582-
},
583-
'x-jsf-logic': {
584-
computedValues: {
585-
a_plus_ten: {
586-
rule: {
587-
'+': [{ var: 'field_a' }, 10],
588-
},
589-
},
590-
},
591-
validations: {
592-
greater_than_a_plus_ten: {
593-
errorMessage: 'Must be greater than Field A + 10',
594-
rule: {
595-
'>': [{ var: 'field_b' }, { '+': [{ var: 'field_a' }, 10] }],
596-
},
597-
},
598-
},
599-
},
600-
allOf: [
601-
{
602-
if: {
603-
properties: {
604-
field_a: {
605-
const: 20,
606-
},
607-
},
608-
},
609-
then: {
610-
properties: {
611-
field_b: {
612-
'x-jsf-logic-computedAttrs': {
613-
title: 'Must be greater than {{a_plus_ten}}.',
614-
},
615-
'x-jsf-logic-validations': ['greater_than_a_plus_ten'],
616-
},
617-
},
618-
},
619-
},
620-
],
621-
};
622-
623-
export const schemaWithTwoValidationsWhereOneOfThemIsAppliedConditionally = {
624-
required: ['field_a', 'field_b'],
625-
properties: {
626-
field_a: {
627-
type: 'number',
628-
},
629-
field_b: {
630-
type: 'number',
631-
'x-jsf-logic-validations': ['greater_than_field_a'],
632-
},
633-
},
634-
'x-jsf-logic': {
635-
validations: {
636-
greater_than_field_a: {
637-
errorMessage: 'Must be greater than A',
638-
rule: {
639-
'>': [{ var: 'field_b' }, { var: 'field_a' }],
640-
},
641-
},
642-
greater_than_two_times_a: {
643-
errorMessage: 'Must be greater than two times A',
644-
rule: {
645-
'>': [{ var: 'field_b' }, { '*': [{ var: 'field_a' }, 2] }],
646-
},
647-
},
648-
},
649-
},
650-
allOf: [
651-
{
652-
if: {
653-
properties: {
654-
field_a: {
655-
const: 20,
656-
},
657-
},
658-
},
659-
then: {
660-
properties: {
661-
field_b: {
662-
'x-jsf-logic-validations': ['greater_than_two_times_a'],
663-
},
664-
},
665-
},
666-
},
667-
],
668-
};
669-
670454
export const multiRuleSchema = {
671455
properties: {
672456
field_a: {

0 commit comments

Comments
 (0)