@@ -2,7 +2,7 @@ import { env } from 'vscode';
22import { expect } from 'chai' ;
33import { QueryHistoryConfig } from '../../config' ;
44import { HistoryItemLabelProvider } from '../../history-item-label-provider' ;
5- import { CompletedLocalQueryInfo , CompletedQueryInfo , InitialQueryInfo } from '../../query-results' ;
5+ import { CompletedLocalQueryInfo , CompletedQueryInfo , InitialQueryInfo , QueryHistoryInfo } from '../../query-results' ;
66import { RemoteQueryHistoryItem } from '../../remote-queries/remote-query-history-item' ;
77
88
@@ -84,7 +84,7 @@ describe('HistoryItemLabelProvider', () => {
8484
8585 describe ( 'remote queries' , ( ) => {
8686 it ( 'should interpolate query when user specified' , ( ) => {
87- const fqi = createMockRemoteQueryInfo ( 'xxx' ) ;
87+ const fqi = createMockRemoteQueryInfo ( { userSpecifiedLabel : 'xxx' } ) ;
8888
8989 expect ( labelProvider . getLabel ( fqi ) ) . to . eq ( 'xxx' ) ;
9090
@@ -95,8 +95,8 @@ describe('HistoryItemLabelProvider', () => {
9595 expect ( labelProvider . getLabel ( fqi ) ) . to . eq ( `${ dateStr } query-name (javascript) github/vscode-codeql-integration-tests in progress %::${ dateStr } query-name (javascript) github/vscode-codeql-integration-tests in progress %` ) ;
9696 } ) ;
9797
98- it ( 'should interpolate query when not user specified' , ( ) => {
99- const fqi = createMockRemoteQueryInfo ( ) ;
98+ it ( 'should interpolate query when not user- specified' , ( ) => {
99+ const fqi = createMockRemoteQueryInfo ( { } ) ;
100100
101101 expect ( labelProvider . getLabel ( fqi ) ) . to . eq ( 'xxx query-name (javascript) xxx' ) ;
102102
@@ -109,14 +109,14 @@ describe('HistoryItemLabelProvider', () => {
109109 } ) ;
110110
111111 it ( 'should use number of repositories instead of controller repo if available' , ( ) => {
112- const fqi = createMockRemoteQueryInfo ( undefined , 2 ) ;
112+ const fqi = createMockRemoteQueryInfo ( { repositoryCount : 2 } ) ;
113113
114114 config . format = '%t %q %d %s %f %r %%' ;
115115 expect ( labelProvider . getLabel ( fqi ) ) . to . eq ( `${ dateStr } query-name (javascript) 2 repositories in progress query-file.ql (16 results) %` ) ;
116116 } ) ;
117117
118118 it ( 'should get query short label' , ( ) => {
119- const fqi = createMockRemoteQueryInfo ( 'xxx' ) ;
119+ const fqi = createMockRemoteQueryInfo ( { userSpecifiedLabel : 'xxx' } ) ;
120120
121121 // fall back on user specified if one exists.
122122 expect ( labelProvider . getShortLabel ( fqi ) ) . to . eq ( 'xxx' ) ;
@@ -126,7 +126,55 @@ describe('HistoryItemLabelProvider', () => {
126126 expect ( labelProvider . getShortLabel ( fqi ) ) . to . eq ( 'query-name' ) ;
127127 } ) ;
128128
129- function createMockRemoteQueryInfo ( userSpecifiedLabel ?: string , repositoryCount ?: number ) {
129+ describe ( 'when results are present' , ( ) => {
130+ it ( 'should display results if there are any' , ( ) => {
131+ const fqi = createMockRemoteQueryInfo ( { resultCount : 16 , repositoryCount : 2 } ) ;
132+ config . format = '%t %q %d %s %f %r %%' ;
133+ expect ( labelProvider . getLabel ( fqi ) ) . to . eq ( `${ dateStr } query-name (javascript) 2 repositories in progress query-file.ql (16 results) %` ) ;
134+ } ) ;
135+ } ) ;
136+
137+ describe ( 'when results are not present' , ( ) => {
138+ it ( 'should skip displaying them' , ( ) => {
139+ const fqi = createMockRemoteQueryInfo ( { resultCount : 0 , repositoryCount : 2 } ) ;
140+ config . format = '%t %q %d %s %f %r %%' ;
141+ expect ( labelProvider . getLabel ( fqi ) ) . to . eq ( `${ dateStr } query-name (javascript) 2 repositories in progress query-file.ql %` ) ;
142+ } ) ;
143+ } ) ;
144+
145+ describe ( 'when extra whitespace is present in the middle of the label' , ( ) => {
146+ it ( 'should squash it down to a single whitespace' , ( ) => {
147+ const fqi = createMockRemoteQueryInfo ( { resultCount : 0 , repositoryCount : 2 } ) ;
148+ config . format = '%t %q %d %s %f %r %%' ;
149+ expect ( labelProvider . getLabel ( fqi ) ) . to . eq ( `${ dateStr } query-name (javascript) 2 repositories in progress query-file.ql %` ) ;
150+ } ) ;
151+ } ) ;
152+
153+ describe ( 'when extra whitespace is present at the start of the label' , ( ) => {
154+ it ( 'should squash it down to a single whitespace' , ( ) => {
155+ const fqi = createMockRemoteQueryInfo ( { resultCount : 0 , repositoryCount : 2 } ) ;
156+ config . format = ' %t %q %d %s %f %r %%' ;
157+ expect ( labelProvider . getLabel ( fqi ) ) . to . eq ( ` ${ dateStr } query-name (javascript) 2 repositories in progress query-file.ql %` ) ;
158+ } ) ;
159+ } ) ;
160+
161+ describe ( 'when extra whitespace is present at the end of the label' , ( ) => {
162+ it ( 'should squash it down to a single whitespace' , ( ) => {
163+ const fqi = createMockRemoteQueryInfo ( { resultCount : 0 , repositoryCount : 2 } ) ;
164+ config . format = '%t %q %d %s %f %r %% ' ;
165+ expect ( labelProvider . getLabel ( fqi ) ) . to . eq ( `${ dateStr } query-name (javascript) 2 repositories in progress query-file.ql % ` ) ;
166+ } ) ;
167+ } ) ;
168+
169+ function createMockRemoteQueryInfo ( {
170+ resultCount = 16 ,
171+ userSpecifiedLabel = undefined ,
172+ repositoryCount = 0
173+ } : {
174+ resultCount ?: number ;
175+ userSpecifiedLabel ?: string ;
176+ repositoryCount ?: number ;
177+ } ) : QueryHistoryInfo {
130178 return {
131179 t : 'remote' ,
132180 userSpecifiedLabel,
@@ -142,7 +190,7 @@ describe('HistoryItemLabelProvider', () => {
142190 repositoryCount,
143191 } ,
144192 status : 'in progress' ,
145- resultCount : 16 ,
193+ resultCount,
146194 } as unknown as RemoteQueryHistoryItem ;
147195 }
148196 } ) ;
0 commit comments