@@ -5,7 +5,6 @@ import userEvent from '@testing-library/user-event';
55import { RhUiExportIcon } from '@patternfly/react-icons/dist/esm/icons/rh-ui-export-icon' ;
66import { RhMicronsInformationFillIcon } from '@patternfly/react-icons/dist/esm/icons/rh-microns-information-fill-icon' ;
77import { RhUiRedoIcon } from '@patternfly/react-icons/dist/esm/icons/rh-ui-redo-icon' ;
8- import Message from '../Message' ;
98
109// Mock the icon components
1110jest . mock ( '@patternfly/react-icons/dist/esm/icons/rh-ui-like-icon' , ( ) => ( {
@@ -368,82 +367,80 @@ describe('ResponseActions', () => {
368367
369368 // we are testing for the reverse case already above
370369 it ( 'should not deselect when clicking outside when persistActionSelection is true' , async ( ) => {
370+ const user = userEvent . setup ( ) ;
371+
371372 render (
372- < Message
373- name = "Bot"
374- role = "bot"
375- avatar = ""
376- content = "Test content"
377- actions = { {
378- positive : { } ,
379- negative : { }
380- } }
381- persistActionSelection
382- />
373+ < div >
374+ < ResponseActions
375+ actions = { {
376+ positive : { onClick : jest . fn ( ) } ,
377+ negative : { onClick : jest . fn ( ) }
378+ } }
379+ persistActionSelection
380+ />
381+ < div data-testid = "outside" > Outside</ div >
382+ </ div >
383383 ) ;
384384 const goodBtn = screen . getByRole ( 'button' , { name : 'Good response' } ) ;
385385
386- await userEvent . click ( goodBtn ) ;
386+ await user . click ( goodBtn ) ;
387387 expect ( screen . getByRole ( 'button' , { name : 'Good response recorded' } ) ) . toHaveClass (
388388 'pf-chatbot__button--response-action-clicked'
389389 ) ;
390390
391- await userEvent . click ( screen . getByText ( 'Test content ') ) ;
391+ await user . click ( screen . getByTestId ( 'outside ') ) ;
392392
393393 expect ( screen . getByRole ( 'button' , { name : 'Good response recorded' } ) ) . toHaveClass (
394394 'pf-chatbot__button--response-action-clicked'
395395 ) ;
396396 } ) ;
397397
398398 it ( 'should switch selection to another button when persistActionSelection is true' , async ( ) => {
399+ const user = userEvent . setup ( ) ;
400+
399401 render (
400- < Message
401- name = "Bot"
402- role = "bot"
403- avatar = ""
404- content = "Test content"
402+ < ResponseActions
405403 actions = { {
406- positive : { } ,
407- negative : { }
404+ positive : { onClick : jest . fn ( ) } ,
405+ negative : { onClick : jest . fn ( ) }
408406 } }
409407 persistActionSelection
410408 />
411409 ) ;
412410 const goodBtn = screen . getByRole ( 'button' , { name : 'Good response' } ) ;
413411 const badBtn = screen . getByRole ( 'button' , { name : 'Bad response' } ) ;
414412
415- await userEvent . click ( goodBtn ) ;
413+ await user . click ( goodBtn ) ;
416414 expect ( goodBtn ) . toHaveClass ( 'pf-chatbot__button--response-action-clicked' ) ;
417415
418- await userEvent . click ( badBtn ) ;
416+ await user . click ( badBtn ) ;
419417 expect ( badBtn ) . toHaveClass ( 'pf-chatbot__button--response-action-clicked' ) ;
420418 expect ( goodBtn ) . not . toHaveClass ( 'pf-chatbot__button--response-action-clicked' ) ;
421419 } ) ;
422420
423421 it ( 'should toggle off when clicking the same button when persistActionSelection is true' , async ( ) => {
422+ const user = userEvent . setup ( ) ;
423+
424424 render (
425- < Message
426- name = "Bot"
427- role = "bot"
428- avatar = ""
429- content = "Test content"
425+ < ResponseActions
430426 actions = { {
431- positive : { } ,
432- negative : { }
427+ positive : { onClick : jest . fn ( ) } ,
428+ negative : { onClick : jest . fn ( ) }
433429 } }
434430 persistActionSelection
435431 />
436432 ) ;
437433 const goodBtn = screen . getByRole ( 'button' , { name : 'Good response' } ) ;
438434
439- await userEvent . click ( goodBtn ) ;
435+ await user . click ( goodBtn ) ;
440436 expect ( goodBtn ) . toHaveClass ( 'pf-chatbot__button--response-action-clicked' ) ;
441437
442- await userEvent . click ( goodBtn ) ;
438+ await user . click ( goodBtn ) ;
443439 expect ( goodBtn ) . not . toHaveClass ( 'pf-chatbot__button--response-action-clicked' ) ;
444440 } ) ;
445441
446442 it ( 'should work with custom actions when persistActionSelection is true' , async ( ) => {
443+ const user = userEvent . setup ( ) ;
447444 const actions = {
448445 positive : { 'data-testid' : 'positive' , onClick : jest . fn ( ) } ,
449446 negative : { 'data-testid' : 'negative' , onClick : jest . fn ( ) } ,
@@ -458,10 +455,10 @@ describe('ResponseActions', () => {
458455 render ( < ResponseActions actions = { actions } persistActionSelection /> ) ;
459456
460457 const customBtn = screen . getByTestId ( 'custom' ) ;
461- await userEvent . click ( customBtn ) ;
458+ await user . click ( customBtn ) ;
462459 expect ( customBtn ) . toHaveClass ( 'pf-chatbot__button--response-action-clicked' ) ;
463460
464- await userEvent . click ( customBtn ) ;
461+ await user . click ( customBtn ) ;
465462 expect ( customBtn ) . not . toHaveClass ( 'pf-chatbot__button--response-action-clicked' ) ;
466463 } ) ;
467464
0 commit comments