@@ -262,8 +262,14 @@ describe('getFieldsFromSchema', function () {
262262 } ,
263263 } ) ;
264264 expect ( result ) . to . deep . equal ( [
265- { name : 'name' , type : 'string' , depth : 0 , glyphs : [ ] } ,
266- { name : 'age' , type : 'int' , depth : 0 , glyphs : [ ] } ,
265+ {
266+ name : 'name' ,
267+ type : 'string' ,
268+ depth : 0 ,
269+ glyphs : [ ] ,
270+ variant : undefined ,
271+ } ,
272+ { name : 'age' , type : 'int' , depth : 0 , glyphs : [ ] , variant : undefined } ,
267273 ] ) ;
268274 } ) ;
269275
@@ -274,9 +280,45 @@ describe('getFieldsFromSchema', function () {
274280 age : { bsonType : [ 'int' , 'string' ] } ,
275281 } ,
276282 } ) ;
277- expect ( result [ 0 ] ) . to . deep . include ( { name : 'age' , depth : 0 , glyphs : [ ] } ) ;
283+ expect ( result [ 0 ] ) . to . deep . include ( {
284+ name : 'age' ,
285+ depth : 0 ,
286+ glyphs : [ ] ,
287+ variant : undefined ,
288+ } ) ;
278289 await validateMixedType ( result [ 0 ] . type , / i n t , s t r i n g / ) ;
279290 } ) ;
291+
292+ it ( 'highlights the correct field' , function ( ) {
293+ const result = getFieldsFromSchema (
294+ {
295+ bsonType : 'object' ,
296+ properties : {
297+ name : { bsonType : 'string' } ,
298+ age : { bsonType : 'int' } ,
299+ profession : { bsonType : 'string' } ,
300+ } ,
301+ } ,
302+ [ 'age' ]
303+ ) ;
304+ expect ( result ) . to . deep . equal ( [
305+ {
306+ name : 'name' ,
307+ type : 'string' ,
308+ depth : 0 ,
309+ glyphs : [ ] ,
310+ variant : undefined ,
311+ } ,
312+ { name : 'age' , type : 'int' , depth : 0 , glyphs : [ ] , variant : 'preview' } ,
313+ {
314+ name : 'profession' ,
315+ type : 'string' ,
316+ depth : 0 ,
317+ glyphs : [ ] ,
318+ variant : undefined ,
319+ } ,
320+ ] ) ;
321+ } ) ;
280322 } ) ;
281323
282324 describe ( 'nested schema' , function ( ) {
@@ -300,11 +342,102 @@ describe('getFieldsFromSchema', function () {
300342 } ,
301343 } ) ;
302344 expect ( result ) . to . deep . equal ( [
303- { name : 'person' , type : 'object' , depth : 0 , glyphs : [ ] } ,
304- { name : 'name' , type : 'string' , depth : 1 , glyphs : [ ] } ,
305- { name : 'address' , type : 'object' , depth : 1 , glyphs : [ ] } ,
306- { name : 'street' , type : 'string' , depth : 2 , glyphs : [ ] } ,
307- { name : 'city' , type : 'string' , depth : 2 , glyphs : [ ] } ,
345+ {
346+ name : 'person' ,
347+ type : 'object' ,
348+ depth : 0 ,
349+ glyphs : [ ] ,
350+ variant : undefined ,
351+ } ,
352+ {
353+ name : 'name' ,
354+ type : 'string' ,
355+ depth : 1 ,
356+ glyphs : [ ] ,
357+ variant : undefined ,
358+ } ,
359+ {
360+ name : 'address' ,
361+ type : 'object' ,
362+ depth : 1 ,
363+ glyphs : [ ] ,
364+ variant : undefined ,
365+ } ,
366+ {
367+ name : 'street' ,
368+ type : 'string' ,
369+ depth : 2 ,
370+ glyphs : [ ] ,
371+ variant : undefined ,
372+ } ,
373+ {
374+ name : 'city' ,
375+ type : 'string' ,
376+ depth : 2 ,
377+ glyphs : [ ] ,
378+ variant : undefined ,
379+ } ,
380+ ] ) ;
381+ } ) ;
382+
383+ it ( 'highlights a field for a nested schema' , function ( ) {
384+ const result = getFieldsFromSchema (
385+ {
386+ bsonType : 'object' ,
387+ properties : {
388+ person : {
389+ bsonType : 'object' ,
390+ properties : {
391+ name : { bsonType : 'string' } ,
392+ address : {
393+ bsonType : 'object' ,
394+ properties : {
395+ street : { bsonType : 'string' } ,
396+ city : { bsonType : 'string' } ,
397+ } ,
398+ } ,
399+ } ,
400+ } ,
401+ } ,
402+ } ,
403+ [ 'person' , 'address' , 'street' ]
404+ ) ;
405+ expect ( result ) . to . deep . equal ( [
406+ {
407+ name : 'person' ,
408+ type : 'object' ,
409+ depth : 0 ,
410+ glyphs : [ ] ,
411+ variant : undefined ,
412+ } ,
413+ {
414+ name : 'name' ,
415+ type : 'string' ,
416+ depth : 1 ,
417+ glyphs : [ ] ,
418+ variant : undefined ,
419+ } ,
420+ {
421+ name : 'address' ,
422+ type : 'object' ,
423+ depth : 1 ,
424+ glyphs : [ ] ,
425+ variant : undefined ,
426+ } ,
427+ {
428+ name : 'street' ,
429+ type : 'string' ,
430+ depth : 2 ,
431+ glyphs : [ ] ,
432+ variant : 'preview' ,
433+ } ,
434+ {
435+ name : 'city' ,
436+ type : 'string' ,
437+ depth : 2 ,
438+ glyphs : [ ] ,
439+ variant : undefined ,
440+ } ,
308441 ] ) ;
309442 } ) ;
310443
@@ -319,7 +452,7 @@ describe('getFieldsFromSchema', function () {
319452 } ,
320453 } ) ;
321454 expect ( result ) . to . deep . equal ( [
322- { name : 'tags' , type : '[]' , depth : 0 , glyphs : [ ] } ,
455+ { name : 'tags' , type : '[]' , depth : 0 , glyphs : [ ] , variant : undefined } ,
323456 ] ) ;
324457 } ) ;
325458
@@ -340,9 +473,21 @@ describe('getFieldsFromSchema', function () {
340473 } ,
341474 } ) ;
342475 expect ( result ) . to . deep . equal ( [
343- { name : 'todos' , type : '[]' , depth : 0 , glyphs : [ ] } ,
344- { name : 'title' , type : 'string' , depth : 1 , glyphs : [ ] } ,
345- { name : 'completed' , type : 'boolean' , depth : 1 , glyphs : [ ] } ,
476+ { name : 'todos' , type : '[]' , depth : 0 , glyphs : [ ] , variant : undefined } ,
477+ {
478+ name : 'title' ,
479+ type : 'string' ,
480+ depth : 1 ,
481+ glyphs : [ ] ,
482+ variant : undefined ,
483+ } ,
484+ {
485+ name : 'completed' ,
486+ type : 'boolean' ,
487+ depth : 1 ,
488+ glyphs : [ ] ,
489+ variant : undefined ,
490+ } ,
346491 ] ) ;
347492 } ) ;
348493
@@ -365,19 +510,26 @@ describe('getFieldsFromSchema', function () {
365510 } ,
366511 } ) ;
367512 expect ( result ) . to . have . lengthOf ( 3 ) ;
368- expect ( result [ 0 ] ) . to . deep . include ( { name : 'name' , depth : 0 , glyphs : [ ] } ) ;
513+ expect ( result [ 0 ] ) . to . deep . include ( {
514+ name : 'name' ,
515+ depth : 0 ,
516+ glyphs : [ ] ,
517+ variant : undefined ,
518+ } ) ;
369519 await validateMixedType ( result [ 0 ] . type , / s t r i n g , o b j e c t / ) ;
370520 expect ( result [ 1 ] ) . to . deep . equal ( {
371521 name : 'first' ,
372522 type : 'string' ,
373523 depth : 1 ,
374524 glyphs : [ ] ,
525+ variant : undefined ,
375526 } ) ;
376527 expect ( result [ 2 ] ) . to . deep . equal ( {
377528 name : 'last' ,
378529 type : 'string' ,
379530 depth : 1 ,
380531 glyphs : [ ] ,
532+ variant : undefined ,
381533 } ) ;
382534 } ) ;
383535
@@ -403,9 +555,21 @@ describe('getFieldsFromSchema', function () {
403555 } ,
404556 } ) ;
405557 expect ( result ) . to . deep . equal ( [
406- { name : 'todos' , type : '[]' , depth : 0 , glyphs : [ ] } ,
407- { name : 'title' , type : 'string' , depth : 1 , glyphs : [ ] } ,
408- { name : 'completed' , type : 'boolean' , depth : 1 , glyphs : [ ] } ,
558+ { name : 'todos' , type : '[]' , depth : 0 , glyphs : [ ] , variant : undefined } ,
559+ {
560+ name : 'title' ,
561+ type : 'string' ,
562+ depth : 1 ,
563+ glyphs : [ ] ,
564+ variant : undefined ,
565+ } ,
566+ {
567+ name : 'completed' ,
568+ type : 'boolean' ,
569+ depth : 1 ,
570+ glyphs : [ ] ,
571+ variant : undefined ,
572+ } ,
409573 ] ) ;
410574 } ) ;
411575 } ) ;
0 commit comments