@@ -2,12 +2,21 @@ import { env } from "vscode";
22import { QueryHistoryConfig } from "../../../../src/config" ;
33import { HistoryItemLabelProvider } from "../../../../src/query-history/history-item-label-provider" ;
44import { createMockLocalQueryInfo } from "../../../factories/query-history/local-query-history-item" ;
5+ import { createMockVariantAnalysisHistoryItem } from "../../../factories/query-history/variant-analysis-history-item" ;
6+ import { QueryStatus } from "../../../../src/query-status" ;
7+ import {
8+ VariantAnalysisRepoStatus ,
9+ VariantAnalysisStatus ,
10+ } from "../../../../src/remote-queries/shared/variant-analysis" ;
11+ import { createMockVariantAnalysis } from "../../../factories/remote-queries/shared/variant-analysis" ;
12+ import { createMockScannedRepos } from "../../../factories/remote-queries/shared/scanned-repositories" ;
513
614describe ( "HistoryItemLabelProvider" , ( ) => {
715 let labelProvider : HistoryItemLabelProvider ;
816 let config : QueryHistoryConfig ;
917 const date = new Date ( "2022-01-01T00:00:00.000Z" ) ;
1018 const dateStr = date . toLocaleString ( env . language ) ;
19+ const executionStartTime = date . getTime ( ) ;
1120 const userSpecifiedLabel = "user-specified-name" ;
1221
1322 beforeEach ( ( ) => {
@@ -82,4 +91,170 @@ describe("HistoryItemLabelProvider", () => {
8291 expect ( labelProvider . getShortLabel ( fqi2 ) ) . toBe ( "query-file.ql" ) ;
8392 } ) ;
8493 } ) ;
94+
95+ describe ( "variant analyses" , ( ) => {
96+ it ( "should interpolate query when user specified" , ( ) => {
97+ const fqi = createMockVariantAnalysisHistoryItem ( {
98+ userSpecifiedLabel,
99+ executionStartTime,
100+ } ) ;
101+
102+ expect ( labelProvider . getLabel ( fqi ) ) . toBe ( userSpecifiedLabel ) ;
103+
104+ fqi . userSpecifiedLabel = "%t %q %d %s %%" ;
105+ expect ( labelProvider . getLabel ( fqi ) ) . toBe (
106+ `${ dateStr } a-query-name (javascript) 1/3 repositories in progress %` ,
107+ ) ;
108+
109+ fqi . userSpecifiedLabel = "%t %q %d %s %%::%t %q %d %s %%" ;
110+ expect ( labelProvider . getLabel ( fqi ) ) . toBe (
111+ `${ dateStr } a-query-name (javascript) 1/3 repositories in progress %::${ dateStr } a-query-name (javascript) 1/3 repositories in progress %` ,
112+ ) ;
113+ } ) ;
114+
115+ it ( "should interpolate query when not user-specified" , ( ) => {
116+ const fqi = createMockVariantAnalysisHistoryItem ( {
117+ historyItemStatus : QueryStatus . Completed ,
118+ variantAnalysisStatus : VariantAnalysisStatus . Succeeded ,
119+ executionStartTime,
120+ resultCount : 16 ,
121+ } ) ;
122+
123+ expect ( labelProvider . getLabel ( fqi ) ) . toBe (
124+ "xxx a-query-name (javascript) xxx" ,
125+ ) ;
126+
127+ config . format = "%t %q %d %s %f %r %%" ;
128+ expect ( labelProvider . getLabel ( fqi ) ) . toBe (
129+ `${ dateStr } a-query-name (javascript) 1/3 repositories completed a-query-file-path (16 results) %` ,
130+ ) ;
131+
132+ config . format = "%t %q %d %s %f %r %%::%t %q %d %s %f %r %%" ;
133+ expect ( labelProvider . getLabel ( fqi ) ) . toBe (
134+ `${ dateStr } a-query-name (javascript) 1/3 repositories completed a-query-file-path (16 results) %::${ dateStr } a-query-name (javascript) 1/3 repositories completed a-query-file-path (16 results) %` ,
135+ ) ;
136+ } ) ;
137+
138+ it ( "should get query short label" , ( ) => {
139+ const fqi = createMockVariantAnalysisHistoryItem ( {
140+ historyItemStatus : QueryStatus . Completed ,
141+ variantAnalysisStatus : VariantAnalysisStatus . Succeeded ,
142+ executionStartTime,
143+ userSpecifiedLabel,
144+ } ) ;
145+
146+ // fall back on user specified if one exists.
147+ expect ( labelProvider . getShortLabel ( fqi ) ) . toBe ( "user-specified-name" ) ;
148+
149+ // use query name if no user-specified label exists
150+ const fqi2 = createMockVariantAnalysisHistoryItem ( { } ) ;
151+
152+ expect ( labelProvider . getShortLabel ( fqi2 ) ) . toBe ( "a-query-name" ) ;
153+ } ) ;
154+
155+ describe ( "when results are present" , ( ) => {
156+ it ( "should display results if there are any" , ( ) => {
157+ const fqi = createMockVariantAnalysisHistoryItem ( {
158+ historyItemStatus : QueryStatus . Completed ,
159+ resultCount : 16 ,
160+ variantAnalysis : createMockVariantAnalysis ( {
161+ status : VariantAnalysisStatus . Succeeded ,
162+ executionStartTime,
163+ scannedRepos : createMockScannedRepos ( [
164+ VariantAnalysisRepoStatus . Succeeded ,
165+ VariantAnalysisRepoStatus . Succeeded ,
166+ ] ) ,
167+ } ) ,
168+ } ) ;
169+ config . format = "%t %q %d %s %f %r %%" ;
170+ expect ( labelProvider . getLabel ( fqi ) ) . toBe (
171+ `${ dateStr } a-query-name (javascript) 2/2 repositories completed a-query-file-path (16 results) %` ,
172+ ) ;
173+ } ) ;
174+ } ) ;
175+
176+ describe ( "when results are not present" , ( ) => {
177+ it ( "should skip displaying them" , ( ) => {
178+ const fqi = createMockVariantAnalysisHistoryItem ( {
179+ historyItemStatus : QueryStatus . Completed ,
180+ resultCount : 0 ,
181+ variantAnalysis : createMockVariantAnalysis ( {
182+ status : VariantAnalysisStatus . Succeeded ,
183+ executionStartTime,
184+ scannedRepos : createMockScannedRepos ( [
185+ VariantAnalysisRepoStatus . Succeeded ,
186+ VariantAnalysisRepoStatus . Succeeded ,
187+ ] ) ,
188+ } ) ,
189+ } ) ;
190+ config . format = "%t %q %d %s %f %r %%" ;
191+ expect ( labelProvider . getLabel ( fqi ) ) . toBe (
192+ `${ dateStr } a-query-name (javascript) 2/2 repositories completed a-query-file-path %` ,
193+ ) ;
194+ } ) ;
195+ } ) ;
196+
197+ describe ( "when extra whitespace is present in the middle of the label" , ( ) => {
198+ it ( "should squash it down to a single whitespace" , ( ) => {
199+ const fqi = createMockVariantAnalysisHistoryItem ( {
200+ historyItemStatus : QueryStatus . Completed ,
201+ resultCount : 0 ,
202+ variantAnalysis : createMockVariantAnalysis ( {
203+ status : VariantAnalysisStatus . Succeeded ,
204+ executionStartTime,
205+ scannedRepos : createMockScannedRepos ( [
206+ VariantAnalysisRepoStatus . Succeeded ,
207+ VariantAnalysisRepoStatus . Succeeded ,
208+ ] ) ,
209+ } ) ,
210+ } ) ;
211+ config . format = "%t %q %d %s %f %r %%" ;
212+ expect ( labelProvider . getLabel ( fqi ) ) . toBe (
213+ `${ dateStr } a-query-name (javascript) 2/2 repositories completed a-query-file-path %` ,
214+ ) ;
215+ } ) ;
216+ } ) ;
217+
218+ describe ( "when extra whitespace is present at the start of the label" , ( ) => {
219+ it ( "should squash it down to a single whitespace" , ( ) => {
220+ const fqi = createMockVariantAnalysisHistoryItem ( {
221+ historyItemStatus : QueryStatus . Completed ,
222+ resultCount : 0 ,
223+ variantAnalysis : createMockVariantAnalysis ( {
224+ status : VariantAnalysisStatus . Succeeded ,
225+ executionStartTime,
226+ scannedRepos : createMockScannedRepos ( [
227+ VariantAnalysisRepoStatus . Succeeded ,
228+ VariantAnalysisRepoStatus . Succeeded ,
229+ ] ) ,
230+ } ) ,
231+ } ) ;
232+ config . format = " %t %q %d %s %f %r %%" ;
233+ expect ( labelProvider . getLabel ( fqi ) ) . toBe (
234+ ` ${ dateStr } a-query-name (javascript) 2/2 repositories completed a-query-file-path %` ,
235+ ) ;
236+ } ) ;
237+ } ) ;
238+
239+ describe ( "when extra whitespace is present at the end of the label" , ( ) => {
240+ it ( "should squash it down to a single whitespace" , ( ) => {
241+ const fqi = createMockVariantAnalysisHistoryItem ( {
242+ historyItemStatus : QueryStatus . Completed ,
243+ resultCount : 0 ,
244+ variantAnalysis : createMockVariantAnalysis ( {
245+ status : VariantAnalysisStatus . Succeeded ,
246+ executionStartTime,
247+ scannedRepos : createMockScannedRepos ( [
248+ VariantAnalysisRepoStatus . Succeeded ,
249+ VariantAnalysisRepoStatus . Succeeded ,
250+ ] ) ,
251+ } ) ,
252+ } ) ;
253+ config . format = "%t %q %d %s %f %r %% " ;
254+ expect ( labelProvider . getLabel ( fqi ) ) . toBe (
255+ `${ dateStr } a-query-name (javascript) 2/2 repositories completed a-query-file-path % ` ,
256+ ) ;
257+ } ) ;
258+ } ) ;
259+ } ) ;
85260} ) ;
0 commit comments