@@ -556,6 +556,51 @@ describe('Postcode lookup form pages', () => {
556556 expect ( $heading ) . toBeInTheDocument ( )
557557 } )
558558
559+ it ( 'should render validation error when invalid postcode is provided on manual page' , async ( ) => {
560+ const { csrfToken, headers } = await initialiseJourney ( server )
561+
562+ // Dispatch to postcode journey
563+ await server . inject ( {
564+ url : `${ basePath } /address` ,
565+ method : 'POST' ,
566+ headers,
567+ payload : {
568+ action : 'external-ybMHIv' ,
569+ crumb : csrfToken
570+ }
571+ } )
572+
573+ const { response, container } = await renderResponse ( server , {
574+ url : '/postcode-lookup?step=manual' ,
575+ method : 'POST' ,
576+ headers,
577+ payload : {
578+ step : 'manual' ,
579+ addressLine1 : '1 Street Name' ,
580+ addressLine2 : '' ,
581+ town : 'Middletown' ,
582+ county : '' ,
583+ postcode : 'INVALID123' ,
584+ crumb : csrfToken
585+ }
586+ } )
587+
588+ expect ( response . statusCode ) . toBe ( StatusCodes . OK )
589+ const $errorSummary = container . getByRole ( 'alert' )
590+
591+ const $heading = within ( $errorSummary ) . getByRole ( 'heading' , {
592+ name : 'There is a problem' ,
593+ level : 2
594+ } )
595+ expect ( $heading ) . toBeInTheDocument ( )
596+
597+ // Verify the specific postcode error message is shown
598+ const $postcodeError = container . getByRole ( 'link' , {
599+ name : 'Enter a valid postcode'
600+ } )
601+ expect ( $postcodeError ) . toBeInTheDocument ( )
602+ } )
603+
559604 it ( 'should redirect back to the source page after successful POST to manual page' , async ( ) => {
560605 const { csrfToken, headers } = await initialiseJourney ( server )
561606
0 commit comments