Skip to content

Commit 3547fdf

Browse files
committed
Add tests for modal behaviour
Tests whether we choose "Yes" / "No" in the new modal window. "Yes" -> remove the item and show you a toast notification "No" -> don't remove item This only shows up for in progress items.
1 parent ab0e67c commit 3547fdf

1 file changed

Lines changed: 90 additions & 3 deletions

File tree

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

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import * as ghActionsApiClient from "../../../src/remote-queries/gh-api/gh-actio
4545
import { Credentials } from "../../../src/authentication";
4646
import { QuickPickItem, TextEditor } from "vscode";
4747
import { WebviewReveal } from "../../../src/interface-utils";
48+
import * as helpers from "../../../src/helpers";
4849

4950
describe("query-history", () => {
5051
const mockExtensionLocation = join(tmpDir.name, "mock-extension-location");
@@ -589,6 +590,25 @@ describe("query-history", () => {
589590
});
590591

591592
describe("when the item is a variant analysis", () => {
593+
let showBinaryChoiceDialogSpy: jest.SpiedFunction<
594+
typeof helpers.showBinaryChoiceDialog
595+
>;
596+
let showInformationMessageWithActionSpy: jest.SpiedFunction<
597+
typeof helpers.showInformationMessageWithAction
598+
>;
599+
600+
beforeEach(() => {
601+
// Choose 'Yes' when asked "Are you sure?"
602+
showBinaryChoiceDialogSpy = jest
603+
.spyOn(helpers, "showBinaryChoiceDialog")
604+
.mockResolvedValue(true);
605+
606+
showInformationMessageWithActionSpy = jest.spyOn(
607+
helpers,
608+
"showInformationMessageWithAction",
609+
);
610+
});
611+
592612
describe("when in progress", () => {
593613
describe("when the item being removed is not selected", () => {
594614
let toDelete: VariantAnalysisHistoryItem;
@@ -618,14 +638,14 @@ describe("query-history", () => {
618638
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
619639
selected,
620640
);
641+
});
621642

643+
it("should remove the item", async () => {
622644
// remove an item
623645
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
624646
toDelete,
625647
]);
626-
});
627648

628-
it("should remove the item", () => {
629649
expect(
630650
variantAnalysisManagerStub.removeVariantAnalysis,
631651
).toHaveBeenCalledWith(toDelete.variantAnalysis);
@@ -634,14 +654,67 @@ describe("query-history", () => {
634654
).not.toContain(toDelete);
635655
});
636656

637-
it("should not change the selection", () => {
657+
it("should not change the selection", async () => {
658+
// remove an item
659+
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
660+
toDelete,
661+
]);
662+
638663
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
639664
selected,
640665
);
641666
expect(variantAnalysisManagerStub.showView).toHaveBeenCalledWith(
642667
selected.variantAnalysis.id,
643668
);
644669
});
670+
671+
it("should show a modal asking 'Are you sure?'", async () => {
672+
// remove an item
673+
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
674+
toDelete,
675+
]);
676+
677+
expect(showBinaryChoiceDialogSpy).toHaveBeenCalledWith(
678+
"You are about to delete this query: query-name. Are you sure?",
679+
);
680+
});
681+
682+
it("should show a toast notification with a link to GitHub Actions", async () => {
683+
// remove an item
684+
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
685+
toDelete,
686+
]);
687+
688+
expect(showInformationMessageWithActionSpy).toHaveBeenCalled();
689+
});
690+
691+
describe("when you choose 'No' in the 'Are you sure?' modal", () => {
692+
beforeEach(async () => {
693+
showBinaryChoiceDialogSpy.mockResolvedValue(false);
694+
});
695+
696+
it("should not delete the item", async () => {
697+
// remove an item
698+
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
699+
toDelete,
700+
]);
701+
702+
expect(
703+
queryHistoryManager.treeDataProvider.allHistory,
704+
).toContain(toDelete);
705+
});
706+
707+
it("should not show a toast notification", async () => {
708+
// remove an item
709+
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
710+
toDelete,
711+
]);
712+
713+
expect(
714+
showInformationMessageWithActionSpy,
715+
).not.toHaveBeenCalled();
716+
});
717+
});
645718
});
646719

647720
describe("when the item being removed is selected", () => {
@@ -683,6 +756,12 @@ describe("query-history", () => {
683756
newSelected.variantAnalysis.id,
684757
);
685758
});
759+
760+
it("should show a modal asking 'Are you sure?'", () => {
761+
expect(showBinaryChoiceDialogSpy).toHaveBeenCalledWith(
762+
"You are about to delete this query: query-name. Are you sure?",
763+
);
764+
});
686765
});
687766
});
688767

@@ -739,6 +818,10 @@ describe("query-history", () => {
739818
selected.variantAnalysis.id,
740819
);
741820
});
821+
822+
it("should not show a modal asking 'Are you sure?'", () => {
823+
expect(showBinaryChoiceDialogSpy).not.toHaveBeenCalled();
824+
});
742825
});
743826

744827
describe("when the item being removed is selected", () => {
@@ -780,6 +863,10 @@ describe("query-history", () => {
780863
newSelected.variantAnalysis.id,
781864
);
782865
});
866+
867+
it("should not show a modal asking 'Are you sure?'", () => {
868+
expect(showBinaryChoiceDialogSpy).not.toHaveBeenCalled();
869+
});
783870
});
784871
});
785872
});

0 commit comments

Comments
 (0)