1
- import React from 'react' ;
2
1
import { expect } from 'chai' ;
3
- import {
4
- screen ,
5
- waitFor ,
6
- render ,
7
- userEvent ,
8
- } from '@mongodb-js/testing-library-compass' ;
9
2
import { getFieldsFromSchema } from './nodes-and-edges' ;
10
3
11
4
describe ( '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
-
26
5
describe ( 'flat schema' , function ( ) {
27
6
it ( 'return empty array for empty schema' , function ( ) {
28
7
const result = getFieldsFromSchema ( { jsonSchema : { } } ) ;
@@ -63,7 +42,7 @@ describe('getFieldsFromSchema', function () {
63
42
] ) ;
64
43
} ) ;
65
44
66
- it ( 'returns mixed fields with tooltip on hover' , async function ( ) {
45
+ it ( 'returns mixed fields' , function ( ) {
67
46
const result = getFieldsFromSchema ( {
68
47
jsonSchema : {
69
48
bsonType : 'object' ,
@@ -72,16 +51,16 @@ describe('getFieldsFromSchema', function () {
72
51
} ,
73
52
} ,
74
53
} ) ;
75
- expect ( result [ 0 ] ) . to . deep . include ( {
54
+ expect ( result [ 0 ] ) . to . deep . equal ( {
76
55
name : 'age' ,
77
56
id : [ 'age' ] ,
78
57
depth : 0 ,
79
58
glyphs : [ ] ,
80
59
selectable : true ,
81
60
selected : false ,
61
+ type : [ 'int' , 'string' ] ,
82
62
variant : undefined ,
83
63
} ) ;
84
- await validateMixedType ( result [ 0 ] . type , / i n t , s t r i n g / ) ;
85
64
} ) ;
86
65
87
66
it ( 'highlights the correct field' , function ( ) {
@@ -445,32 +424,6 @@ describe('getFieldsFromSchema', function () {
445
424
] ) ;
446
425
} ) ;
447
426
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
-
474
427
it ( 'returns fields for an array of objects' , function ( ) {
475
428
const result = getFieldsFromSchema ( {
476
429
jsonSchema : {
@@ -493,7 +446,7 @@ describe('getFieldsFromSchema', function () {
493
446
{
494
447
name : 'todos' ,
495
448
id : [ 'todos' ] ,
496
- type : '[] ' ,
449
+ type : 'array ' ,
497
450
depth : 0 ,
498
451
glyphs : [ ] ,
499
452
selectable : true ,
@@ -523,7 +476,7 @@ describe('getFieldsFromSchema', function () {
523
476
] ) ;
524
477
} ) ;
525
478
526
- it ( 'returns fields for a mixed schema with objects' , async function ( ) {
479
+ it ( 'returns fields for a mixed schema with objects' , function ( ) {
527
480
const result = getFieldsFromSchema ( {
528
481
jsonSchema : {
529
482
bsonType : 'object' ,
@@ -544,16 +497,16 @@ describe('getFieldsFromSchema', function () {
544
497
} ,
545
498
} ) ;
546
499
expect ( result ) . to . have . lengthOf ( 3 ) ;
547
- expect ( result [ 0 ] ) . to . deep . include ( {
500
+ expect ( result [ 0 ] ) . to . deep . equal ( {
548
501
name : 'name' ,
549
502
id : [ 'name' ] ,
550
503
depth : 0 ,
504
+ type : [ 'string' , 'object' ] ,
551
505
glyphs : [ ] ,
552
506
selectable : true ,
553
507
selected : false ,
554
508
variant : undefined ,
555
509
} ) ;
556
- await validateMixedType ( result [ 0 ] . type , / s t r i n g , o b j e c t / ) ;
557
510
expect ( result [ 1 ] ) . to . deep . equal ( {
558
511
name : 'first' ,
559
512
id : [ 'name' , 'first' ] ,
@@ -603,7 +556,7 @@ describe('getFieldsFromSchema', function () {
603
556
{
604
557
name : 'todos' ,
605
558
id : [ 'todos' ] ,
606
- type : '[] ' ,
559
+ type : 'array ' ,
607
560
depth : 0 ,
608
561
glyphs : [ ] ,
609
562
selectable : true ,
0 commit comments