Skip to content

Commit 502d423

Browse files
committed
Add tests for removing remote queries and variant analyses
Unfortunately, one of the tests we have for local queries doesn't seem to be working for variant analyses. I'm not sure why it isn't working, but I think it's better to get the rest of the integration tests in and then figure out what's going on with that one.
1 parent 28652a2 commit 502d423

File tree

2 files changed

+137
-1
lines changed

2 files changed

+137
-1
lines changed

extensions/ql-vscode/src/vscode-tests/factories/remote-queries/remote-query-history-item.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { nanoid } from "nanoid";
12
import { RemoteQueryHistoryItem } from "../../../remote-queries/remote-query-history-item";
23
import { QueryStatus } from "../../../query-status";
34

@@ -25,7 +26,7 @@ export function createMockRemoteQueryHistoryItem({
2526
resultCount,
2627
status,
2728
completed: false,
28-
queryId: "queryId",
29+
queryId: nanoid(),
2930
remoteQuery: {
3031
queryName: "query-name",
3132
queryFilePath: "query-file.ql",

extensions/ql-vscode/src/vscode-tests/no-workspace/query-history.test.ts

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,141 @@ describe("query-history", () => {
462462
false,
463463
);
464464
});
465+
466+
it("should remove a remote query item and not select a new one", async () => {
467+
queryHistoryManager = await createMockQueryHistory(allHistory);
468+
// initialize the selection
469+
await queryHistoryManager.treeView.reveal(remoteQueryHistory[0], {
470+
select: true,
471+
});
472+
473+
// deleting the first item when a different item is selected
474+
// will not change the selection
475+
const toDelete = remoteQueryHistory[1];
476+
const selected = remoteQueryHistory[3];
477+
478+
// select the item we want
479+
await queryHistoryManager.treeView.reveal(selected, { select: true });
480+
481+
// should be selected
482+
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
483+
selected,
484+
);
485+
486+
// remove an item
487+
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [toDelete]);
488+
489+
expect(remoteQueriesManagerStub.removeRemoteQuery).toHaveBeenCalledWith(
490+
toDelete.queryId,
491+
);
492+
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
493+
selected,
494+
);
495+
expect(queryHistoryManager.treeDataProvider.allHistory).not.toContain(
496+
toDelete,
497+
);
498+
499+
// the same item should be selected
500+
expect(
501+
remoteQueriesManagerStub.openRemoteQueryResults,
502+
).toHaveBeenCalledWith(selected.queryId);
503+
});
504+
505+
it("should remove a remote query item and select a new one", async () => {
506+
queryHistoryManager = await createMockQueryHistory(remoteQueryHistory);
507+
508+
// deleting the selected item automatically selects next item
509+
const toDelete = remoteQueryHistory[1];
510+
const newSelected = remoteQueryHistory[2];
511+
512+
// select the item we want
513+
await queryHistoryManager.treeView.reveal(toDelete, { select: true });
514+
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [toDelete]);
515+
516+
expect(remoteQueriesManagerStub.removeRemoteQuery).toHaveBeenCalledWith(
517+
toDelete.queryId,
518+
);
519+
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
520+
newSelected,
521+
);
522+
expect(queryHistoryManager.treeDataProvider.allHistory).not.toContain(
523+
toDelete,
524+
);
525+
526+
// the current item should have been selected
527+
expect(
528+
remoteQueriesManagerStub.openRemoteQueryResults,
529+
).toHaveBeenCalledWith(newSelected.queryId);
530+
});
531+
532+
it("should remove a variant analysis item and not select a new one", async () => {
533+
queryHistoryManager = await createMockQueryHistory(allHistory);
534+
// initialize the selection
535+
await queryHistoryManager.treeView.reveal(variantAnalysisHistory[0], {
536+
select: true,
537+
});
538+
539+
// deleting the first item when a different item is selected
540+
// will not change the selection
541+
const toDelete = variantAnalysisHistory[1];
542+
const selected = variantAnalysisHistory[3];
543+
544+
// select the item we want
545+
await queryHistoryManager.treeView.reveal(selected, { select: true });
546+
547+
// should be selected
548+
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
549+
selected,
550+
);
551+
552+
// remove an item
553+
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [toDelete]);
554+
555+
expect(
556+
variantAnalysisManagerStub.removeVariantAnalysis,
557+
).toHaveBeenCalledWith(toDelete.variantAnalysis);
558+
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
559+
selected,
560+
);
561+
expect(queryHistoryManager.treeDataProvider.allHistory).not.toContain(
562+
toDelete,
563+
);
564+
565+
// the same item should be selected
566+
expect(variantAnalysisManagerStub.showView).toHaveBeenCalledWith(
567+
selected.variantAnalysis.id,
568+
);
569+
});
570+
571+
it("should remove a variant analysis item and select a new one", async () => {
572+
queryHistoryManager = await createMockQueryHistory(
573+
variantAnalysisHistory,
574+
);
575+
576+
// deleting the selected item automatically selects next item
577+
const toDelete = variantAnalysisHistory[1];
578+
// const newSelected = variantAnalysisHistory[2];
579+
580+
// select the item we want
581+
await queryHistoryManager.treeView.reveal(toDelete, { select: true });
582+
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [toDelete]);
583+
584+
expect(
585+
variantAnalysisManagerStub.removeVariantAnalysis,
586+
).toHaveBeenCalledWith(toDelete.variantAnalysis);
587+
expect(queryHistoryManager.treeDataProvider.allHistory).not.toContain(
588+
toDelete,
589+
);
590+
591+
// the current item should have been selected
592+
// TODO: Make sure the correct item is selected
593+
// expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
594+
// newSelected,
595+
// );
596+
// expect(variantAnalysisManagerStub.showView).toHaveBeenCalledWith(
597+
// newSelected.variantAnalysis.id,
598+
// );
599+
});
465600
});
466601

467602
describe("handleCancel", () => {

0 commit comments

Comments
 (0)