@@ -4,8 +4,11 @@ import {
44 env ,
55 extensions ,
66 QuickPickItem ,
7+ TextDocument ,
8+ TextEditor ,
79 Uri ,
810 window ,
11+ workspace ,
912} from "vscode" ;
1013import { CodeQLExtensionInterface } from "../../../extension" ;
1114import { extLogger } from "../../../common" ;
@@ -1121,4 +1124,94 @@ describe("Variant Analysis Manager", () => {
11211124 } ) ;
11221125 } ) ;
11231126 } ) ;
1127+
1128+ describe ( "openQueryText" , ( ) => {
1129+ let variantAnalysis : VariantAnalysis ;
1130+ let variantAnalysisStorageLocation : string ;
1131+
1132+ let showTextDocumentSpy : jest . SpiedFunction < typeof window . showTextDocument > ;
1133+ let openTextDocumentSpy : jest . SpiedFunction <
1134+ typeof workspace . openTextDocument
1135+ > ;
1136+
1137+ beforeEach ( async ( ) => {
1138+ variantAnalysis = createMockVariantAnalysis ( { } ) ;
1139+
1140+ variantAnalysisStorageLocation =
1141+ variantAnalysisManager . getVariantAnalysisStorageLocation (
1142+ variantAnalysis . id ,
1143+ ) ;
1144+ await createTimestampFile ( variantAnalysisStorageLocation ) ;
1145+ await variantAnalysisManager . rehydrateVariantAnalysis ( variantAnalysis ) ;
1146+
1147+ showTextDocumentSpy = jest
1148+ . spyOn ( window , "showTextDocument" )
1149+ . mockResolvedValue ( undefined as unknown as TextEditor ) ;
1150+ openTextDocumentSpy = jest
1151+ . spyOn ( workspace , "openTextDocument" )
1152+ . mockResolvedValue ( undefined as unknown as TextDocument ) ;
1153+ } ) ;
1154+
1155+ afterEach ( ( ) => {
1156+ fs . rmSync ( variantAnalysisStorageLocation , { recursive : true } ) ;
1157+ } ) ;
1158+
1159+ it ( "opens the query text" , async ( ) => {
1160+ await variantAnalysisManager . openQueryText ( variantAnalysis . id ) ;
1161+
1162+ expect ( showTextDocumentSpy ) . toHaveBeenCalledTimes ( 1 ) ;
1163+ expect ( openTextDocumentSpy ) . toHaveBeenCalledTimes ( 1 ) ;
1164+
1165+ const uri : Uri = openTextDocumentSpy . mock . calls [ 0 ] [ 0 ] as Uri ;
1166+ expect ( uri . scheme ) . toEqual ( "codeql-variant-analysis" ) ;
1167+ expect ( uri . path ) . toEqual ( variantAnalysis . query . filePath ) ;
1168+ const params = new URLSearchParams ( uri . query ) ;
1169+ expect ( Array . from ( params . keys ( ) ) ) . toEqual ( [ "variantAnalysisId" ] ) ;
1170+ expect ( params . get ( "variantAnalysisId" ) ) . toEqual (
1171+ variantAnalysis . id . toString ( ) ,
1172+ ) ;
1173+ } ) ;
1174+ } ) ;
1175+
1176+ describe ( "openQueryFile" , ( ) => {
1177+ let variantAnalysis : VariantAnalysis ;
1178+ let variantAnalysisStorageLocation : string ;
1179+
1180+ let showTextDocumentSpy : jest . SpiedFunction < typeof window . showTextDocument > ;
1181+ let openTextDocumentSpy : jest . SpiedFunction <
1182+ typeof workspace . openTextDocument
1183+ > ;
1184+
1185+ beforeEach ( async ( ) => {
1186+ variantAnalysis = createMockVariantAnalysis ( { } ) ;
1187+
1188+ variantAnalysisStorageLocation =
1189+ variantAnalysisManager . getVariantAnalysisStorageLocation (
1190+ variantAnalysis . id ,
1191+ ) ;
1192+ await createTimestampFile ( variantAnalysisStorageLocation ) ;
1193+ await variantAnalysisManager . rehydrateVariantAnalysis ( variantAnalysis ) ;
1194+
1195+ showTextDocumentSpy = jest
1196+ . spyOn ( window , "showTextDocument" )
1197+ . mockResolvedValue ( undefined as unknown as TextEditor ) ;
1198+ openTextDocumentSpy = jest
1199+ . spyOn ( workspace , "openTextDocument" )
1200+ . mockResolvedValue ( undefined as unknown as TextDocument ) ;
1201+ } ) ;
1202+
1203+ afterEach ( ( ) => {
1204+ fs . rmSync ( variantAnalysisStorageLocation , { recursive : true } ) ;
1205+ } ) ;
1206+
1207+ it ( "opens the query file" , async ( ) => {
1208+ await variantAnalysisManager . openQueryFile ( variantAnalysis . id ) ;
1209+
1210+ expect ( showTextDocumentSpy ) . toHaveBeenCalledTimes ( 1 ) ;
1211+ expect ( openTextDocumentSpy ) . toHaveBeenCalledTimes ( 1 ) ;
1212+
1213+ const filename : string = openTextDocumentSpy . mock . calls [ 0 ] [ 0 ] as string ;
1214+ expect ( filename ) . toEqual ( variantAnalysis . query . filePath ) ;
1215+ } ) ;
1216+ } ) ;
11241217} ) ;
0 commit comments