@@ -425,4 +425,215 @@ describe("Bedrock Component", () => {
425425 expect ( screen . getByTestId ( "vpc-endpoint-input" ) ) . toHaveValue ( "https://updated-endpoint.aws.com" )
426426 } )
427427 } )
428+
429+ // Test Scenario 6: Custom Region Tests
430+ describe ( "Custom Region" , ( ) => {
431+ it ( "should show custom region input when 'Custom region...' is selected" , ( ) => {
432+ const apiConfiguration : Partial < ProviderSettings > = {
433+ awsRegion : "" ,
434+ awsUseProfile : true ,
435+ }
436+
437+ render (
438+ < Bedrock
439+ apiConfiguration = { apiConfiguration as ProviderSettings }
440+ setApiConfigurationField = { mockSetApiConfigurationField }
441+ /> ,
442+ )
443+
444+ // Custom region input should not be visible initially
445+ expect ( screen . queryByTestId ( "custom-region-input" ) ) . not . toBeInTheDocument ( )
446+
447+ // Mock the Select component to simulate selecting "custom"
448+ // Since we're mocking the Select component, we need to simulate the onValueChange call
449+ const selectComponent = screen . getByRole ( "combobox" , { hidden : true } )
450+ if ( selectComponent ) {
451+ // Simulate selecting "custom" region
452+ const onValueChange = ( selectComponent as any ) . onValueChange || ( ( ) => { } )
453+ onValueChange ( "custom" )
454+ }
455+
456+ // Verify that setApiConfigurationField was called with "custom"
457+ expect ( mockSetApiConfigurationField ) . toHaveBeenCalledWith ( "awsRegion" , "custom" )
458+ } )
459+
460+ it ( "should hide custom region input when switching from custom to standard region" , ( ) => {
461+ const apiConfiguration : Partial < ProviderSettings > = {
462+ awsRegion : "custom" ,
463+ awsCustomRegion : "us-west-3" ,
464+ awsUseProfile : true ,
465+ }
466+
467+ render (
468+ < Bedrock
469+ apiConfiguration = { apiConfiguration as ProviderSettings }
470+ setApiConfigurationField = { mockSetApiConfigurationField }
471+ /> ,
472+ )
473+
474+ // Custom region input should be visible initially
475+ expect ( screen . getByTestId ( "custom-region-input" ) ) . toBeInTheDocument ( )
476+ expect ( screen . getByTestId ( "custom-region-input" ) ) . toHaveValue ( "us-west-3" )
477+
478+ // Mock selecting a standard region
479+ const selectComponent = screen . getByRole ( "combobox" , { hidden : true } )
480+ if ( selectComponent ) {
481+ const onValueChange = ( selectComponent as any ) . onValueChange || ( ( ) => { } )
482+ onValueChange ( "us-east-1" )
483+ }
484+
485+ // Verify that both awsRegion and awsCustomRegion were updated
486+ expect ( mockSetApiConfigurationField ) . toHaveBeenCalledWith ( "awsRegion" , "us-east-1" )
487+ expect ( mockSetApiConfigurationField ) . toHaveBeenCalledWith ( "awsCustomRegion" , "" )
488+ } )
489+
490+ it ( "should handle custom region input changes" , ( ) => {
491+ const apiConfiguration : Partial < ProviderSettings > = {
492+ awsRegion : "custom" ,
493+ awsCustomRegion : "" ,
494+ awsUseProfile : true ,
495+ }
496+
497+ render (
498+ < Bedrock
499+ apiConfiguration = { apiConfiguration as ProviderSettings }
500+ setApiConfigurationField = { mockSetApiConfigurationField }
501+ /> ,
502+ )
503+
504+ // Find the custom region input field
505+ const customRegionInput = screen . getByTestId ( "custom-region-input" )
506+ expect ( customRegionInput ) . toBeInTheDocument ( )
507+
508+ // Enter a custom region
509+ fireEvent . change ( customRegionInput , { target : { value : "us-west-3" } } )
510+
511+ // Verify the configuration field was updated
512+ expect ( mockSetApiConfigurationField ) . toHaveBeenCalledWith ( "awsCustomRegion" , "us-west-3" )
513+ } )
514+
515+ it ( "should display example regions when custom region is selected" , ( ) => {
516+ const apiConfiguration : Partial < ProviderSettings > = {
517+ awsRegion : "custom" ,
518+ awsCustomRegion : "us-west-3" ,
519+ awsUseProfile : true ,
520+ }
521+
522+ render (
523+ < Bedrock
524+ apiConfiguration = { apiConfiguration as ProviderSettings }
525+ setApiConfigurationField = { mockSetApiConfigurationField }
526+ /> ,
527+ )
528+
529+ // Check that the custom region input is visible
530+ expect ( screen . getByTestId ( "custom-region-input" ) ) . toBeInTheDocument ( )
531+
532+ // Check for the example regions section
533+ expect ( screen . getByText ( "settings:providers.awsCustomRegion.examples" ) ) . toBeInTheDocument ( )
534+ expect ( screen . getByText ( "• us-west-3" ) ) . toBeInTheDocument ( )
535+ expect ( screen . getByText ( "• eu-central-3" ) ) . toBeInTheDocument ( )
536+ expect ( screen . getByText ( "• ap-southeast-3" ) ) . toBeInTheDocument ( )
537+ } )
538+
539+ it ( "should preserve custom region value when toggling between custom and standard regions" , ( ) => {
540+ const apiConfiguration : Partial < ProviderSettings > = {
541+ awsRegion : "custom" ,
542+ awsCustomRegion : "us-west-3" ,
543+ awsUseProfile : true ,
544+ }
545+
546+ const { rerender } = render (
547+ < Bedrock
548+ apiConfiguration = { apiConfiguration as ProviderSettings }
549+ setApiConfigurationField = { mockSetApiConfigurationField }
550+ /> ,
551+ )
552+
553+ // Initial state: custom region selected with value
554+ expect ( screen . getByTestId ( "custom-region-input" ) ) . toBeInTheDocument ( )
555+ expect ( screen . getByTestId ( "custom-region-input" ) ) . toHaveValue ( "us-west-3" )
556+
557+ // Switch to standard region
558+ const updatedConfig : Partial < ProviderSettings > = {
559+ awsRegion : "us-east-1" ,
560+ awsCustomRegion : "" , // This would be cleared by the component logic
561+ awsUseProfile : true ,
562+ }
563+
564+ rerender (
565+ < Bedrock
566+ apiConfiguration = { updatedConfig as ProviderSettings }
567+ setApiConfigurationField = { mockSetApiConfigurationField }
568+ /> ,
569+ )
570+
571+ // Custom region input should be hidden
572+ expect ( screen . queryByTestId ( "custom-region-input" ) ) . not . toBeInTheDocument ( )
573+
574+ // Switch back to custom region with preserved value
575+ const backToCustomConfig : Partial < ProviderSettings > = {
576+ awsRegion : "custom" ,
577+ awsCustomRegion : "us-west-3" , // Value preserved in parent state
578+ awsUseProfile : true ,
579+ }
580+
581+ rerender (
582+ < Bedrock
583+ apiConfiguration = { backToCustomConfig as ProviderSettings }
584+ setApiConfigurationField = { mockSetApiConfigurationField }
585+ /> ,
586+ )
587+
588+ // Custom region input should be visible again with preserved value
589+ expect ( screen . getByTestId ( "custom-region-input" ) ) . toBeInTheDocument ( )
590+ expect ( screen . getByTestId ( "custom-region-input" ) ) . toHaveValue ( "us-west-3" )
591+ } )
592+
593+ it ( "should handle empty custom region input" , ( ) => {
594+ const apiConfiguration : Partial < ProviderSettings > = {
595+ awsRegion : "custom" ,
596+ awsCustomRegion : "us-west-3" ,
597+ awsUseProfile : true ,
598+ }
599+
600+ render (
601+ < Bedrock
602+ apiConfiguration = { apiConfiguration as ProviderSettings }
603+ setApiConfigurationField = { mockSetApiConfigurationField }
604+ /> ,
605+ )
606+
607+ // Find the custom region input field
608+ const customRegionInput = screen . getByTestId ( "custom-region-input" )
609+
610+ // Clear the field
611+ fireEvent . change ( customRegionInput , { target : { value : "" } } )
612+
613+ // Verify the configuration field was updated with empty string
614+ expect ( mockSetApiConfigurationField ) . toHaveBeenCalledWith ( "awsCustomRegion" , "" )
615+ } )
616+
617+ it ( "should initialize with correct state when custom region is pre-selected" , ( ) => {
618+ const apiConfiguration : Partial < ProviderSettings > = {
619+ awsRegion : "custom" ,
620+ awsCustomRegion : "eu-central-3" ,
621+ awsUseProfile : true ,
622+ }
623+
624+ render (
625+ < Bedrock
626+ apiConfiguration = { apiConfiguration as ProviderSettings }
627+ setApiConfigurationField = { mockSetApiConfigurationField }
628+ /> ,
629+ )
630+
631+ // Verify custom region input is visible and has correct value
632+ expect ( screen . getByTestId ( "custom-region-input" ) ) . toBeInTheDocument ( )
633+ expect ( screen . getByTestId ( "custom-region-input" ) ) . toHaveValue ( "eu-central-3" )
634+
635+ // Verify examples are shown
636+ expect ( screen . getByText ( "settings:providers.awsCustomRegion.examples" ) ) . toBeInTheDocument ( )
637+ } )
638+ } )
428639} )
0 commit comments