@@ -647,6 +647,272 @@ suite("resolveDartFrogProjectPathFromActiveTextEditor", () => {
647647 } ) ;
648648} ) ;
649649
650+ suite ( "quickPickProject" , ( ) => {
651+ let vscodeStub : any ;
652+ let quickPickProject : any ;
653+ let quickPick : any ;
654+
655+ const projectPath1 = "home/project1" ;
656+ const projectPath2 = "home/project2" ;
657+
658+ beforeEach ( ( ) => {
659+ vscodeStub = {
660+ window : {
661+ createQuickPick : sinon . stub ( ) ,
662+ } ,
663+ } ;
664+
665+ quickPickProject = proxyquire ( "../../../utils/dart-frog-project" , {
666+ vscode : vscodeStub ,
667+ } ) . quickPickProject ;
668+
669+ quickPick = sinon . stub ( ) ;
670+ vscodeStub . window . createQuickPick . returns ( quickPick ) ;
671+ quickPick . show = sinon . stub ( ) ;
672+ quickPick . dispose = sinon . stub ( ) ;
673+ quickPick . onDidChangeSelection = sinon . stub ( ) ;
674+ } ) ;
675+
676+ afterEach ( ( ) => {
677+ sinon . restore ( ) ;
678+ } ) ;
679+
680+ suite ( "placeholder" , ( ) => {
681+ test ( "is defined by default" , async ( ) => {
682+ const project = quickPickProject ( { } , [ projectPath1 , projectPath2 ] ) ;
683+
684+ const onDidChangeSelection =
685+ quickPick . onDidChangeSelection . getCall ( 0 ) . args [ 0 ] ;
686+ onDidChangeSelection ( [ ] ) ;
687+
688+ await project ;
689+
690+ assert . strictEqual ( quickPick . placeholder , "Select a Dart Frog project" ) ;
691+ } ) ;
692+
693+ test ( "can be overridden" , async ( ) => {
694+ const placeHolder = "placeholder" ;
695+ const project = quickPickProject (
696+ {
697+ placeHolder,
698+ } ,
699+ [ projectPath1 , projectPath2 ]
700+ ) ;
701+
702+ const onDidChangeSelection =
703+ quickPick . onDidChangeSelection . getCall ( 0 ) . args [ 0 ] ;
704+ onDidChangeSelection ( [ ] ) ;
705+
706+ await project ;
707+
708+ assert . strictEqual ( quickPick . placeholder , placeHolder ) ;
709+ } ) ;
710+ } ) ;
711+
712+ suite ( "ignoreFocusOut" , ( ) => {
713+ test ( "is true by default" , async ( ) => {
714+ const project = quickPickProject ( { } , [ projectPath1 , projectPath2 ] ) ;
715+
716+ const onDidChangeSelection =
717+ quickPick . onDidChangeSelection . getCall ( 0 ) . args [ 0 ] ;
718+ onDidChangeSelection ( [ ] ) ;
719+
720+ await project ;
721+
722+ assert . strictEqual ( quickPick . ignoreFocusOut , true ) ;
723+ } ) ;
724+
725+ test ( "can be overridden" , async ( ) => {
726+ const ignoreFocusOut = false ;
727+ const project = quickPickProject (
728+ {
729+ ignoreFocusOut,
730+ } ,
731+ [ projectPath1 , projectPath2 ]
732+ ) ;
733+
734+ const onDidChangeSelection =
735+ quickPick . onDidChangeSelection . getCall ( 0 ) . args [ 0 ] ;
736+ onDidChangeSelection ( [ ] ) ;
737+
738+ await project ;
739+
740+ assert . strictEqual ( quickPick . ignoreFocusOut , ignoreFocusOut ) ;
741+ } ) ;
742+ } ) ;
743+
744+ suite ( "canSelectMany" , ( ) => {
745+ test ( "is false by default" , async ( ) => {
746+ const project = quickPickProject ( { } , [ projectPath1 , projectPath2 ] ) ;
747+
748+ const onDidChangeSelection =
749+ quickPick . onDidChangeSelection . getCall ( 0 ) . args [ 0 ] ;
750+ onDidChangeSelection ( [ ] ) ;
751+
752+ await project ;
753+
754+ assert . strictEqual ( quickPick . canSelectMany , false ) ;
755+ } ) ;
756+
757+ test ( "can be overridden" , async ( ) => {
758+ const canPickMany = true ;
759+ const project = quickPickProject (
760+ {
761+ canPickMany,
762+ } ,
763+ [ projectPath1 , projectPath2 ]
764+ ) ;
765+
766+ const onDidChangeSelection =
767+ quickPick . onDidChangeSelection . getCall ( 0 ) . args [ 0 ] ;
768+ onDidChangeSelection ( [ ] ) ;
769+
770+ await project ;
771+
772+ assert . strictEqual ( quickPick . canSelectMany , canPickMany ) ;
773+ } ) ;
774+ } ) ;
775+
776+ test ( "busy is false by default" , async ( ) => {
777+ const project = quickPickProject ( { } , [ projectPath1 , projectPath2 ] ) ;
778+
779+ const onDidChangeSelection =
780+ quickPick . onDidChangeSelection . getCall ( 0 ) . args [ 0 ] ;
781+ onDidChangeSelection ( [ ] ) ;
782+
783+ await project ;
784+
785+ assert . strictEqual ( quickPick . busy , false ) ;
786+ } ) ;
787+
788+ test ( "shows appropiate items for resolved projects" , async ( ) => {
789+ const project = quickPickProject ( { } , [ projectPath1 , projectPath2 ] ) ;
790+
791+ const onDidChangeSelection =
792+ quickPick . onDidChangeSelection . getCall ( 0 ) . args [ 0 ] ;
793+ onDidChangeSelection ( [ ] ) ;
794+
795+ await project ;
796+
797+ const items = quickPick . items ;
798+
799+ sinon . assert . match ( items [ 0 ] , {
800+ label : `$(dart-frog) project1` ,
801+ description : projectPath1 ,
802+ projectPath : projectPath1 ,
803+ } ) ;
804+ sinon . assert . match ( items [ 1 ] , {
805+ label : `$(dart-frog) project2` ,
806+ description : projectPath2 ,
807+ projectPath : projectPath2 ,
808+ } ) ;
809+ } ) ;
810+
811+ test ( "shows the quick pick" , async ( ) => {
812+ const project = quickPickProject ( { } , [ projectPath1 , projectPath2 ] ) ;
813+
814+ const onDidChangeSelection =
815+ quickPick . onDidChangeSelection . getCall ( 0 ) . args [ 0 ] ;
816+ onDidChangeSelection ( [ ] ) ;
817+
818+ await project ;
819+
820+ sinon . assert . calledOnce ( quickPick . show ) ;
821+ } ) ;
822+
823+ suite ( "onDidSelectItem" , ( ) => {
824+ test ( "is called when an item is selected" , async ( ) => {
825+ const onDidSelectItem = sinon . stub ( ) ;
826+ const project = quickPickProject (
827+ {
828+ onDidSelectItem,
829+ } ,
830+ [ projectPath1 , projectPath2 ]
831+ ) ;
832+
833+ const onDidChangeSelection =
834+ quickPick . onDidChangeSelection . getCall ( 0 ) . args [ 0 ] ;
835+ onDidChangeSelection ( [ { projectPath : projectPath1 } ] ) ;
836+
837+ await project ;
838+
839+ sinon . assert . calledOnceWithExactly ( onDidSelectItem , {
840+ projectPath : projectPath1 ,
841+ } ) ;
842+ } ) ;
843+
844+ test ( "is not called when an item is dismissed" , async ( ) => {
845+ const onDidSelectItem = sinon . stub ( ) ;
846+ const project = quickPickProject (
847+ {
848+ onDidSelectItem,
849+ } ,
850+ [ projectPath1 , projectPath2 ]
851+ ) ;
852+
853+ const onDidChangeSelection =
854+ quickPick . onDidChangeSelection . getCall ( 0 ) . args [ 0 ] ;
855+ onDidChangeSelection ( undefined ) ;
856+
857+ await project ;
858+
859+ sinon . assert . notCalled ( onDidSelectItem ) ;
860+ } ) ;
861+ } ) ;
862+
863+ suite ( "dispose" , ( ) => {
864+ test ( "is called when an item is selected" , async ( ) => {
865+ const project = quickPickProject ( { } , [ projectPath1 , projectPath2 ] ) ;
866+
867+ const onDidChangeSelection =
868+ quickPick . onDidChangeSelection . getCall ( 0 ) . args [ 0 ] ;
869+ onDidChangeSelection ( [ { projectPath : projectPath1 } ] ) ;
870+
871+ await project ;
872+
873+ sinon . assert . calledOnce ( quickPick . dispose ) ;
874+ } ) ;
875+
876+ test ( "is called when an item is dismissed" , async ( ) => {
877+ const project = quickPickProject ( { } , [ projectPath1 , projectPath2 ] ) ;
878+
879+ const onDidChangeSelection =
880+ quickPick . onDidChangeSelection . getCall ( 0 ) . args [ 0 ] ;
881+ onDidChangeSelection ( undefined ) ;
882+
883+ await project ;
884+
885+ sinon . assert . calledOnce ( quickPick . dispose ) ;
886+ } ) ;
887+ } ) ;
888+
889+ suite ( "returns" , ( ) => {
890+ test ( "undefined when dismissed" , async ( ) => {
891+ const project = quickPickProject ( { } , [ projectPath1 , projectPath2 ] ) ;
892+
893+ const onDidChangeSelection =
894+ quickPick . onDidChangeSelection . getCall ( 0 ) . args [ 0 ] ;
895+ onDidChangeSelection ( undefined ) ;
896+
897+ const selection = await project ;
898+
899+ assert . strictEqual ( selection , undefined ) ;
900+ } ) ;
901+
902+ test ( "application when selected" , async ( ) => {
903+ const project = quickPickProject ( { } , [ projectPath1 , projectPath2 ] ) ;
904+
905+ const onDidChangeSelection =
906+ quickPick . onDidChangeSelection . getCall ( 0 ) . args [ 0 ] ;
907+ onDidChangeSelection ( [ { projectPath : projectPath1 } ] ) ;
908+
909+ const selection = await project ;
910+
911+ assert . strictEqual ( selection , projectPath1 ) ;
912+ } ) ;
913+ } ) ;
914+ } ) ;
915+
650916/**
651917 * Example of a pubspec.yaml file that depends on Dart Frog.
652918 *
0 commit comments