@@ -2,7 +2,7 @@ import { palette } from '@leafygreen-ui/palette';
2
2
import { ComponentProps } from 'react' ;
3
3
import { userEvent } from '@testing-library/user-event' ;
4
4
5
- import { render , screen } from '@/mocks/testing-utils' ;
5
+ import { render , screen , waitFor } from '@/mocks/testing-utils' ;
6
6
import { Field as FieldComponent } from '@/components/field/field' ;
7
7
import { DEFAULT_PREVIEW_GROUP_AREA } from '@/utilities/get-preview-group-area' ;
8
8
import { EditableDiagramInteractionsProvider } from '@/hooks/use-editable-diagram-interactions' ;
@@ -88,6 +88,31 @@ describe('field', () => {
88
88
expect ( screen . getByText ( '[]' ) ) . toBeInTheDocument ( ) ;
89
89
expect ( screen . queryByText ( 'array' ) ) . not . toBeInTheDocument ( ) ;
90
90
} ) ;
91
+
92
+ it ( 'shows (mixed) with multiple types with a tooltip with more info' , async ( ) => {
93
+ render ( < Field { ...DEFAULT_PROPS } type = { [ 'string' , 'number' , 'array' ] } /> ) ;
94
+ expect ( screen . getByText ( '(mixed)' ) ) . toBeInTheDocument ( ) ;
95
+ expect ( screen . queryByText ( 'string' ) ) . not . toBeInTheDocument ( ) ;
96
+
97
+ // When hovering the (mixed) text, the tooltip content is present in the document.
98
+ await userEvent . hover ( screen . getByText ( '(mixed)' ) ) ;
99
+ const tooltipText = 'Multiple types: string, number, array' ;
100
+ await screen . findByText ( tooltipText ) ;
101
+ await userEvent . unhover ( screen . getByText ( '(mixed)' ) ) ;
102
+ await waitFor ( ( ) => expect ( screen . queryByText ( tooltipText ) ) . not . toBeInTheDocument ( ) ) ;
103
+ } ) ;
104
+
105
+ it ( 'shows type when a single type in an array is provided' , ( ) => {
106
+ render ( < Field { ...DEFAULT_PROPS } type = { [ 'string' ] } /> ) ;
107
+ expect ( screen . getByText ( 'string' ) ) . toBeInTheDocument ( ) ;
108
+ expect ( screen . queryByText ( '(mixed)' ) ) . not . toBeInTheDocument ( ) ;
109
+ } ) ;
110
+
111
+ it ( 'shows unknown when an empty array type is provided' , ( ) => {
112
+ render ( < Field { ...DEFAULT_PROPS } type = { [ ] } /> ) ;
113
+ expect ( screen . getByText ( 'unknown' ) ) . toBeInTheDocument ( ) ;
114
+ expect ( screen . queryByText ( '(mixed)' ) ) . not . toBeInTheDocument ( ) ;
115
+ } ) ;
91
116
} ) ;
92
117
93
118
describe ( 'With glyphs' , ( ) => {
0 commit comments