File tree Expand file tree Collapse file tree
src/steps/ValidationStep/tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -623,6 +623,72 @@ describe("Validation step tests", () => {
623623 expect ( newLastNameCell ) . toBeInTheDocument ( )
624624 } )
625625
626+ test ( "Row hook only runs on a single row" , async ( ) => {
627+ const NAME = "John"
628+ const NEW_NAME = "Kate"
629+ const LAST_NAME = "Doe"
630+ const initialData = [
631+ {
632+ name : NAME ,
633+ lastName : LAST_NAME ,
634+ } ,
635+ {
636+ name : "Johnny" ,
637+ lastName : "Doeson" ,
638+ } ,
639+ ]
640+ const fields = [
641+ {
642+ label : "Name" ,
643+ key : "name" ,
644+ fieldType : {
645+ type : "input" ,
646+ } ,
647+ } ,
648+ {
649+ label : "lastName" ,
650+ key : "lastName" ,
651+ fieldType : {
652+ type : "input" ,
653+ } ,
654+ } ,
655+ ] as const
656+
657+ const mockedHook = jest . fn ( ( a ) => a )
658+ await act ( async ( ) => {
659+ render (
660+ < Providers
661+ theme = { defaultTheme }
662+ rsiValues = { {
663+ ...mockValues ,
664+ fields,
665+ rowHook : mockedHook ,
666+ } }
667+ >
668+ < ModalWrapper isOpen = { true } onClose = { ( ) => { } } >
669+ < ValidationStep initialData = { initialData } file = { file } />
670+ </ ModalWrapper >
671+ </ Providers > ,
672+ )
673+ } )
674+
675+ // initially row hook is called for each row
676+ expect ( mockedHook . mock . calls . length ) . toBe ( 2 )
677+
678+ const nameCell = screen . getByRole ( "gridcell" , {
679+ name : NAME ,
680+ } )
681+ expect ( nameCell ) . toBeInTheDocument ( )
682+
683+ // activate input
684+ await userEvent . click ( nameCell )
685+
686+ await userEvent . keyboard ( NEW_NAME + "{enter}" )
687+
688+ expect ( mockedHook . mock . calls [ 2 ] [ 0 ] ?. name ) . toBe ( NEW_NAME )
689+ expect ( mockedHook . mock . calls . length ) . toBe ( 3 )
690+ } )
691+
626692 test ( "Row hook raises error" , async ( ) => {
627693 const WRONG_NAME = "Johnny"
628694 const RIGHT_NAME = "Jonathan"
You can’t perform that action at this time.
0 commit comments