11import { expect } from 'chai' ;
22
33import { QueryStatus } from '../../src/query-status' ;
4- import { getQueryHistoryItemId , getQueryText , getRawQueryName } from '../../src/query-history-info' ;
4+ import { buildRepoLabel , getQueryHistoryItemId , getQueryText , getRawQueryName } from '../../src/query-history-info' ;
55import { VariantAnalysisHistoryItem } from '../../src/remote-queries/variant-analysis-history-item' ;
66import { createMockVariantAnalysis } from '../../src/vscode-tests/factories/remote-queries/shared/variant-analysis' ;
7+ import { createMockScannedRepos } from '../../src/vscode-tests/factories/remote-queries/shared/scanned-repositories' ;
78import { createMockLocalQueryInfo } from '../../src/vscode-tests/factories/local-queries/local-query-history-item' ;
89import { createMockRemoteQueryHistoryItem } from '../../src/vscode-tests/factories/remote-queries/remote-query-history-item' ;
10+ import { VariantAnalysisRepoStatus , VariantAnalysisStatus } from '../../src/remote-queries/shared/variant-analysis' ;
911
1012describe ( 'Query history info' , ( ) => {
1113
@@ -18,7 +20,15 @@ describe('Query history info', () => {
1820 status : QueryStatus . InProgress ,
1921 completed : false ,
2022 historyItemId : 'abc123' ,
21- variantAnalysis : createMockVariantAnalysis ( )
23+ variantAnalysis : createMockVariantAnalysis (
24+ VariantAnalysisStatus . InProgress ,
25+ createMockScannedRepos ( [
26+ VariantAnalysisRepoStatus . Succeeded ,
27+ VariantAnalysisRepoStatus . Pending ,
28+ VariantAnalysisRepoStatus . InProgress ,
29+ VariantAnalysisRepoStatus . Canceled ,
30+ ] )
31+ ) ,
2232 } ;
2333
2434 describe ( 'getRawQueryName' , ( ) => {
@@ -80,4 +90,61 @@ describe('Query history info', () => {
8090 expect ( queryText ) . to . equal ( variantAnalysisHistoryItem . variantAnalysis . query . text ) ;
8191 } ) ;
8292 } ) ;
93+
94+ describe ( 'buildRepoLabel' , ( ) => {
95+ describe ( 'repo label for remote query history items' , ( ) => {
96+ it ( 'should return controller repo when `repositoryCount` is 0' , ( ) => {
97+ const repoLabel = buildRepoLabel ( remoteQueryHistoryItem ) ;
98+ const expectedRepoLabel = `${ remoteQueryHistoryItem . remoteQuery . controllerRepository . owner } /${ remoteQueryHistoryItem . remoteQuery . controllerRepository . name } ` ;
99+
100+ expect ( repoLabel ) . to . equal ( expectedRepoLabel ) ;
101+ } ) ;
102+ it ( 'should return number of repositories when `repositoryCount` is non-zero' , ( ) => {
103+ const remoteQueryHistoryItem2 = createMockRemoteQueryHistoryItem ( { repositoryCount : 3 } ) ;
104+ const repoLabel2 = buildRepoLabel ( remoteQueryHistoryItem2 ) ;
105+ const expectedRepoLabel2 = '3 repositories' ;
106+
107+ expect ( repoLabel2 ) . to . equal ( expectedRepoLabel2 ) ;
108+ } ) ;
109+ } ) ;
110+ describe ( 'repo label for variant analysis history items' , ( ) => {
111+ it ( 'should return label when `totalScannedRepositoryCount` is 0' , ( ) => {
112+ const variantAnalysisHistoryItem0 : VariantAnalysisHistoryItem = {
113+ t : 'variant-analysis' ,
114+ status : QueryStatus . InProgress ,
115+ completed : false ,
116+ historyItemId : 'abc123' ,
117+ variantAnalysis : createMockVariantAnalysis (
118+ VariantAnalysisStatus . InProgress ,
119+ createMockScannedRepos ( [ ] )
120+ ) ,
121+ } ;
122+ const repoLabel0 = buildRepoLabel ( variantAnalysisHistoryItem0 ) ;
123+
124+ expect ( repoLabel0 ) . to . equal ( '0/0 repositories' ) ;
125+ } ) ;
126+ it ( 'should return label when `totalScannedRepositoryCount` is 1' , ( ) => {
127+ const variantAnalysisHistoryItem1 : VariantAnalysisHistoryItem = {
128+ t : 'variant-analysis' ,
129+ status : QueryStatus . InProgress ,
130+ completed : false ,
131+ historyItemId : 'abc123' ,
132+ variantAnalysis : createMockVariantAnalysis (
133+ VariantAnalysisStatus . InProgress ,
134+ createMockScannedRepos ( [
135+ VariantAnalysisRepoStatus . Pending ,
136+ ] )
137+ ) ,
138+ } ;
139+
140+ const repoLabel1 = buildRepoLabel ( variantAnalysisHistoryItem1 ) ;
141+ expect ( repoLabel1 ) . to . equal ( '0/1 repository' ) ;
142+ } ) ;
143+ it ( 'should return label when `totalScannedRepositoryCount` is greater than 1' , ( ) => {
144+ const repoLabel = buildRepoLabel ( variantAnalysisHistoryItem ) ;
145+
146+ expect ( repoLabel ) . to . equal ( '2/4 repositories' ) ;
147+ } ) ;
148+ } ) ;
149+ } ) ;
83150} ) ;
0 commit comments