@@ -45,11 +45,11 @@ export default function getClosestMatchingOptionTest(testValidator: TestValidato
4545 it ( 'returns 0 when formData is empty object' , ( ) => {
4646 expect ( calculateIndexScore ( testValidator , oneOfSchema , firstOption , { } ) ) . toEqual ( 0 ) ;
4747 } ) ;
48- it ( 'returns 1 for first option in oneOf schema' , ( ) => {
49- expect ( calculateIndexScore ( testValidator , oneOfSchema , firstOption , ONE_OF_SCHEMA_DATA ) ) . toEqual ( 1 ) ;
48+ it ( 'returns 2 for first option in oneOf schema' , ( ) => {
49+ expect ( calculateIndexScore ( testValidator , oneOfSchema , firstOption , ONE_OF_SCHEMA_DATA ) ) . toEqual ( 2 ) ;
5050 } ) ;
51- it ( 'returns 8 for second option in oneOf schema' , ( ) => {
52- expect ( calculateIndexScore ( testValidator , oneOfSchema , secondOption , ONE_OF_SCHEMA_DATA ) ) . toEqual ( 9 ) ;
51+ it ( 'returns 10 for second option in oneOf schema' , ( ) => {
52+ expect ( calculateIndexScore ( testValidator , oneOfSchema , secondOption , ONE_OF_SCHEMA_DATA ) ) . toEqual ( 10 ) ;
5353 } ) ;
5454 it ( 'returns 1 for a schema that has a type matching the formData type' , ( ) => {
5555 expect ( calculateIndexScore ( testValidator , oneOfSchema , { type : 'boolean' } , true ) ) . toEqual ( 1 ) ;
@@ -161,9 +161,10 @@ export default function getClosestMatchingOptionTest(testValidator: TestValidato
161161 } ,
162162 } ;
163163 const formData = { ipsum : { night : 'nicht' } } ;
164- // Mock to return true for the last of the second one-ofs
164+ // Mock: first 3 calls (JUNK for lorem, lorem itself, JUNK for ipsum) fail;
165+ // 4th call (ipsum with oneOf stripped to {}) succeeds, giving a unique valid match
165166 testValidator . setReturnValues ( {
166- isValid : [ false , false , false , false , false , false , false , true ] ,
167+ isValid : [ false , false , false , true ] ,
167168 } ) ;
168169 expect ( getClosestMatchingOption ( testValidator , schema , formData , get ( schema , 'items.oneOf' ) ) ) . toEqual ( 1 ) ;
169170 } ) ;
@@ -207,9 +208,10 @@ export default function getClosestMatchingOptionTest(testValidator: TestValidato
207208 } ,
208209 } ;
209210 const formData = { ipsum : { night : 'nicht' } } ;
210- // Mock to return true for the last of the second anyOfs
211+ // Mock: first 3 calls (JUNK for lorem, lorem itself, JUNK for ipsum) fail;
212+ // 4th call (ipsum with anyOf stripped to {}) succeeds, giving a unique valid match
211213 testValidator . setReturnValues ( {
212- isValid : [ false , false , false , false , false , false , false , true ] ,
214+ isValid : [ false , false , false , true ] ,
213215 } ) ;
214216 expect ( getClosestMatchingOption ( testValidator , schema , formData , get ( schema , 'items.anyOf' ) ) ) . toEqual ( 1 ) ;
215217 } ) ;
0 commit comments