@@ -676,8 +676,77 @@ describe("Validation", () => {
676
676
} ) ;
677
677
} ) ;
678
678
describe ( "Custom meta schema" , ( ) => {
679
+ let sandboxErr ;
680
+ let onSubmit ;
681
+ let onError ;
682
+ let compWithMeta , nodeWithMeta , compWithoutMeta , nodeWithoutMeta ;
683
+
684
+ beforeEach ( ( ) => {
685
+ sandboxErr = sinon . sandbox . create ( ) ;
686
+ onSubmit = sandboxErr . spy ( ) ;
687
+ onError = sandboxErr . spy ( ) ;
688
+ const withMetaSchema = createFormComponent ( {
689
+ schema,
690
+ formData,
691
+ metaSchema : require ( "ajv/lib/refs/json-schema-draft-04.json" ) ,
692
+ onSubmit,
693
+ onError,
694
+ } ) ;
695
+
696
+ compWithMeta = withMetaSchema . comp ;
697
+ nodeWithMeta = withMetaSchema . node ;
698
+ const withoutMetaSchema = createFormComponent ( {
699
+ schema,
700
+ formData,
701
+ onSubmit,
702
+ onError,
703
+ } ) ;
704
+ compWithoutMeta = withoutMetaSchema . comp ;
705
+ nodeWithoutMeta = withoutMetaSchema . node ;
706
+ } ) ;
707
+
708
+ afterEach ( ( ) => {
709
+ sandboxErr . restore ( ) ;
710
+ } ) ;
711
+
712
+ const schema = {
713
+ $ref : "#/definitions/Dataset" ,
714
+ $schema : "http://json-schema.org/draft-04/schema#" ,
715
+ definitions : {
716
+ Dataset : {
717
+ properties : {
718
+ datasetId : {
719
+ pattern : "\\d+" ,
720
+ type : "string" ,
721
+ } ,
722
+ } ,
723
+ required : [ "datasetId" ] ,
724
+ type : "object" ,
725
+ } ,
726
+ } ,
727
+ } ;
728
+ const formData = {
729
+ datasetId : "no err" ,
730
+ } ;
731
+
679
732
it . only ( "asd" , ( ) => {
680
- expect ( true ) . to . eql ( true ) ;
733
+ Simulate . submit ( nodeWithoutMeta ) ;
734
+ expect (
735
+ nodeWithoutMeta . querySelectorAll ( ".errors li" )
736
+ ) . to . have . length . of ( 0 ) ;
737
+ expect ( compWithoutMeta . state . errors ) . to . have . lengthOf ( 0 ) ;
738
+ } ) ;
739
+ it . only ( "query select" , ( ) => {
740
+ Simulate . submit ( nodeWithMeta ) ;
741
+ expect ( nodeWithMeta . querySelectorAll ( ".errors li" ) ) . to . have . length . of (
742
+ 1
743
+ ) ;
744
+ expect ( compWithMeta . state . errors [ 0 ] . message ) . eql (
745
+ `should match pattern "\\d+"`
746
+ ) ;
747
+ } ) ;
748
+ it . only ( "dff" , ( ) => {
749
+ // expect(compWithoutMeta.state.errors).to.have.length.of(0);
681
750
} ) ;
682
751
} ) ;
683
752
} ) ;
0 commit comments