11import * as sinon from 'sinon' ;
22import { assert , expect } from 'chai' ;
3- import { CancellationTokenSource , commands , extensions , QuickPickItem , Uri , window } from 'vscode' ;
3+ import { CancellationTokenSource , commands , env , extensions , QuickPickItem , Uri , window } 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 ,
@@ -252,7 +255,9 @@ describe('Variant Analysis Manager', async function() {
252255 } ) ;
253256
254257 describe ( 'when credentials are invalid' , async ( ) => {
255- beforeEach ( async ( ) => { sandbox . stub ( Credentials , 'initialize' ) . resolves ( undefined ) ; } ) ;
258+ beforeEach ( async ( ) => {
259+ sandbox . stub ( Credentials , 'initialize' ) . resolves ( undefined ) ;
260+ } ) ;
256261
257262 it ( 'should return early if credentials are wrong' , async ( ) => {
258263 try {
@@ -695,4 +700,121 @@ describe('Variant Analysis Manager', async function() {
695700 } ) ;
696701 } ) ;
697702 } ) ;
703+
704+ describe ( 'copyRepoListToClipboard' , async ( ) => {
705+ let variantAnalysis : VariantAnalysis ;
706+ let variantAnalysisStorageLocation : string ;
707+
708+ let writeTextStub : sinon . SinonStub ;
709+
710+ beforeEach ( async ( ) => {
711+ variantAnalysis = createMockVariantAnalysis ( { } ) ;
712+
713+ variantAnalysisStorageLocation = variantAnalysisManager . getVariantAnalysisStorageLocation ( variantAnalysis . id ) ;
714+ await createTimestampFile ( variantAnalysisStorageLocation ) ;
715+ await variantAnalysisManager . rehydrateVariantAnalysis ( variantAnalysis ) ;
716+
717+ writeTextStub = sinon . stub ( ) ;
718+ sinon . stub ( env , 'clipboard' ) . value ( {
719+ writeText : writeTextStub ,
720+ } ) ;
721+ } ) ;
722+
723+ afterEach ( ( ) => {
724+ fs . rmSync ( variantAnalysisStorageLocation , { recursive : true } ) ;
725+ } ) ;
726+
727+ describe ( 'when the variant analysis does not have any repositories' , ( ) => {
728+ beforeEach ( async ( ) => {
729+ await variantAnalysisManager . rehydrateVariantAnalysis ( {
730+ ...variantAnalysis ,
731+ scannedRepos : [ ] ,
732+ } ) ;
733+ } ) ;
734+
735+ it ( 'should not copy any text' , async ( ) => {
736+ await variantAnalysisManager . copyRepoListToClipboard ( variantAnalysis . id ) ;
737+
738+ expect ( writeTextStub ) . not . to . have . been . called ;
739+ } ) ;
740+ } ) ;
741+
742+ describe ( 'when the variant analysis does not have any repositories with results' , ( ) => {
743+ beforeEach ( async ( ) => {
744+ await variantAnalysisManager . rehydrateVariantAnalysis ( {
745+ ...variantAnalysis ,
746+ scannedRepos : [
747+ {
748+ ...createMockScannedRepo ( ) ,
749+ resultCount : 0 ,
750+ } ,
751+ {
752+ ...createMockScannedRepo ( ) ,
753+ resultCount : undefined ,
754+ }
755+ ] ,
756+ } ) ;
757+ } ) ;
758+
759+ it ( 'should not copy any text' , async ( ) => {
760+ await variantAnalysisManager . copyRepoListToClipboard ( variantAnalysis . id ) ;
761+
762+ expect ( writeTextStub ) . not . to . have . been . called ;
763+ } ) ;
764+ } ) ;
765+
766+ describe ( 'when the variant analysis has repositories with results' , ( ) => {
767+ const scannedRepos = [
768+ {
769+ ...createMockScannedRepo ( ) ,
770+ resultCount : 100 ,
771+ } ,
772+ {
773+ ...createMockScannedRepo ( ) ,
774+ resultCount : 0 ,
775+ } ,
776+ {
777+ ...createMockScannedRepo ( ) ,
778+ resultCount : 200 ,
779+ } ,
780+ {
781+ ...createMockScannedRepo ( ) ,
782+ resultCount : undefined ,
783+ } ,
784+ {
785+ ...createMockScannedRepo ( ) ,
786+ resultCount : 5 ,
787+ } ,
788+ ] ;
789+
790+ beforeEach ( async ( ) => {
791+ await variantAnalysisManager . rehydrateVariantAnalysis ( {
792+ ...variantAnalysis ,
793+ scannedRepos,
794+ } ) ;
795+ } ) ;
796+
797+ it ( 'should copy text' , async ( ) => {
798+ await variantAnalysisManager . copyRepoListToClipboard ( variantAnalysis . id ) ;
799+
800+ expect ( writeTextStub ) . to . have . been . calledOnce ;
801+ } ) ;
802+
803+ it ( 'should be valid JSON when put in object' , async ( ) => {
804+ await variantAnalysisManager . copyRepoListToClipboard ( variantAnalysis . id ) ;
805+
806+ const text = writeTextStub . getCalls ( ) [ 0 ] . lastArg ;
807+
808+ const parsed = JSON . parse ( '{' + text + '}' ) ;
809+
810+ expect ( parsed ) . to . deep . eq ( {
811+ 'new-repo-list' : [
812+ scannedRepos [ 0 ] . repository . fullName ,
813+ scannedRepos [ 2 ] . repository . fullName ,
814+ scannedRepos [ 4 ] . repository . fullName ,
815+ ] ,
816+ } ) ;
817+ } ) ;
818+ } ) ;
819+ } ) ;
698820} ) ;
0 commit comments