@@ -14,8 +14,11 @@ import {
1414 filterCommandPaletteGroups ,
1515 findHighlightedCommandPaletteItem ,
1616 reduceCommandPaletteUiState ,
17+ createCommandPaletteSearchState ,
18+ reduceCommandPaletteSearchState ,
1719 type CommandPaletteActionItem ,
1820 type CommandPaletteGroup ,
21+ type CommandPaletteUiState ,
1922} from "./CommandPalette.logic" ;
2023
2124describe ( "linked pull request thread navigation" , ( ) => {
@@ -894,3 +897,95 @@ describe("virtualized command palette rows", () => {
894897 expect ( findHighlightedCommandPaletteItem ( groups , null ) ) . toBeNull ( ) ;
895898 } ) ;
896899} ) ;
900+
901+ describe ( "command palette search return" , ( ) => {
902+ const picker = { addonIcon : null , groups : [ ] } ;
903+
904+ it ( "Back restores the query that led into each nested picker" , ( ) => {
905+ let state = createCommandPaletteSearchState ( ">new thread" ) ;
906+ state = reduceCommandPaletteSearchState ( state , { type : "push" , view : picker } ) ;
907+ expect ( state . query ) . toBe ( "" ) ;
908+ state = reduceCommandPaletteSearchState ( state , { type : "query" , query : "remote project" } ) ;
909+ state = reduceCommandPaletteSearchState ( state , {
910+ type : "push" ,
911+ view : { ...picker , initialQuery : "~/" } ,
912+ } ) ;
913+ expect ( state . query ) . toBe ( "~/" ) ;
914+ state = reduceCommandPaletteSearchState ( state , { type : "back" } ) ;
915+ expect ( state . query ) . toBe ( "remote project" ) ;
916+ expect ( state . views ) . toHaveLength ( 1 ) ;
917+ state = reduceCommandPaletteSearchState ( state , { type : "back" } ) ;
918+ expect ( state ) . toEqual ( createCommandPaletteSearchState ( ">new thread" ) ) ;
919+ expect ( reduceCommandPaletteSearchState ( state , { type : "back" } ) ) . toBe ( state ) ;
920+ } ) ;
921+
922+ it ( "clearing a child's prefilled query before Back keeps the parent query" , ( ) => {
923+ let state = createCommandPaletteSearchState ( ">add project" ) ;
924+ state = reduceCommandPaletteSearchState ( state , {
925+ type : "push" ,
926+ view : { ...picker , initialQuery : "~/" } ,
927+ } ) ;
928+ state = reduceCommandPaletteSearchState ( state , { type : "query" , query : "" } ) ;
929+ state = reduceCommandPaletteSearchState ( state , { type : "back" } ) ;
930+ expect ( state . query ) . toBe ( ">add project" ) ;
931+ } ) ;
932+
933+ it ( "a reset drops the pickers it replaces" , ( ) => {
934+ const nested = reduceCommandPaletteSearchState ( createCommandPaletteSearchState ( "old" ) , {
935+ type : "push" ,
936+ view : picker ,
937+ } ) ;
938+ const reset = reduceCommandPaletteSearchState ( nested , { type : "reset" , query : "linked" } ) ;
939+ expect ( reduceCommandPaletteSearchState ( reset , { type : "back" } ) ) . toEqual (
940+ createCommandPaletteSearchState ( "linked" ) ,
941+ ) ;
942+ } ) ;
943+ } ) ;
944+
945+ describe ( "returning from file and content search" , ( ) => {
946+ const root : CommandPaletteUiState = { open : true , mode : "command" , openIntent : null } ;
947+ const context = { query : "go to file" , linkedThreadSearch : null } ;
948+
949+ it . each ( [ "files" , "content" ] as const ) ( "Escape from %s restores the palette query" , ( mode ) => {
950+ const child = reduceCommandPaletteUiState ( root , { _tag : "OpenChildSearch" , mode, context } ) ;
951+ expect ( child . mode ) . toBe ( mode ) ;
952+ const returned = reduceCommandPaletteUiState ( child , { _tag : "BackToCommand" } ) ;
953+ expect ( returned ) . toEqual ( { ...root , restoredSearch : context } ) ;
954+ } ) ;
955+
956+ it ( "restores linked-thread search results with the query" , ( ) => {
957+ const linkedContext = {
958+ query : "https://github.com/acme/web/pull/7" ,
959+ linkedThreadSearch : {
960+ kind : "search" as const ,
961+ query : "https://github.com/acme/web/pull/7" ,
962+ linkedThreads : { environmentId : EnvironmentId . make ( "remote" ) , threads : [ ] } ,
963+ } ,
964+ } ;
965+ const child = reduceCommandPaletteUiState ( root , {
966+ _tag : "OpenChildSearch" ,
967+ mode : "content" ,
968+ context : linkedContext ,
969+ } ) ;
970+ const returned = reduceCommandPaletteUiState ( child , { _tag : "BackToCommand" } ) ;
971+ expect ( returned . restoredSearch ) . toEqual ( linkedContext ) ;
972+ } ) ;
973+
974+ it ( "closing, a fresh shortcut, or a direct intent forgets the parent query" , ( ) => {
975+ const child = reduceCommandPaletteUiState ( root , {
976+ _tag : "OpenChildSearch" ,
977+ mode : "files" ,
978+ context,
979+ } ) ;
980+ const closed = reduceCommandPaletteUiState ( child , { _tag : "SetOpen" , open : false } ) ;
981+ expect ( reduceCommandPaletteUiState ( closed , { _tag : "BackToCommand" } ) ) . toBe ( closed ) ;
982+ expect ( reduceCommandPaletteUiState ( closed , { _tag : "SetOpen" , open : true } ) ) . toEqual ( root ) ;
983+
984+ const fresh = reduceCommandPaletteUiState ( child , { _tag : "ToggleMode" , mode : "content" } ) ;
985+ expect ( reduceCommandPaletteUiState ( fresh , { _tag : "BackToCommand" } ) ) . toEqual ( root ) ;
986+
987+ const direct = reduceCommandPaletteUiState ( child , { _tag : "OpenChangeTheme" } ) ;
988+ expect ( direct . parentSearch ) . toBeUndefined ( ) ;
989+ expect ( direct . restoredSearch ) . toBeUndefined ( ) ;
990+ } ) ;
991+ } ) ;
0 commit comments