11import * as sinon from 'sinon' ;
22import { expect } from 'chai' ;
3- import { CancellationTokenSource , commands , extensions } from 'vscode' ;
3+ import { CancellationTokenSource , commands , env , extensions } from 'vscode' ;
44import { CodeQLExtensionInterface } from '../../../extension' ;
55import { logger } from '../../../logging' ;
66import * as config from '../../../config' ;
@@ -16,7 +16,10 @@ import { storagePath } from '../global.helper';
1616import { VariantAnalysisResultsManager } from '../../../remote-queries/variant-analysis-results-manager' ;
1717import { createMockVariantAnalysis } from '../../factories/remote-queries/shared/variant-analysis' ;
1818import * as VariantAnalysisModule from '../../../remote-queries/shared/variant-analysis' ;
19- import { createMockScannedRepos } from '../../factories/remote-queries/shared/scanned-repositories' ;
19+ import {
20+ createMockScannedRepo ,
21+ createMockScannedRepos
22+ } from '../../factories/remote-queries/shared/scanned-repositories' ;
2023import {
2124 VariantAnalysis ,
2225 VariantAnalysisScannedRepository ,
@@ -142,7 +145,9 @@ describe('Variant Analysis Manager', async function() {
142145 } ) ;
143146
144147 describe ( 'when credentials are invalid' , async ( ) => {
145- beforeEach ( async ( ) => { sandbox . stub ( Credentials , 'initialize' ) . resolves ( undefined ) ; } ) ;
148+ beforeEach ( async ( ) => {
149+ sandbox . stub ( Credentials , 'initialize' ) . resolves ( undefined ) ;
150+ } ) ;
146151
147152 it ( 'should return early if credentials are wrong' , async ( ) => {
148153 try {
@@ -585,4 +590,121 @@ describe('Variant Analysis Manager', async function() {
585590 } ) ;
586591 } ) ;
587592 } ) ;
593+
594+ describe ( 'copyRepoListToClipboard' , async ( ) => {
595+ let variantAnalysis : VariantAnalysis ;
596+ let variantAnalysisStorageLocation : string ;
597+
598+ let writeTextStub : sinon . SinonStub ;
599+
600+ beforeEach ( async ( ) => {
601+ variantAnalysis = createMockVariantAnalysis ( { } ) ;
602+
603+ variantAnalysisStorageLocation = variantAnalysisManager . getVariantAnalysisStorageLocation ( variantAnalysis . id ) ;
604+ await createTimestampFile ( variantAnalysisStorageLocation ) ;
605+ await variantAnalysisManager . rehydrateVariantAnalysis ( variantAnalysis ) ;
606+
607+ writeTextStub = sinon . stub ( ) ;
608+ sinon . stub ( env , 'clipboard' ) . value ( {
609+ writeText : writeTextStub ,
610+ } ) ;
611+ } ) ;
612+
613+ afterEach ( ( ) => {
614+ fs . rmSync ( variantAnalysisStorageLocation , { recursive : true } ) ;
615+ } ) ;
616+
617+ describe ( 'when the variant analysis does not have any repositories' , ( ) => {
618+ beforeEach ( async ( ) => {
619+ await variantAnalysisManager . rehydrateVariantAnalysis ( {
620+ ...variantAnalysis ,
621+ scannedRepos : [ ] ,
622+ } ) ;
623+ } ) ;
624+
625+ it ( 'should not copy any text' , async ( ) => {
626+ await variantAnalysisManager . copyRepoListToClipboard ( variantAnalysis . id ) ;
627+
628+ expect ( writeTextStub ) . not . to . have . been . called ;
629+ } ) ;
630+ } ) ;
631+
632+ describe ( 'when the variant analysis does not have any repositories with results' , ( ) => {
633+ beforeEach ( async ( ) => {
634+ await variantAnalysisManager . rehydrateVariantAnalysis ( {
635+ ...variantAnalysis ,
636+ scannedRepos : [
637+ {
638+ ...createMockScannedRepo ( ) ,
639+ resultCount : 0 ,
640+ } ,
641+ {
642+ ...createMockScannedRepo ( ) ,
643+ resultCount : undefined ,
644+ }
645+ ] ,
646+ } ) ;
647+ } ) ;
648+
649+ it ( 'should not copy any text' , async ( ) => {
650+ await variantAnalysisManager . copyRepoListToClipboard ( variantAnalysis . id ) ;
651+
652+ expect ( writeTextStub ) . not . to . have . been . called ;
653+ } ) ;
654+ } ) ;
655+
656+ describe ( 'when the variant analysis has repositories with results' , ( ) => {
657+ const scannedRepos = [
658+ {
659+ ...createMockScannedRepo ( ) ,
660+ resultCount : 100 ,
661+ } ,
662+ {
663+ ...createMockScannedRepo ( ) ,
664+ resultCount : 0 ,
665+ } ,
666+ {
667+ ...createMockScannedRepo ( ) ,
668+ resultCount : 200 ,
669+ } ,
670+ {
671+ ...createMockScannedRepo ( ) ,
672+ resultCount : undefined ,
673+ } ,
674+ {
675+ ...createMockScannedRepo ( ) ,
676+ resultCount : 5 ,
677+ } ,
678+ ] ;
679+
680+ beforeEach ( async ( ) => {
681+ await variantAnalysisManager . rehydrateVariantAnalysis ( {
682+ ...variantAnalysis ,
683+ scannedRepos,
684+ } ) ;
685+ } ) ;
686+
687+ it ( 'should copy text' , async ( ) => {
688+ await variantAnalysisManager . copyRepoListToClipboard ( variantAnalysis . id ) ;
689+
690+ expect ( writeTextStub ) . to . have . been . calledOnce ;
691+ } ) ;
692+
693+ it ( 'should be valid JSON when put in object' , async ( ) => {
694+ await variantAnalysisManager . copyRepoListToClipboard ( variantAnalysis . id ) ;
695+
696+ const text = writeTextStub . getCalls ( ) [ 0 ] . lastArg ;
697+
698+ const parsed = JSON . parse ( '{' + text + '}' ) ;
699+
700+ expect ( parsed ) . to . deep . eq ( {
701+ 'new-repo-list' : [
702+ scannedRepos [ 0 ] . repository . fullName ,
703+ scannedRepos [ 2 ] . repository . fullName ,
704+ scannedRepos [ 4 ] . repository . fullName ,
705+ ] ,
706+ } ) ;
707+ } ) ;
708+ } ) ;
709+ } ) ;
588710} ) ;
0 commit comments