@@ -1229,6 +1229,103 @@ describe("Form", () => {
12291229 expect ( errors ) . eql ( [ "should NOT be shorter than 4 characters" ] ) ;
12301230 } ) ;
12311231 } ) ;
1232+
1233+ describe ( "schema dependencies" , ( ) => {
1234+ const schema = {
1235+ type : "object" ,
1236+ properties : {
1237+ branch : {
1238+ type : "number" ,
1239+ enum : [ 1 , 2 , 3 ] ,
1240+ default : 1 ,
1241+ } ,
1242+ } ,
1243+ required : [ "branch" ] ,
1244+ dependencies : {
1245+ branch : {
1246+ oneOf : [
1247+ {
1248+ properties : {
1249+ branch : {
1250+ enum : [ 1 ] ,
1251+ } ,
1252+ field1 : {
1253+ type : "number" ,
1254+ } ,
1255+ } ,
1256+ required : [ "field1" ] ,
1257+ } ,
1258+ {
1259+ properties : {
1260+ branch : {
1261+ enum : [ 2 ] ,
1262+ } ,
1263+ field1 : {
1264+ type : "number" ,
1265+ } ,
1266+ field2 : {
1267+ type : "number" ,
1268+ } ,
1269+ } ,
1270+ required : [ "field1" , "field2" ] ,
1271+ } ,
1272+ ] ,
1273+ } ,
1274+ } ,
1275+ } ;
1276+
1277+ it ( "should only show error for property in selected branch" , ( ) => {
1278+ const { comp, node } = createFormComponent ( {
1279+ schema,
1280+ liveValidate : true ,
1281+ } ) ;
1282+
1283+ Simulate . change ( node . querySelector ( "input[type=text]" ) , {
1284+ target : { value : "not a number" } ,
1285+ } ) ;
1286+
1287+ expect ( comp . state . errorSchema ) . eql ( {
1288+ field1 : {
1289+ __errors : [ "should be number" ] ,
1290+ } ,
1291+ } ) ;
1292+ } ) ;
1293+
1294+ it ( "should only show errors for properties in selected branch" , ( ) => {
1295+ const { comp, node } = createFormComponent ( {
1296+ schema,
1297+ liveValidate : true ,
1298+ formData : { branch : 2 } ,
1299+ } ) ;
1300+
1301+ Simulate . change ( node . querySelector ( "input[type=text]" ) , {
1302+ target : { value : "not a number" } ,
1303+ } ) ;
1304+
1305+ expect ( comp . state . errorSchema ) . eql ( {
1306+ field1 : {
1307+ __errors : [ "should be number" ] ,
1308+ } ,
1309+ field2 : {
1310+ __errors : [ "is a required property" ] ,
1311+ } ,
1312+ } ) ;
1313+ } ) ;
1314+
1315+ it ( "should not show any errors when branch is empty" , ( ) => {
1316+ const { comp, node } = createFormComponent ( {
1317+ schema,
1318+ liveValidate : true ,
1319+ formData : { branch : 3 } ,
1320+ } ) ;
1321+
1322+ Simulate . change ( node . querySelector ( "select" ) , {
1323+ target : { value : 3 } ,
1324+ } ) ;
1325+
1326+ expect ( comp . state . errorSchema ) . eql ( { } ) ;
1327+ } ) ;
1328+ } ) ;
12321329 } ) ;
12331330
12341331 describe ( "Schema and formData updates" , ( ) => {
0 commit comments