1- import React from 'react' ;
21import { expect } from 'chai' ;
3- import {
4- screen ,
5- waitFor ,
6- render ,
7- userEvent ,
8- } from '@mongodb-js/testing-library-compass' ;
92import { getFieldsFromSchema } from './nodes-and-edges' ;
103
114describe ( 'getFieldsFromSchema' , function ( ) {
12- const validateMixedType = async (
13- type : React . ReactNode ,
14- expectedTooltip : RegExp
15- ) => {
16- render ( < > { type } </ > ) ;
17- const mixed = screen . getByText ( '(mixed)' ) ;
18- expect ( mixed ) . to . be . visible ;
19- expect ( screen . queryByText ( expectedTooltip ) ) . to . not . exist ;
20- userEvent . hover ( mixed ) ;
21- await waitFor ( ( ) => {
22- expect ( screen . getByText ( expectedTooltip ) ) . to . be . visible ;
23- } ) ;
24- } ;
25-
265 describe ( 'flat schema' , function ( ) {
276 it ( 'return empty array for empty schema' , function ( ) {
287 const result = getFieldsFromSchema ( { jsonSchema : { } } ) ;
@@ -63,7 +42,7 @@ describe('getFieldsFromSchema', function () {
6342 ] ) ;
6443 } ) ;
6544
66- it ( 'returns mixed fields with tooltip on hover' , async function ( ) {
45+ it ( 'returns mixed fields' , function ( ) {
6746 const result = getFieldsFromSchema ( {
6847 jsonSchema : {
6948 bsonType : 'object' ,
@@ -72,16 +51,16 @@ describe('getFieldsFromSchema', function () {
7251 } ,
7352 } ,
7453 } ) ;
75- expect ( result [ 0 ] ) . to . deep . include ( {
54+ expect ( result [ 0 ] ) . to . deep . equal ( {
7655 name : 'age' ,
7756 id : [ 'age' ] ,
7857 depth : 0 ,
7958 glyphs : [ ] ,
8059 selectable : true ,
8160 selected : false ,
61+ type : [ 'int' , 'string' ] ,
8262 variant : undefined ,
8363 } ) ;
84- await validateMixedType ( result [ 0 ] . type , / i n t , s t r i n g / ) ;
8564 } ) ;
8665
8766 it ( 'highlights the correct field' , function ( ) {
@@ -445,32 +424,6 @@ describe('getFieldsFromSchema', function () {
445424 ] ) ;
446425 } ) ;
447426
448- it ( 'returns [] for array' , function ( ) {
449- const result = getFieldsFromSchema ( {
450- jsonSchema : {
451- bsonType : 'object' ,
452- properties : {
453- tags : {
454- bsonType : 'array' ,
455- items : { bsonType : 'string' } ,
456- } ,
457- } ,
458- } ,
459- } ) ;
460- expect ( result ) . to . deep . equal ( [
461- {
462- name : 'tags' ,
463- id : [ 'tags' ] ,
464- type : '[]' ,
465- depth : 0 ,
466- glyphs : [ ] ,
467- selectable : true ,
468- selected : false ,
469- variant : undefined ,
470- } ,
471- ] ) ;
472- } ) ;
473-
474427 it ( 'returns fields for an array of objects' , function ( ) {
475428 const result = getFieldsFromSchema ( {
476429 jsonSchema : {
@@ -493,7 +446,7 @@ describe('getFieldsFromSchema', function () {
493446 {
494447 name : 'todos' ,
495448 id : [ 'todos' ] ,
496- type : '[] ' ,
449+ type : 'array ' ,
497450 depth : 0 ,
498451 glyphs : [ ] ,
499452 selectable : true ,
@@ -523,7 +476,7 @@ describe('getFieldsFromSchema', function () {
523476 ] ) ;
524477 } ) ;
525478
526- it ( 'returns fields for a mixed schema with objects' , async function ( ) {
479+ it ( 'returns fields for a mixed schema with objects' , function ( ) {
527480 const result = getFieldsFromSchema ( {
528481 jsonSchema : {
529482 bsonType : 'object' ,
@@ -544,16 +497,16 @@ describe('getFieldsFromSchema', function () {
544497 } ,
545498 } ) ;
546499 expect ( result ) . to . have . lengthOf ( 3 ) ;
547- expect ( result [ 0 ] ) . to . deep . include ( {
500+ expect ( result [ 0 ] ) . to . deep . equal ( {
548501 name : 'name' ,
549502 id : [ 'name' ] ,
550503 depth : 0 ,
504+ type : [ 'string' , 'object' ] ,
551505 glyphs : [ ] ,
552506 selectable : true ,
553507 selected : false ,
554508 variant : undefined ,
555509 } ) ;
556- await validateMixedType ( result [ 0 ] . type , / s t r i n g , o b j e c t / ) ;
557510 expect ( result [ 1 ] ) . to . deep . equal ( {
558511 name : 'first' ,
559512 id : [ 'name' , 'first' ] ,
@@ -603,7 +556,7 @@ describe('getFieldsFromSchema', function () {
603556 {
604557 name : 'todos' ,
605558 id : [ 'todos' ] ,
606- type : '[] ' ,
559+ type : 'array ' ,
607560 depth : 0 ,
608561 glyphs : [ ] ,
609562 selectable : true ,
0 commit comments