@@ -107,6 +107,34 @@ const actionListWithNoHeader = (
107107 </ ActionList >
108108)
109109
110+ const handleActionClick = jest . fn ( )
111+ const handleListItemClick = jest . fn ( )
112+ const clickableItems = data . map ( ( { id, name, type } ) => {
113+ const availableActions = (
114+ < >
115+ < ActionListItemAction onClick = { handleActionClick } >
116+ View Profile
117+ </ ActionListItemAction >
118+ </ >
119+ )
120+
121+ return (
122+ < ActionListItem
123+ id = { String ( id ) }
124+ key = { id }
125+ actions = { availableActions }
126+ onClick = { handleListItemClick }
127+ >
128+ < ActionListItemColumn > { id } </ ActionListItemColumn >
129+ < ActionListItemColumn > { name } </ ActionListItemColumn >
130+ < ActionListItemColumn > { type } </ ActionListItemColumn >
131+ </ ActionListItem >
132+ )
133+ } )
134+ const actionListWithClickableRows = (
135+ < ActionList columns = { columns } > { clickableItems } </ ActionList >
136+ )
137+
110138describe ( 'ActionList' , ( ) => {
111139 let rafSpy : jest . SpyInstance < number , [ FrameRequestCallback ] >
112140
@@ -118,6 +146,8 @@ describe('ActionList', () => {
118146
119147 afterEach ( ( ) => {
120148 rafSpy . mockRestore ( )
149+ handleActionClick . mockClear ( )
150+ handleListItemClick . mockClear ( )
121151 } )
122152
123153 describe ( 'General Layout' , ( ) => {
@@ -163,43 +193,13 @@ describe('ActionList', () => {
163193 expect ( getByText ( 'Game Designer' ) ) . toBeInTheDocument ( )
164194 } )
165195
166- test ( 'Renders action menu on button click and handles clicks on list item and action' , ( ) => {
167- const handleActionClick = jest . fn ( )
168- const handleListItemClick = jest . fn ( )
169-
170- const clickableItems = data . map ( ( { id, name, type } ) => {
171- const availableActions = (
172- < >
173- < ActionListItemAction onClick = { handleActionClick } >
174- View Profile
175- </ ActionListItemAction >
176- </ >
177- )
178-
179- return (
180- < ActionListItem
181- id = { String ( id ) }
182- key = { id }
183- actions = { availableActions }
184- onClick = { handleListItemClick }
185- >
186- < ActionListItemColumn > { id } </ ActionListItemColumn >
187- < ActionListItemColumn > { name } </ ActionListItemColumn >
188- < ActionListItemColumn > { type } </ ActionListItemColumn >
189- </ ActionListItem >
190- )
191- } )
192-
196+ test ( 'Renders action menu on button click and handles action click' , ( ) => {
193197 const { getByRole, getByText, queryByText } = renderWithTheme (
194- < ActionList columns = { columns } > { clickableItems } </ ActionList >
198+ actionListWithClickableRows
195199 )
196200
197201 const listItemId = getByText ( '1' )
198202
199- expect ( handleListItemClick . mock . calls . length ) . toBe ( 0 )
200- fireEvent . click ( listItemId )
201- expect ( handleListItemClick . mock . calls . length ) . toBe ( 1 )
202-
203203 fireEvent (
204204 listItemId ,
205205 new MouseEvent ( 'mouseenter' , {
@@ -221,6 +221,24 @@ describe('ActionList', () => {
221221
222222 expect ( queryByText ( 'View Profile' ) ) . not . toBeInTheDocument ( )
223223 } )
224+
225+ test ( 'Handles item click' , ( ) => {
226+ const { getByText } = renderWithTheme ( actionListWithClickableRows )
227+
228+ const actionListItemColumn = getByText ( '1' )
229+
230+ expect ( handleListItemClick ) . toHaveBeenCalledTimes ( 0 )
231+ fireEvent . click ( actionListItemColumn )
232+ expect ( handleListItemClick ) . toHaveBeenCalledTimes ( 1 )
233+ } )
234+
235+ xtest ( 'Item has pointer cursor and shadow when hovering over ActionListItem' , ( ) => {
236+ /**
237+ * mouseEnter events off of the fireEvent jest-dom function do not (currently)
238+ * trigger hover styles (i.e. hover pseudo classes) on ActionListItems, which makes
239+ * writing this particularly challenging at the moment.
240+ */
241+ } )
224242 } )
225243
226244 describe ( 'Sorting' , ( ) => {
@@ -252,7 +270,7 @@ describe('ActionList', () => {
252270 } )
253271 } )
254272
255- describe . only ( 'Selecting' , ( ) => {
273+ describe ( 'Selecting' , ( ) => {
256274 const onSelect = jest . fn ( )
257275 const actionListWithSelect = (
258276 < ActionList columns = { columns } canSelect onSelect = { onSelect } >
0 commit comments