Restructure handleRemoveHistoryItem tests

This will restructure the `handleRemoveHistoryItem` tests to be more
structured and easier to read.
This commit is contained in:
Koen Vlaswinkel
2022-12-08 14:01:33 +01:00
parent 502d4236ad
commit 691121d7c7

View File

@@ -58,7 +58,7 @@ describe("query-history", () => {
>; >;
const doCompareCallback = jest.fn(); const doCompareCallback = jest.fn();
let queryHistoryManager: QueryHistoryManager | undefined; let queryHistoryManager: QueryHistoryManager;
let localQueriesResultsViewStub: ResultsView; let localQueriesResultsViewStub: ResultsView;
let remoteQueriesManagerStub: RemoteQueriesManager; let remoteQueriesManagerStub: RemoteQueriesManager;
@@ -177,7 +177,6 @@ describe("query-history", () => {
afterEach(async () => { afterEach(async () => {
if (queryHistoryManager) { if (queryHistoryManager) {
queryHistoryManager.dispose(); queryHistoryManager.dispose();
queryHistoryManager = undefined;
} }
}); });
@@ -390,212 +389,297 @@ describe("query-history", () => {
}); });
describe("handleRemoveHistoryItem", () => { describe("handleRemoveHistoryItem", () => {
it("should remove an item and not select a new one", async () => { describe("when the item is a local query", () => {
queryHistoryManager = await createMockQueryHistory(localQueryHistory); describe("when the item being removed is not selected", () => {
// initialize the selection // deleting the first item when a different item is selected
await queryHistoryManager.treeView.reveal(localQueryHistory[0], { // will not change the selection
select: true, let toDelete: LocalQueryInfo;
let selected: LocalQueryInfo;
beforeEach(async () => {
toDelete = localQueryHistory[1];
selected = localQueryHistory[3];
queryHistoryManager = await createMockQueryHistory(
localQueryHistory,
);
// initialize the selection
await queryHistoryManager.treeView.reveal(localQueryHistory[0], {
select: true,
});
// select the item we want
await queryHistoryManager.treeView.reveal(selected, {
select: true,
});
// should be selected
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
selected,
);
// remove an item
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
toDelete,
]);
});
it("should remove the item", () => {
expect(toDelete.completedQuery!.dispose).toBeCalledTimes(1);
expect(queryHistoryManager.treeDataProvider.allHistory).toEqual(
expect.not.arrayContaining([toDelete]),
);
});
it("should not change the selection", () => {
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
selected,
);
expect(
localQueriesResultsViewStub.showResults,
).toHaveBeenCalledTimes(1);
expect(
localQueriesResultsViewStub.showResults,
).toHaveBeenCalledWith(selected, WebviewReveal.Forced, false);
});
}); });
// deleting the first item when a different item is selected describe("when the item being removed is selected", () => {
// will not change the selection // deleting the selected item automatically selects next item
const toDelete = localQueryHistory[1]; let toDelete: LocalQueryInfo;
const selected = localQueryHistory[3]; let newSelected: LocalQueryInfo;
// select the item we want beforeEach(async () => {
await queryHistoryManager.treeView.reveal(selected, { select: true }); toDelete = localQueryHistory[1];
newSelected = localQueryHistory[2];
// should be selected queryHistoryManager = await createMockQueryHistory(
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual( localQueryHistory,
selected, );
);
// remove an item // select the item we want
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [toDelete]); await queryHistoryManager.treeView.reveal(toDelete, {
select: true,
});
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
toDelete,
]);
});
expect(toDelete.completedQuery!.dispose).toBeCalledTimes(1); it("should remove the item", () => {
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual( expect(toDelete.completedQuery!.dispose).toBeCalledTimes(1);
selected, expect(queryHistoryManager.treeDataProvider.allHistory).toEqual(
); expect.not.arrayContaining([toDelete]),
expect(queryHistoryManager.treeDataProvider.allHistory).toEqual( );
expect.not.arrayContaining([toDelete]), });
);
// the same item should be selected it("should change the selection", () => {
expect(localQueriesResultsViewStub.showResults).toHaveBeenCalledTimes( expect(queryHistoryManager.treeDataProvider.getCurrent()).toBe(
1, newSelected,
); );
expect(localQueriesResultsViewStub.showResults).toHaveBeenCalledWith(
selected, expect(
WebviewReveal.Forced, localQueriesResultsViewStub.showResults,
false, ).toHaveBeenCalledTimes(1);
); expect(
localQueriesResultsViewStub.showResults,
).toHaveBeenCalledWith(newSelected, WebviewReveal.Forced, false);
});
});
}); });
it("should remove an item and select a new one", async () => { describe("when the item is a remote query", () => {
queryHistoryManager = await createMockQueryHistory(localQueryHistory); describe("when the item being removed is not selected", () => {
let toDelete: RemoteQueryHistoryItem;
let selected: RemoteQueryHistoryItem;
// deleting the selected item automatically selects next item beforeEach(async () => {
const toDelete = localQueryHistory[1]; // deleting the first item when a different item is selected
const newSelected = localQueryHistory[2]; // will not change the selection
// avoid triggering the callback by setting the field directly toDelete = remoteQueryHistory[1];
selected = remoteQueryHistory[3];
// select the item we want queryHistoryManager = await createMockQueryHistory(allHistory);
await queryHistoryManager.treeView.reveal(toDelete, { select: true });
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [toDelete]);
expect(toDelete.completedQuery!.dispose).toBeCalledTimes(1); // initialize the selection
expect(queryHistoryManager.treeDataProvider.getCurrent()).toBe( await queryHistoryManager.treeView.reveal(remoteQueryHistory[0], {
newSelected, select: true,
); });
expect(queryHistoryManager.treeDataProvider.allHistory).toEqual(
expect.not.arrayContaining([toDelete]),
);
// the current item should have been selected // select the item we want
expect(localQueriesResultsViewStub.showResults).toHaveBeenCalledTimes( await queryHistoryManager.treeView.reveal(selected, {
1, select: true,
); });
expect(localQueriesResultsViewStub.showResults).toHaveBeenCalledWith(
newSelected,
WebviewReveal.Forced,
false,
);
});
it("should remove a remote query item and not select a new one", async () => { // should be selected
queryHistoryManager = await createMockQueryHistory(allHistory); expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
// initialize the selection selected,
await queryHistoryManager.treeView.reveal(remoteQueryHistory[0], { );
select: true,
// remove an item
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
toDelete,
]);
});
it("should remove the item", () => {
expect(
remoteQueriesManagerStub.removeRemoteQuery,
).toHaveBeenCalledWith(toDelete.queryId);
expect(
queryHistoryManager.treeDataProvider.allHistory,
).not.toContain(toDelete);
});
it("should not change the selection", () => {
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
selected,
);
expect(
remoteQueriesManagerStub.openRemoteQueryResults,
).toHaveBeenCalledWith(selected.queryId);
});
}); });
// deleting the first item when a different item is selected describe("when the item being removed is selected", () => {
// will not change the selection let toDelete: RemoteQueryHistoryItem;
const toDelete = remoteQueryHistory[1]; let newSelected: RemoteQueryHistoryItem;
const selected = remoteQueryHistory[3];
// select the item we want beforeEach(async () => {
await queryHistoryManager.treeView.reveal(selected, { select: true }); // deleting the selected item automatically selects next item
toDelete = remoteQueryHistory[1];
newSelected = remoteQueryHistory[2];
// should be selected queryHistoryManager = await createMockQueryHistory(
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual( remoteQueryHistory,
selected, );
);
// remove an item // select the item we want
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [toDelete]); await queryHistoryManager.treeView.reveal(toDelete, {
select: true,
});
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
toDelete,
]);
});
expect(remoteQueriesManagerStub.removeRemoteQuery).toHaveBeenCalledWith( it("should remove the item", () => {
toDelete.queryId, expect(
); remoteQueriesManagerStub.removeRemoteQuery,
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual( ).toHaveBeenCalledWith(toDelete.queryId);
selected, expect(
); queryHistoryManager.treeDataProvider.allHistory,
expect(queryHistoryManager.treeDataProvider.allHistory).not.toContain( ).not.toContain(toDelete);
toDelete, });
);
// the same item should be selected it("should change the selection", () => {
expect( expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
remoteQueriesManagerStub.openRemoteQueryResults, newSelected,
).toHaveBeenCalledWith(selected.queryId); );
expect(
remoteQueriesManagerStub.openRemoteQueryResults,
).toHaveBeenCalledWith(newSelected.queryId);
});
});
}); });
it("should remove a remote query item and select a new one", async () => { describe("when the item is a variant analysis", () => {
queryHistoryManager = await createMockQueryHistory(remoteQueryHistory); describe("when the item being removed is not selected", () => {
let toDelete: VariantAnalysisHistoryItem;
let selected: VariantAnalysisHistoryItem;
// deleting the selected item automatically selects next item beforeEach(async () => {
const toDelete = remoteQueryHistory[1]; // deleting the first item when a different item is selected
const newSelected = remoteQueryHistory[2]; // will not change the selection
toDelete = variantAnalysisHistory[1];
selected = variantAnalysisHistory[3];
// select the item we want queryHistoryManager = await createMockQueryHistory(allHistory);
await queryHistoryManager.treeView.reveal(toDelete, { select: true }); // initialize the selection
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [toDelete]); await queryHistoryManager.treeView.reveal(
variantAnalysisHistory[0],
{
select: true,
},
);
expect(remoteQueriesManagerStub.removeRemoteQuery).toHaveBeenCalledWith( // select the item we want
toDelete.queryId, await queryHistoryManager.treeView.reveal(selected, {
); select: true,
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual( });
newSelected,
);
expect(queryHistoryManager.treeDataProvider.allHistory).not.toContain(
toDelete,
);
// the current item should have been selected // should be selected
expect( expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
remoteQueriesManagerStub.openRemoteQueryResults, selected,
).toHaveBeenCalledWith(newSelected.queryId); );
});
it("should remove a variant analysis item and not select a new one", async () => { // remove an item
queryHistoryManager = await createMockQueryHistory(allHistory); await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
// initialize the selection toDelete,
await queryHistoryManager.treeView.reveal(variantAnalysisHistory[0], { ]);
select: true, });
it("should remove the item", () => {
expect(
variantAnalysisManagerStub.removeVariantAnalysis,
).toHaveBeenCalledWith(toDelete.variantAnalysis);
expect(
queryHistoryManager.treeDataProvider.allHistory,
).not.toContain(toDelete);
});
it("should not change the selection", () => {
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
selected,
);
expect(variantAnalysisManagerStub.showView).toHaveBeenCalledWith(
selected.variantAnalysis.id,
);
});
}); });
// deleting the first item when a different item is selected describe("when the item being removed is selected", () => {
// will not change the selection let toDelete: VariantAnalysisHistoryItem;
const toDelete = variantAnalysisHistory[1]; let newSelected: VariantAnalysisHistoryItem;
const selected = variantAnalysisHistory[3];
// select the item we want beforeEach(async () => {
await queryHistoryManager.treeView.reveal(selected, { select: true }); // deleting the selected item automatically selects next item
toDelete = variantAnalysisHistory[1];
newSelected = variantAnalysisHistory[2];
// should be selected queryHistoryManager = await createMockQueryHistory(
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual( variantAnalysisHistory,
selected, );
);
// remove an item // select the item we want
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [toDelete]); await queryHistoryManager.treeView.reveal(toDelete, {
select: true,
});
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
toDelete,
]);
});
expect( it("should remove the item", () => {
variantAnalysisManagerStub.removeVariantAnalysis, expect(
).toHaveBeenCalledWith(toDelete.variantAnalysis); variantAnalysisManagerStub.removeVariantAnalysis,
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual( ).toHaveBeenCalledWith(toDelete.variantAnalysis);
selected, expect(
); queryHistoryManager.treeDataProvider.allHistory,
expect(queryHistoryManager.treeDataProvider.allHistory).not.toContain( ).not.toContain(toDelete);
toDelete, });
);
// the same item should be selected it.skip("should change the selection", () => {
expect(variantAnalysisManagerStub.showView).toHaveBeenCalledWith( expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
selected.variantAnalysis.id, newSelected,
); );
}); expect(variantAnalysisManagerStub.showView).toHaveBeenCalledWith(
newSelected.variantAnalysis.id,
it("should remove a variant analysis item and select a new one", async () => { );
queryHistoryManager = await createMockQueryHistory( });
variantAnalysisHistory, });
);
// deleting the selected item automatically selects next item
const toDelete = variantAnalysisHistory[1];
// const newSelected = variantAnalysisHistory[2];
// select the item we want
await queryHistoryManager.treeView.reveal(toDelete, { select: true });
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [toDelete]);
expect(
variantAnalysisManagerStub.removeVariantAnalysis,
).toHaveBeenCalledWith(toDelete.variantAnalysis);
expect(queryHistoryManager.treeDataProvider.allHistory).not.toContain(
toDelete,
);
// the current item should have been selected
// TODO: Make sure the correct item is selected
// expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
// newSelected,
// );
// expect(variantAnalysisManagerStub.showView).toHaveBeenCalledWith(
// newSelected.variantAnalysis.id,
// );
}); });
}); });