@@ -36,6 +36,7 @@ import {
3636 showBinaryChoiceDialog ,
3737 showBinaryChoiceWithUrlDialog ,
3838 showInformationMessageWithAction ,
39+ showNeverAskAgainDialog ,
3940 walkDirectory ,
4041} from "../../../src/helpers" ;
4142import { reportStreamProgress } from "../../../src/progress" ;
@@ -528,6 +529,53 @@ describe("helpers", () => {
528529 expect ( showInformationMessageSpy ) . toHaveBeenCalledTimes ( 5 ) ;
529530 } ) ;
530531 } ) ;
532+
533+ describe ( "showNeverAskAgainDialog" , ( ) => {
534+ let showInformationMessageSpy : jest . SpiedFunction <
535+ typeof window . showInformationMessage
536+ > ;
537+
538+ beforeEach ( ( ) => {
539+ showInformationMessageSpy = jest
540+ . spyOn ( window , "showInformationMessage" )
541+ . mockResolvedValue ( undefined ) ;
542+ } ) ;
543+
544+ const resolveArg =
545+ ( index : number ) =>
546+ ( ...args : any [ ] ) =>
547+ Promise . resolve ( args [ index ] ) ;
548+
549+ const title =
550+ "We've noticed you don't have a CodeQL pack available to analyze this database. Can we set up a query pack for you?" ;
551+
552+ it ( "should show a binary choice dialog and return `Yes`" , async ( ) => {
553+ // pretend user chooses 'Yes'
554+ const yesItem = resolveArg ( 2 ) ;
555+ showInformationMessageSpy . mockImplementationOnce ( yesItem ) ;
556+
557+ const answer = await showNeverAskAgainDialog ( title ) ;
558+ expect ( answer ) . toBe ( "Yes" ) ;
559+ } ) ;
560+
561+ it ( "should show a binary choice dialog and return `No`" , async ( ) => {
562+ // pretend user chooses 'No'
563+ const noItem = resolveArg ( 3 ) ;
564+ showInformationMessageSpy . mockImplementationOnce ( noItem ) ;
565+
566+ const answer = await showNeverAskAgainDialog ( title ) ;
567+ expect ( answer ) . toBe ( "No" ) ;
568+ } ) ;
569+
570+ it ( "should show a binary choice dialog and return `No, and never ask me again`" , async ( ) => {
571+ // pretend user chooses 'No, and never ask me again'
572+ const neverAskAgainItem = resolveArg ( 4 ) ;
573+ showInformationMessageSpy . mockImplementationOnce ( neverAskAgainItem ) ;
574+
575+ const answer = await showNeverAskAgainDialog ( title ) ;
576+ expect ( answer ) . toBe ( "No, and never ask me again" ) ;
577+ } ) ;
578+ } ) ;
531579} ) ;
532580
533581describe ( "walkDirectory" , ( ) => {
0 commit comments