@@ -21,6 +21,7 @@ import {
2121import * as databaseFetcher from "../../../src/databaseFetcher" ;
2222import { createMockDB } from "../../factories/databases/databases" ;
2323import { asError } from "../../../src/pure/helpers-pure" ;
24+ import { Setting } from "../../../src/config" ;
2425
2526describe ( "SkeletonQueryWizard" , ( ) => {
2627 let mockCli : CodeQLCliServer ;
@@ -29,6 +30,7 @@ describe("SkeletonQueryWizard", () => {
2930 let dir : tmp . DirResult ;
3031 let storagePath : string ;
3132 let quickPickSpy : jest . SpiedFunction < typeof window . showQuickPick > ;
33+ let showInputBoxSpy : jest . SpiedFunction < typeof window . showInputBox > ;
3234 let generateSpy : jest . SpiedFunction <
3335 typeof QlPackGenerator . prototype . generate
3436 > ;
@@ -93,6 +95,9 @@ describe("SkeletonQueryWizard", () => {
9395 quickPickSpy = jest
9496 . spyOn ( window , "showQuickPick" )
9597 . mockResolvedValueOnce ( mockedQuickPickItem ( chosenLanguage ) ) ;
98+ showInputBoxSpy = jest
99+ . spyOn ( window , "showInputBox" )
100+ . mockResolvedValue ( storagePath ) ;
96101 generateSpy = jest
97102 . spyOn ( QlPackGenerator . prototype , "generate" )
98103 . mockResolvedValue ( undefined ) ;
@@ -493,4 +498,116 @@ describe("SkeletonQueryWizard", () => {
493498 } ) ;
494499 } ) ;
495500 } ) ;
501+
502+ describe ( "determineStoragePath" , ( ) => {
503+ it ( "should prompt the user to provide a storage path" , async ( ) => {
504+ const chosenPath = await wizard . determineStoragePath ( ) ;
505+
506+ expect ( showInputBoxSpy ) . toHaveBeenCalledWith (
507+ expect . objectContaining ( { value : storagePath } ) ,
508+ ) ;
509+ expect ( chosenPath ) . toEqual ( storagePath ) ;
510+ } ) ;
511+
512+ it ( "should write the chosen folder to settings" , async ( ) => {
513+ const updateValueSpy = jest . spyOn ( Setting . prototype , "updateValue" ) ;
514+
515+ await wizard . determineStoragePath ( ) ;
516+
517+ expect ( updateValueSpy ) . toHaveBeenCalledWith ( storagePath , 1 ) ;
518+ } ) ;
519+
520+ describe ( "when the user is using the codespace template" , ( ) => {
521+ let originalValue : any ;
522+ let storedPath : string ;
523+
524+ beforeEach ( async ( ) => {
525+ storedPath = join ( dir . name , "pickles-folder" ) ;
526+ ensureDirSync ( storedPath ) ;
527+
528+ originalValue = workspace
529+ . getConfiguration ( "codeQL.skeletonWizard" )
530+ . get ( "folder" ) ;
531+
532+ // Set isCodespacesTemplate to true to indicate we are in the codespace template
533+ await workspace
534+ . getConfiguration ( "codeQL" )
535+ . update ( "codespacesTemplate" , true ) ;
536+ } ) ;
537+
538+ afterEach ( async ( ) => {
539+ await workspace
540+ . getConfiguration ( "codeQL" )
541+ . update ( "codespacesTemplate" , originalValue ) ;
542+ } ) ;
543+
544+ it ( "should not prompt the user" , async ( ) => {
545+ const chosenPath = await wizard . determineStoragePath ( ) ;
546+
547+ expect ( showInputBoxSpy ) . not . toHaveBeenCalled ( ) ;
548+ expect ( chosenPath ) . toEqual ( storagePath ) ;
549+ } ) ;
550+ } ) ;
551+
552+ describe ( "when there is already a saved storage path in settings" , ( ) => {
553+ describe ( "when the saved storage path exists" , ( ) => {
554+ let originalValue : any ;
555+ let storedPath : string ;
556+
557+ beforeEach ( async ( ) => {
558+ storedPath = join ( dir . name , "pickles-folder" ) ;
559+ ensureDirSync ( storedPath ) ;
560+
561+ originalValue = workspace
562+ . getConfiguration ( "codeQL.skeletonWizard" )
563+ . get ( "folder" ) ;
564+ await workspace
565+ . getConfiguration ( "codeQL.skeletonWizard" )
566+ . update ( "folder" , storedPath ) ;
567+ } ) ;
568+
569+ afterEach ( async ( ) => {
570+ await workspace
571+ . getConfiguration ( "codeQL.skeletonWizard" )
572+ . update ( "folder" , originalValue ) ;
573+ } ) ;
574+
575+ it ( "should return it and not prompt the user" , async ( ) => {
576+ const chosenPath = await wizard . determineStoragePath ( ) ;
577+
578+ expect ( showInputBoxSpy ) . not . toHaveBeenCalled ( ) ;
579+ expect ( chosenPath ) . toEqual ( storedPath ) ;
580+ } ) ;
581+ } ) ;
582+
583+ describe ( "when the saved storage path does not exist" , ( ) => {
584+ let originalValue : any ;
585+ let storedPath : string ;
586+
587+ beforeEach ( async ( ) => {
588+ storedPath = join ( dir . name , "this-folder-does-not-exist" ) ;
589+
590+ originalValue = workspace
591+ . getConfiguration ( "codeQL.skeletonWizard" )
592+ . get ( "folder" ) ;
593+ await workspace
594+ . getConfiguration ( "codeQL.skeletonWizard" )
595+ . update ( "folder" , storedPath ) ;
596+ } ) ;
597+
598+ afterEach ( async ( ) => {
599+ await workspace
600+ . getConfiguration ( "codeQL.skeletonWizard" )
601+ . update ( "folder" , originalValue ) ;
602+ } ) ;
603+
604+ it ( "should prompt the user for to provide a new folder name" , async ( ) => {
605+ const chosenPath = await wizard . determineStoragePath ( ) ;
606+
607+ expect ( showInputBoxSpy ) . toHaveBeenCalled ( ) ;
608+ expect ( chosenPath ) . toEqual ( storagePath ) ;
609+ } ) ;
610+ } ) ;
611+ } ) ;
612+ } ) ;
496613} ) ;
0 commit comments