Skip to content

Commit 718a6d6

Browse files
committed
Allow testing for multiple types of history items
At the moment our query history tests are set up to only check local queries. Let's prepare the ground to introduce remote query history items and variant analysis history items. This will allow us to expand test coverage for these other types of items.
1 parent bf1e3c1 commit 718a6d6

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { EvalLogViewer } from '../../eval-log-viewer';
2222
import { QueryRunner } from '../../queryRunner';
2323
import { QueryResultType } from '../../pure/legacy-messages';
2424
import { VariantAnalysisManager } from '../../remote-queries/variant-analysis-manager';
25+
import { QueryHistoryInfo } from '../../query-history-info';
2526

2627
describe('query-history', () => {
2728
const mockExtensionLocation = path.join(tmpDir.name, 'mock-extension-location');
@@ -122,15 +123,17 @@ describe('query-history', () => {
122123
});
123124
});
124125

125-
let allHistory: LocalQueryInfo[];
126+
let allHistory: QueryHistoryInfo[];
127+
let localQueryHistory: LocalQueryInfo[];
126128

127129
beforeEach(() => {
128-
allHistory = [
130+
localQueryHistory = [
129131
createMockFullQueryInfo('a', createMockQueryWithResults(true)),
130132
createMockFullQueryInfo('b', createMockQueryWithResults(true)),
131133
createMockFullQueryInfo('a', createMockQueryWithResults(false)),
132134
createMockFullQueryInfo('a', createMockQueryWithResults(true)),
133135
];
136+
allHistory = [...localQueryHistory];
134137
});
135138

136139
describe('findOtherQueryToCompare', () => {
@@ -255,7 +258,9 @@ describe('query-history', () => {
255258
// remove an item
256259
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [toDelete]);
257260

258-
expect(toDelete.completedQuery!.dispose).to.have.been.calledOnce;
261+
if (toDelete.t == 'local') {
262+
expect(toDelete.completedQuery!.dispose).to.have.been.calledOnce;
263+
}
259264
expect(queryHistoryManager.treeDataProvider.getCurrent()).to.deep.eq(selected);
260265
expect(queryHistoryManager.treeDataProvider.allHistory).not.to.contain(toDelete);
261266

@@ -275,7 +280,9 @@ describe('query-history', () => {
275280
await queryHistoryManager.treeView.reveal(toDelete, { select: true });
276281
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [toDelete]);
277282

278-
expect(toDelete.completedQuery!.dispose).to.have.been.calledOnce;
283+
if (toDelete.t == 'local') {
284+
expect(toDelete.completedQuery!.dispose).to.have.been.calledOnce;
285+
}
279286
expect(queryHistoryManager.treeDataProvider.getCurrent()).to.eq(newSelected);
280287
expect(queryHistoryManager.treeDataProvider.allHistory).not.to.contain(toDelete);
281288

@@ -306,30 +313,30 @@ describe('query-history', () => {
306313

307314
it('should delete compareWithItem when there are 0 items', async () => {
308315
queryHistoryManager = await createMockQueryHistory([]);
309-
queryHistoryManager.compareWithItem = allHistory[0];
316+
queryHistoryManager.compareWithItem = localQueryHistory[0];
310317
(queryHistoryManager as any).updateCompareWith([]);
311318
expect(queryHistoryManager.compareWithItem).to.be.undefined;
312319
});
313320

314321
it('should delete compareWithItem when there are more than 2 items', async () => {
315322
queryHistoryManager = await createMockQueryHistory(allHistory);
316-
queryHistoryManager.compareWithItem = allHistory[0];
317-
(queryHistoryManager as any).updateCompareWith([allHistory[0], allHistory[1], allHistory[2]]);
323+
queryHistoryManager.compareWithItem = localQueryHistory[0];
324+
(queryHistoryManager as any).updateCompareWith([localQueryHistory[0], localQueryHistory[1], localQueryHistory[2]]);
318325
expect(queryHistoryManager.compareWithItem).to.be.undefined;
319326
});
320327

321328
it('should delete compareWithItem when there are 2 items and disjoint from compareWithItem', async () => {
322329
queryHistoryManager = await createMockQueryHistory([]);
323-
queryHistoryManager.compareWithItem = allHistory[0];
324-
(queryHistoryManager as any).updateCompareWith([allHistory[1], allHistory[2]]);
330+
queryHistoryManager.compareWithItem = localQueryHistory[0];
331+
(queryHistoryManager as any).updateCompareWith([localQueryHistory[1], localQueryHistory[2]]);
325332
expect(queryHistoryManager.compareWithItem).to.be.undefined;
326333
});
327334

328335
it('should do nothing when compareWithItem exists and exactly 2 items', async () => {
329336
queryHistoryManager = await createMockQueryHistory([]);
330-
queryHistoryManager.compareWithItem = allHistory[0];
331-
(queryHistoryManager as any).updateCompareWith([allHistory[0], allHistory[1]]);
332-
expect(queryHistoryManager.compareWithItem).to.be.eq(allHistory[0]);
337+
queryHistoryManager.compareWithItem = localQueryHistory[0];
338+
(queryHistoryManager as any).updateCompareWith([localQueryHistory[0], localQueryHistory[1]]);
339+
expect(queryHistoryManager.compareWithItem).to.be.eq(localQueryHistory[0]);
333340
});
334341
});
335342

@@ -805,7 +812,7 @@ describe('query-history', () => {
805812
};
806813
}
807814

808-
async function createMockQueryHistory(allHistory: LocalQueryInfo[]) {
815+
async function createMockQueryHistory(allHistory: QueryHistoryInfo[]) {
809816
const qhm = new QueryHistoryManager(
810817
{} as QueryRunner,
811818
{} as DatabaseManager,

0 commit comments

Comments
 (0)