@@ -2,7 +2,7 @@ import { palette } from '@leafygreen-ui/palette';
22import { ComponentProps } from 'react' ;
33import { userEvent } from '@testing-library/user-event' ;
44
5- import { render , screen } from '@/mocks/testing-utils' ;
5+ import { render , screen , waitFor } from '@/mocks/testing-utils' ;
66import { Field as FieldComponent } from '@/components/field/field' ;
77import { DEFAULT_PREVIEW_GROUP_AREA } from '@/utilities/get-preview-group-area' ;
88import { EditableDiagramInteractionsProvider } from '@/hooks/use-editable-diagram-interactions' ;
@@ -88,6 +88,31 @@ describe('field', () => {
8888 expect ( screen . getByText ( '[]' ) ) . toBeInTheDocument ( ) ;
8989 expect ( screen . queryByText ( 'array' ) ) . not . toBeInTheDocument ( ) ;
9090 } ) ;
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+ } ) ;
91116 } ) ;
92117
93118 describe ( 'With glyphs' , ( ) => {
0 commit comments