@@ -641,7 +641,126 @@ describe("ButtonSetManager", () => {
641641 } ) ;
642642 } ) ;
643643
644- describe ( "updateButtonSet" , ( ) => {
644+ describe ( "renameButtonSet" , ( ) => {
645+ it ( "should return setNotFound error when renaming non-existent set" , async ( ) => {
646+ const existingSets = [ { buttons : [ ] , id : "set-1" , name : "SetA" } ] ;
647+ const mockConfig = createMockConfig ( ) ;
648+ mockConfig . get . mockReturnValue ( CONFIGURATION_TARGETS . WORKSPACE ) ;
649+ mockConfig . inspect . mockImplementation ( ( key : string ) => {
650+ if ( key === "buttonSets" ) {
651+ return { workspaceValue : existingSets } ;
652+ }
653+ if ( key === "activeSet" ) {
654+ return { workspaceValue : null } ;
655+ }
656+ return { } ;
657+ } ) ;
658+ jest
659+ . spyOn ( vscode . workspace , "getConfiguration" )
660+ . mockReturnValue ( mockConfig as unknown as vscode . WorkspaceConfiguration ) ;
661+
662+ const configManager = createMockConfigManager ( ) ;
663+ const configReader = createMockConfigReader ( ) ;
664+ const buttonSetWriter = createMockButtonSetWriter ( ) ;
665+
666+ const manager = ButtonSetManager . create ( configManager , configReader , buttonSetWriter ) ;
667+ const result = await manager . renameButtonSet ( "NonExistent" , "NewName" ) ;
668+
669+ expect ( result . success ) . toBe ( false ) ;
670+ if ( ! result . success ) {
671+ expect ( result . error ) . toBe ( "setNotFound" ) ;
672+ }
673+ } ) ;
674+
675+ it ( "should return setNameRequired error when new name is empty" , async ( ) => {
676+ const existingSets = [ { buttons : [ ] , id : "set-1" , name : "SetA" } ] ;
677+ const mockConfig = createMockConfig ( ) ;
678+ mockConfig . get . mockReturnValue ( CONFIGURATION_TARGETS . WORKSPACE ) ;
679+ mockConfig . inspect . mockImplementation ( ( key : string ) => {
680+ if ( key === "buttonSets" ) {
681+ return { workspaceValue : existingSets } ;
682+ }
683+ if ( key === "activeSet" ) {
684+ return { workspaceValue : null } ;
685+ }
686+ return { } ;
687+ } ) ;
688+ jest
689+ . spyOn ( vscode . workspace , "getConfiguration" )
690+ . mockReturnValue ( mockConfig as unknown as vscode . WorkspaceConfiguration ) ;
691+
692+ const configManager = createMockConfigManager ( ) ;
693+ const configReader = createMockConfigReader ( ) ;
694+ const buttonSetWriter = createMockButtonSetWriter ( ) ;
695+
696+ const manager = ButtonSetManager . create ( configManager , configReader , buttonSetWriter ) ;
697+ const result = await manager . renameButtonSet ( "SetA" , " " ) ;
698+
699+ expect ( result . success ) . toBe ( false ) ;
700+ if ( ! result . success ) {
701+ expect ( result . error ) . toBe ( "setNameRequired" ) ;
702+ }
703+ } ) ;
704+
705+ it ( "should update active set when renaming currently active set" , async ( ) => {
706+ const existingSets = [ { buttons : [ ] , id : "set-1" , name : "SetA" } ] ;
707+ const mockConfig = createMockConfig ( ) ;
708+ mockConfig . get . mockReturnValue ( CONFIGURATION_TARGETS . WORKSPACE ) ;
709+ mockConfig . inspect . mockImplementation ( ( key : string ) => {
710+ if ( key === "buttonSets" ) {
711+ return { workspaceValue : existingSets } ;
712+ }
713+ if ( key === "activeSet" ) {
714+ return { workspaceValue : "SetA" } ;
715+ }
716+ return { } ;
717+ } ) ;
718+ jest
719+ . spyOn ( vscode . workspace , "getConfiguration" )
720+ . mockReturnValue ( mockConfig as unknown as vscode . WorkspaceConfiguration ) ;
721+
722+ const configManager = createMockConfigManager ( ) ;
723+ const configReader = createMockConfigReader ( ) ;
724+ const buttonSetWriter = createMockButtonSetWriter ( ) ;
725+
726+ const manager = ButtonSetManager . create ( configManager , configReader , buttonSetWriter ) ;
727+ const result = await manager . renameButtonSet ( "SetA" , "SetB" ) ;
728+
729+ expect ( result . success ) . toBe ( true ) ;
730+ expect ( buttonSetWriter . writeActiveSet ) . toHaveBeenCalledWith ( "SetB" , expect . anything ( ) ) ;
731+ } ) ;
732+
733+ it ( "should NOT update active set when renaming non-active set" , async ( ) => {
734+ const existingSets = [
735+ { buttons : [ ] , id : "set-1" , name : "SetA" } ,
736+ { buttons : [ ] , id : "set-2" , name : "SetB" } ,
737+ ] ;
738+ const mockConfig = createMockConfig ( ) ;
739+ mockConfig . get . mockReturnValue ( CONFIGURATION_TARGETS . WORKSPACE ) ;
740+ mockConfig . inspect . mockImplementation ( ( key : string ) => {
741+ if ( key === "buttonSets" ) {
742+ return { workspaceValue : existingSets } ;
743+ }
744+ if ( key === "activeSet" ) {
745+ return { workspaceValue : "SetA" } ;
746+ }
747+ return { } ;
748+ } ) ;
749+ jest
750+ . spyOn ( vscode . workspace , "getConfiguration" )
751+ . mockReturnValue ( mockConfig as unknown as vscode . WorkspaceConfiguration ) ;
752+
753+ const configManager = createMockConfigManager ( ) ;
754+ const configReader = createMockConfigReader ( ) ;
755+ const buttonSetWriter = createMockButtonSetWriter ( ) ;
756+
757+ const manager = ButtonSetManager . create ( configManager , configReader , buttonSetWriter ) ;
758+ const result = await manager . renameButtonSet ( "SetB" , "SetC" ) ;
759+
760+ expect ( result . success ) . toBe ( true ) ;
761+ expect ( buttonSetWriter . writeActiveSet ) . not . toHaveBeenCalled ( ) ;
762+ } ) ;
763+
645764 it ( "should detect duplicate when renaming to existing name with different case" , async ( ) => {
646765 const existingSets = [
647766 { buttons : [ ] , id : "set-1" , name : "SetA" } ,
@@ -669,7 +788,7 @@ describe("ButtonSetManager", () => {
669788 const buttonSetWriter = createMockButtonSetWriter ( ) ;
670789
671790 const manager = ButtonSetManager . create ( configManager , configReader , buttonSetWriter ) ;
672- const result = await manager . updateButtonSet ( "set-1 ", { name : "SETB" } ) ;
791+ const result = await manager . renameButtonSet ( "SetA ", "SETB" ) ;
673792
674793 expect ( result . success ) . toBe ( false ) ;
675794 if ( ! result . success ) {
@@ -704,7 +823,7 @@ describe("ButtonSetManager", () => {
704823 const buttonSetWriter = createMockButtonSetWriter ( ) ;
705824
706825 const manager = ButtonSetManager . create ( configManager , configReader , buttonSetWriter ) ;
707- const result = await manager . updateButtonSet ( "set-1 ", { name : "SETA" } ) ;
826+ const result = await manager . renameButtonSet ( "SetA ", "SETA" ) ;
708827
709828 expect ( result . success ) . toBe ( true ) ;
710829 expect ( buttonSetWriter . writeButtonSets ) . toHaveBeenCalled ( ) ;
0 commit comments