@@ -3071,5 +3071,120 @@ describe('ContractorOnboardingFlow', () => {
30713071 expect ( screen . getByLabelText ( / E n t e r f u l l n a m e / i) ) . toBeInTheDocument ( ) ;
30723072 expect ( signatureField ) . toHaveValue ( 'John Doe' ) ;
30733073 } ) ;
3074+
3075+ it ( 'should refetch contract document after signing and allow navigation back without errors' , async ( ) => {
3076+ const employmentId = generateUniqueEmploymentId ( ) ;
3077+ const contractDocumentId = 'f4f32dbf-4d15-42ef-a960-fea60ab3b68c' ;
3078+ let getContractDocumentCallCount = 0 ;
3079+ const signContractSpy = vi . fn ( ) ;
3080+
3081+ server . use (
3082+ http . post (
3083+ '*/v1/contractors/employments/*/contract-documents' ,
3084+ async ( ) => {
3085+ return HttpResponse . json ( {
3086+ data : {
3087+ contract_document : {
3088+ id : contractDocumentId ,
3089+ } ,
3090+ } ,
3091+ } ) ;
3092+ } ,
3093+ ) ,
3094+ http . get (
3095+ '*/v1/contractors/employments/*/contract-documents/*' ,
3096+ async ( ) => {
3097+ getContractDocumentCallCount ++ ;
3098+ return HttpResponse . json ( {
3099+ data : {
3100+ contract_document : {
3101+ name : '2025-10-23_TestContract.pdf' ,
3102+ content : 'data:application/pdf;base64,JVBERi0xLjQ=' ,
3103+ signatories : [
3104+ {
3105+ type : 'company' ,
3106+ status :
3107+ getContractDocumentCallCount > 2 ? 'signed' : 'pending' ,
3108+ } ,
3109+ ] ,
3110+ } ,
3111+ } ,
3112+ } ) ;
3113+ } ,
3114+ ) ,
3115+ http . post (
3116+ '*/v1/contractors/employments/*/contract-documents/*/sign' ,
3117+ async ( { request } ) => {
3118+ const requestBody = await request . json ( ) ;
3119+ signContractSpy ( requestBody ) ;
3120+ return HttpResponse . json ( mockContractDocumentSignedResponse ) ;
3121+ } ,
3122+ ) ,
3123+ ) ;
3124+
3125+ mockRender . mockImplementation (
3126+ createMockRenderImplementation ( MultiStepFormWithoutCountry ) ,
3127+ ) ;
3128+
3129+ render (
3130+ < ContractorOnboardingFlow
3131+ employmentId = { employmentId }
3132+ countryCode = 'PRT'
3133+ skipSteps = { [ 'select_country' ] }
3134+ { ...defaultProps }
3135+ /> ,
3136+ { wrapper : TestProviders } ,
3137+ ) ;
3138+
3139+ await screen . findByText ( / S t e p : B a s i c I n f o r m a t i o n / i) ;
3140+ await waitForElementToBeRemoved ( ( ) => screen . getByTestId ( 'spinner' ) ) ;
3141+
3142+ await fillBasicInformation ( ) ;
3143+ let nextButton = screen . getByText ( / N e x t S t e p / i) ;
3144+ nextButton . click ( ) ;
3145+
3146+ await screen . findByText ( / S t e p : P r i c i n g P l a n / i) ;
3147+
3148+ await fillContractorSubscription ( ) ;
3149+ nextButton = screen . getByText ( / N e x t S t e p / i) ;
3150+ nextButton . click ( ) ;
3151+
3152+ await screen . findByText ( / S t e p : C o n t r a c t D e t a i l s / i) ;
3153+ await fillContractDetails ( ) ;
3154+
3155+ nextButton = screen . getByText ( / N e x t S t e p / i) ;
3156+ nextButton . click ( ) ;
3157+
3158+ await screen . findByText ( / S t e p : C o n t r a c t P r e v i e w / i) ;
3159+ await waitForElementToBeRemoved ( ( ) => screen . getByTestId ( 'spinner' ) ) ;
3160+ const countBeforeSigning = getContractDocumentCallCount ;
3161+
3162+ await fillSignature ( ) ;
3163+
3164+ nextButton = screen . getByText ( / C o n t i n u e / i) ;
3165+ nextButton . click ( ) ;
3166+
3167+ // Wait for navigation to review step, which means signing AND refetching completed
3168+ await screen . findByText ( / S t e p : R e v i e w / i) ;
3169+
3170+ // Verify signing happened
3171+ expect ( signContractSpy ) . toHaveBeenCalledTimes ( 1 ) ;
3172+
3173+ // After signing, the refetch should have happened
3174+ expect ( getContractDocumentCallCount ) . toBe ( countBeforeSigning + 1 ) ;
3175+
3176+ // Now navigate back to contract preview
3177+ const backButton = screen . getByText ( / B a c k / i) ;
3178+ backButton . click ( ) ;
3179+
3180+ await screen . findByText ( / S t e p : C o n t r a c t P r e v i e w / i) ;
3181+
3182+ // Verify no errors occurred during navigation back
3183+ expect ( mockOnError ) . not . toHaveBeenCalled ( ) ;
3184+
3185+ // Count might be 3 now if going back triggers another fetch,
3186+ // or still 2 if it uses cached data
3187+ expect ( getContractDocumentCallCount ) . toBeGreaterThanOrEqual ( 2 ) ;
3188+ } ) ;
30743189 } ) ;
30753190} ) ;
0 commit comments