@@ -31,20 +31,6 @@ describe('<DataList.Item /> component', () => {
3131 expect ( link . classList ) . toContain ( 'cursor-pointer' ) ;
3232 } ) ;
3333
34- it ( 'marks the item as hidden when the data list is on initialLoading state' , ( ) => {
35- const context = { state : 'initialLoading' as const } ;
36- const props = { href : '/test' } ;
37- render ( createTestComponent ( { context, props } ) ) ;
38- expect ( screen . queryByRole ( 'link' ) ) . not . toBeInTheDocument ( ) ;
39- } ) ;
40-
41- it ( 'marks the item as hidden when the data list is on loading state with no elements being currently rendered' , ( ) => {
42- const context = { state : 'loading' as const , childrenItemCount : 0 } ;
43- const props = { href : '/test' } ;
44- render ( createTestComponent ( { context, props } ) ) ;
45- expect ( screen . queryByRole ( 'link' ) ) . not . toBeInTheDocument ( ) ;
46- } ) ;
47-
4834 it ( 'does not throw error when not placed inside the DataListContextProvider' , ( ) => {
4935 const context = null ;
5036 expect ( ( ) => render ( createTestComponent ( { context } ) ) ) . not . toThrow ( ) ;
@@ -58,9 +44,22 @@ describe('<DataList.Item /> component', () => {
5844 expect ( button . classList ) . toContain ( 'cursor-pointer' ) ;
5945 } ) ;
6046
61- it ( 'renders the item as a non interactive button when both onClick and href property are not set' , ( ) => {
62- const props = { onClick : undefined , href : undefined } ;
47+ it ( 'renders the item as a non interactive div when both onClick and href property are not set' , ( ) => {
48+ const props = { children : 'test-data-list-item' , onClick : undefined , href : undefined } ;
49+ render ( createTestComponent ( { props } ) ) ;
50+ const button = screen . queryByRole ( 'button' , { name : props . children } ) ;
51+ const link = screen . queryByRole ( 'link' , { name : props . children } ) ;
52+ const text = screen . getByText ( props . children ) ;
53+ expect ( button ) . not . toBeInTheDocument ( ) ;
54+ expect ( link ) . not . toBeInTheDocument ( ) ;
55+ expect ( text ) . toBeInTheDocument ( ) ;
56+ } ) ;
57+
58+ it ( 'renders the item as an interactive button when onClick property is set' , ( ) => {
59+ const props = { children : 'test-data-list-item' , onClick : jest . fn ( ) } ;
6360 render ( createTestComponent ( { props } ) ) ;
64- expect ( screen . getByRole ( 'button' ) . classList ) . not . toContain ( 'cursor-pointer' ) ;
61+ const button = screen . getByRole ( 'button' , { name : props . children } ) ;
62+ expect ( button ) . toBeInTheDocument ( ) ;
63+ expect ( button . classList ) . toContain ( 'cursor-pointer' ) ;
6564 } ) ;
6665} ) ;
0 commit comments