@@ -26,8 +26,6 @@ const getFilterSwitch = () =>
2626
2727const file = new File ( [ "" ] , "file.csv" )
2828
29- jest . useFakeTimers ( )
30-
3129describe ( "Validation step tests" , ( ) => {
3230 test ( "Submit data" , async ( ) => {
3331 const onSubmit = jest . fn ( )
@@ -661,206 +659,6 @@ describe("Validation step tests", () => {
661659 expect ( mockedHook . mock . calls . length ) . toBe ( 3 )
662660 } )
663661
664- test ( "Async row hook" , async ( ) => {
665- const NAME = "John"
666- const LASTNAME = "Doe"
667- const NEW_NAME = "Johnny"
668- const NEW_LASTNAME = "CENA"
669- const TIMEOUT = 1000
670-
671- const fields = [
672- {
673- label : "Name" ,
674- key : "name" ,
675- fieldType : {
676- type : "input" ,
677- } ,
678- } ,
679- {
680- label : "lastName" ,
681- key : "lastName" ,
682- fieldType : {
683- type : "input" ,
684- } ,
685- } ,
686- ] as const
687- const tableHook : TableHook < fieldKeys < typeof fields > > = async ( rows ) => {
688- await new Promise ( ( resolve ) => setTimeout ( resolve , TIMEOUT ) )
689-
690- return rows . map ( ( value ) => ( {
691- name : value . name ?. toString ( ) ?. split ( / ( \s + ) / ) [ 0 ] ,
692- lastName : value . name ?. toString ( ) ?. split ( / ( \s + ) / ) [ 2 ] ,
693- } ) )
694- }
695-
696- const initialData = await addErrorsAndRunHooks (
697- [
698- {
699- name : NAME + " " + LASTNAME ,
700- lastName : undefined ,
701- } ,
702- ] ,
703- fields ,
704- undefined ,
705- tableHook ,
706- )
707- await act ( async ( ) => {
708- render (
709- < Providers
710- theme = { defaultTheme }
711- rsiValues = { {
712- ...mockValues ,
713- fields,
714- tableHook,
715- } }
716- >
717- < ModalWrapper isOpen = { true } onClose = { ( ) => { } } >
718- < ValidationStep < fieldKeys < typeof fields > > initialData = { initialData } file = { file } />
719- </ ModalWrapper >
720- </ Providers > ,
721- )
722- } )
723-
724- const nameCell = screen . getByRole ( "gridcell" , {
725- name : NAME ,
726- } )
727- expect ( nameCell ) . toBeInTheDocument ( )
728- const lastNameCell = screen . getByRole ( "gridcell" , {
729- name : LASTNAME ,
730- } )
731- expect ( lastNameCell ) . toBeInTheDocument ( )
732-
733- const NEW_FIRST_NAME_BEFORE_HOOK_RUNS = NEW_NAME + " " + NEW_LASTNAME
734-
735- // activate input
736- await userEvent . click ( nameCell )
737-
738- await userEvent . keyboard ( NEW_FIRST_NAME_BEFORE_HOOK_RUNS + "{enter}" )
739- // check that the value is updated before the hook runs
740- await waitFor ( ( ) =>
741- expect (
742- screen . getByRole ( "gridcell" , {
743- name : NEW_FIRST_NAME_BEFORE_HOOK_RUNS ,
744- } ) ,
745- ) . toBeInTheDocument ( ) ,
746- )
747-
748- jest . runAllTimers ( )
749-
750- // check that the value is updated after the hook runs
751- await waitFor ( ( ) =>
752- expect (
753- screen . getByRole ( "gridcell" , {
754- name : NEW_NAME ,
755- } ) ,
756- ) . toBeInTheDocument ( ) ,
757- )
758-
759- const newLastNameCell = screen . getByRole ( "gridcell" , {
760- name : NEW_LASTNAME ,
761- } )
762- expect ( newLastNameCell ) . toBeInTheDocument ( )
763- } )
764-
765- test ( "Async table hook" , async ( ) => {
766- const NAME = "John"
767- const LASTNAME = "Doe"
768- const NEW_NAME = "Johnny"
769- const NEW_LASTNAME = "CENA"
770- const TIMEOUT = 1000
771-
772- const fields = [
773- {
774- label : "Name" ,
775- key : "name" ,
776- fieldType : {
777- type : "input" ,
778- } ,
779- } ,
780- {
781- label : "lastName" ,
782- key : "lastName" ,
783- fieldType : {
784- type : "input" ,
785- } ,
786- } ,
787- ] as const
788- const rowHook : RowHook < fieldKeys < typeof fields > > = async ( value ) => {
789- await new Promise ( ( resolve ) => setTimeout ( resolve , TIMEOUT ) )
790-
791- return {
792- name : value . name ?. toString ( ) ?. split ( / ( \s + ) / ) [ 0 ] ,
793- lastName : value . name ?. toString ( ) ?. split ( / ( \s + ) / ) [ 2 ] ,
794- }
795- }
796-
797- const initialData = await addErrorsAndRunHooks (
798- [
799- {
800- name : NAME + " " + LASTNAME ,
801- lastName : undefined ,
802- } ,
803- ] ,
804- fields ,
805- rowHook ,
806- )
807- await act ( async ( ) => {
808- render (
809- < Providers
810- theme = { defaultTheme }
811- rsiValues = { {
812- ...mockValues ,
813- fields,
814- rowHook,
815- } }
816- >
817- < ModalWrapper isOpen = { true } onClose = { ( ) => { } } >
818- < ValidationStep < fieldKeys < typeof fields > > initialData = { initialData } file = { file } />
819- </ ModalWrapper >
820- </ Providers > ,
821- )
822- } )
823-
824- const nameCell = screen . getByRole ( "gridcell" , {
825- name : NAME ,
826- } )
827- expect ( nameCell ) . toBeInTheDocument ( )
828- const lastNameCell = screen . getByRole ( "gridcell" , {
829- name : LASTNAME ,
830- } )
831- expect ( lastNameCell ) . toBeInTheDocument ( )
832-
833- const NEW_FIRST_NAME_BEFORE_HOOK_RUNS = NEW_NAME + " " + NEW_LASTNAME
834-
835- // activate input
836- await userEvent . click ( nameCell )
837-
838- await userEvent . keyboard ( NEW_FIRST_NAME_BEFORE_HOOK_RUNS + "{enter}" )
839- // check that the value is updated before the hook runs
840- await waitFor ( ( ) =>
841- expect (
842- screen . getByRole ( "gridcell" , {
843- name : NEW_FIRST_NAME_BEFORE_HOOK_RUNS ,
844- } ) ,
845- ) . toBeInTheDocument ( ) ,
846- )
847-
848- jest . runAllTimers ( )
849- // check that the value is updated after the hook runs
850- await waitFor ( ( ) =>
851- expect (
852- screen . getByRole ( "gridcell" , {
853- name : NEW_NAME ,
854- } ) ,
855- ) . toBeInTheDocument ( ) ,
856- )
857-
858- const newLastNameCell = screen . getByRole ( "gridcell" , {
859- name : NEW_LASTNAME ,
860- } )
861- expect ( newLastNameCell ) . toBeInTheDocument ( )
862- } )
863-
864662 test ( "Row hook raises error" , async ( ) => {
865663 const WRONG_NAME = "Johnny"
866664 const RIGHT_NAME = "Jonathan"
0 commit comments