1+ import React from "react"
12import { render , screen , fireEvent } from "@/utils/test-utils"
23import { QueryClient , QueryClientProvider } from "@tanstack/react-query"
34
@@ -10,16 +11,47 @@ vi.mock("@src/utils/vscode", () => ({ vscode: { postMessage: vi.fn() } }))
1011
1112vi . mock ( "../ApiConfigManager" , ( ) => ( {
1213 __esModule : true ,
13- default : ( { currentApiConfigName, onRenameConfig } : any ) => (
14- < div data-testid = "api-config-management" >
15- < span > Current config: { currentApiConfigName } </ span >
16- < button
17- data-testid = "rename-profile-button"
18- onClick = { ( ) => onRenameConfig && onRenameConfig ( "oldProfile" , "newProfile" ) } >
19- Rename Profile
20- </ button >
21- </ div >
22- ) ,
14+ default : ( { currentApiConfigName, onRenameConfig } : any ) => {
15+ const [ isRenaming , setIsRenaming ] = React . useState ( false )
16+ const [ newName , setNewName ] = React . useState ( "" )
17+
18+ const handleRename = ( ) => {
19+ if ( isRenaming && newName . trim ( ) && onRenameConfig ) {
20+ onRenameConfig ( currentApiConfigName || "defaultProfile" , newName . trim ( ) )
21+ setIsRenaming ( false )
22+ setNewName ( "" )
23+ } else {
24+ setIsRenaming ( true )
25+ setNewName ( currentApiConfigName || "defaultProfile" )
26+ }
27+ }
28+
29+ return (
30+ < div data-testid = "api-config-management" >
31+ < span > Current config: { currentApiConfigName } </ span >
32+ { isRenaming ? (
33+ < div >
34+ < input
35+ data-testid = "rename-input"
36+ value = { newName }
37+ onChange = { ( e ) => setNewName ( e . target . value ) }
38+ placeholder = "Enter new profile name"
39+ />
40+ < button data-testid = "confirm-rename-button" onClick = { handleRename } >
41+ Confirm
42+ </ button >
43+ < button data-testid = "cancel-rename-button" onClick = { ( ) => setIsRenaming ( false ) } >
44+ Cancel
45+ </ button >
46+ </ div >
47+ ) : (
48+ < button data-testid = "rename-profile-button" onClick = { handleRename } >
49+ Rename Profile
50+ </ button >
51+ ) }
52+ </ div >
53+ )
54+ } ,
2355} ) )
2456
2557vi . mock ( "@vscode/webview-ui-toolkit/react" , ( ) => ( {
@@ -657,10 +689,17 @@ describe("SettingsView - Profile Rename Change Detection", () => {
657689 // Render settings view
658690 renderSettingsView ( )
659691
660- // Rename a profile to trigger change detection
692+ // Start rename process
661693 const renameButton = screen . getByTestId ( "rename-profile-button" )
662694 fireEvent . click ( renameButton )
663695
696+ // Enter new name and confirm
697+ const renameInput = screen . getByTestId ( "rename-input" )
698+ fireEvent . change ( renameInput , { target : { value : "newProfileName" } } )
699+
700+ const confirmButton = screen . getByTestId ( "confirm-rename-button" )
701+ fireEvent . click ( confirmButton )
702+
664703 // Save button should now be enabled due to change detection
665704 const saveButton = screen . getByTestId ( "save-button" )
666705 expect ( saveButton ) . not . toBeDisabled ( )
@@ -670,15 +709,25 @@ describe("SettingsView - Profile Rename Change Detection", () => {
670709 // Render settings view
671710 renderSettingsView ( )
672711
673- // Rename a profile
712+ // Start rename process
674713 const renameButton = screen . getByTestId ( "rename-profile-button" )
675714 fireEvent . click ( renameButton )
676715
677- // Verify that the rename message was sent to vscode
716+ // Enter new name and confirm
717+ const renameInput = screen . getByTestId ( "rename-input" )
718+ fireEvent . change ( renameInput , { target : { value : "renamedProfile" } } )
719+
720+ const confirmButton = screen . getByTestId ( "confirm-rename-button" )
721+ fireEvent . click ( confirmButton )
722+
723+ // Verify that the rename message was sent to vscode with dynamic values
724+ // Note: The actual oldName will depend on the current API config name from the extension state
678725 expect ( vscode . postMessage ) . toHaveBeenCalledWith (
679726 expect . objectContaining ( {
680727 type : "renameApiConfiguration" ,
681- values : { oldName : "oldProfile" , newName : "newProfile" } ,
728+ values : expect . objectContaining ( {
729+ newName : "renamedProfile" ,
730+ } ) ,
682731 } ) ,
683732 )
684733 } )
@@ -687,10 +736,17 @@ describe("SettingsView - Profile Rename Change Detection", () => {
687736 // Render settings view
688737 renderSettingsView ( )
689738
690- // Rename a profile
739+ // Start rename process
691740 const renameButton = screen . getByTestId ( "rename-profile-button" )
692741 fireEvent . click ( renameButton )
693742
743+ // Enter new name and confirm
744+ const renameInput = screen . getByTestId ( "rename-input" )
745+ fireEvent . change ( renameInput , { target : { value : "renamedProfile" } } )
746+
747+ const confirmButton = screen . getByTestId ( "confirm-rename-button" )
748+ fireEvent . click ( confirmButton )
749+
694750 // Click save button
695751 const saveButton = screen . getByTestId ( "save-button" )
696752 fireEvent . click ( saveButton )
@@ -707,10 +763,17 @@ describe("SettingsView - Profile Rename Change Detection", () => {
707763 // Render settings view
708764 renderSettingsView ( )
709765
710- // Rename a profile
766+ // Start rename process
711767 const renameButton = screen . getByTestId ( "rename-profile-button" )
712768 fireEvent . click ( renameButton )
713769
770+ // Enter new name and confirm
771+ const renameInput = screen . getByTestId ( "rename-input" )
772+ fireEvent . change ( renameInput , { target : { value : "renamedProfile" } } )
773+
774+ const confirmButton = screen . getByTestId ( "confirm-rename-button" )
775+ fireEvent . click ( confirmButton )
776+
714777 // Verify save button is enabled
715778 const saveButton = screen . getByTestId ( "save-button" )
716779 expect ( saveButton ) . not . toBeDisabled ( )
@@ -726,10 +789,17 @@ describe("SettingsView - Profile Rename Change Detection", () => {
726789 // Render with activateTab helper
727790 const { onDone } = renderSettingsView ( )
728791
729- // Rename a profile to create unsaved changes
792+ // Start rename process
730793 const renameButton = screen . getByTestId ( "rename-profile-button" )
731794 fireEvent . click ( renameButton )
732795
796+ // Enter new name and confirm to create unsaved changes
797+ const renameInput = screen . getByTestId ( "rename-input" )
798+ fireEvent . change ( renameInput , { target : { value : "renamedProfile" } } )
799+
800+ const confirmButton = screen . getByTestId ( "confirm-rename-button" )
801+ fireEvent . click ( confirmButton )
802+
733803 // Try to leave by clicking Done
734804 const doneButton = screen . getByText ( "settings:common.done" )
735805 fireEvent . click ( doneButton )
@@ -746,10 +816,17 @@ describe("SettingsView - Profile Rename Change Detection", () => {
746816 // Render with activateTab helper
747817 const { onDone } = renderSettingsView ( )
748818
749- // Rename a profile to create unsaved changes
819+ // Start rename process
750820 const renameButton = screen . getByTestId ( "rename-profile-button" )
751821 fireEvent . click ( renameButton )
752822
823+ // Enter new name and confirm to create unsaved changes
824+ const renameInput = screen . getByTestId ( "rename-input" )
825+ fireEvent . change ( renameInput , { target : { value : "renamedProfile" } } )
826+
827+ const confirmButton = screen . getByTestId ( "confirm-rename-button" )
828+ fireEvent . click ( confirmButton )
829+
753830 // Try to leave by clicking Done
754831 const doneButton = screen . getByText ( "settings:common.done" )
755832 fireEvent . click ( doneButton )
@@ -766,10 +843,17 @@ describe("SettingsView - Profile Rename Change Detection", () => {
766843 // Render with activateTab helper
767844 const { onDone } = renderSettingsView ( )
768845
769- // Rename a profile to create unsaved changes
846+ // Start rename process
770847 const renameButton = screen . getByTestId ( "rename-profile-button" )
771848 fireEvent . click ( renameButton )
772849
850+ // Enter new name and confirm to create unsaved changes
851+ const renameInput = screen . getByTestId ( "rename-input" )
852+ fireEvent . change ( renameInput , { target : { value : "renamedProfile" } } )
853+
854+ const confirmButton = screen . getByTestId ( "confirm-rename-button" )
855+ fireEvent . click ( confirmButton )
856+
773857 // Try to leave by clicking Done
774858 const doneButton = screen . getByText ( "settings:common.done" )
775859 fireEvent . click ( doneButton )
0 commit comments