Skip to content

Commit 8550778

Browse files
committed
Wrap tests for removal in handleRemoveHistoryItem describe block
Instead of having them dangle around.
1 parent f837508 commit 8550778

1 file changed

Lines changed: 65 additions & 63 deletions

File tree

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

Lines changed: 65 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -325,77 +325,79 @@ describe('query-history', () => {
325325
});
326326
});
327327

328-
it('should remove an item and not select a new one', async () => {
329-
queryHistoryManager = await createMockQueryHistory(allHistory);
330-
// initialize the selection
331-
await queryHistoryManager.treeView.reveal(allHistory[0], { select: true });
332-
333-
// deleting the first item when a different item is selected
334-
// will not change the selection
335-
const toDelete = allHistory[1];
336-
const selected = allHistory[3];
337-
338-
// select the item we want
339-
await queryHistoryManager.treeView.reveal(selected, { select: true });
340-
341-
// should be selected
342-
expect(queryHistoryManager.treeDataProvider.getCurrent()).to.deep.eq(selected);
343-
344-
// remove an item
345-
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [toDelete]);
346-
347-
if (toDelete.t == 'local') {
348-
expect(toDelete.completedQuery!.dispose).to.have.been.calledOnce;
349-
} else if (toDelete.t == 'remote') {
350-
expect(remoteQueriesManagerStub.removeRemoteQuery).to.have.been.calledOnceWith((toDelete as RemoteQueryHistoryItem).queryId);
351-
} else if (toDelete.t == 'variant-analysis') {
352-
expect(variantAnalysisManagerStub.removeVariantAnalysis).to.have.been.calledOnceWith((toDelete as VariantAnalysisHistoryItem).variantAnalysis.id);
353-
}
328+
describe('handleRemoveHistoryItem', () => {
329+
it('should remove an item and not select a new one', async () => {
330+
queryHistoryManager = await createMockQueryHistory(allHistory);
331+
// initialize the selection
332+
await queryHistoryManager.treeView.reveal(allHistory[0], { select: true });
354333

355-
// the same item should be selected
356-
if (selected.t == 'local') {
357-
expect(localQueriesResultsViewStub.showResults).to.have.been.calledOnceWith(selected);
358-
} else if (toDelete.t == 'remote') {
359-
expect(remoteQueriesManagerStub.openRemoteQueryResults).to.have.been.calledOnceWith((selected as RemoteQueryHistoryItem).queryId);
360-
} else if (toDelete.t == 'variant-analysis') {
361-
expect(variantAnalysisManagerStub.showView).to.have.been.calledOnceWith((selected as VariantAnalysisHistoryItem).variantAnalysis.id);
362-
}
334+
// deleting the first item when a different item is selected
335+
// will not change the selection
336+
const toDelete = allHistory[1];
337+
const selected = allHistory[3];
363338

364-
expect(queryHistoryManager.treeDataProvider.getCurrent()).to.deep.eq(selected);
365-
expect(queryHistoryManager.treeDataProvider.allHistory).not.to.contain(toDelete);
366-
});
339+
// select the item we want
340+
await queryHistoryManager.treeView.reveal(selected, { select: true });
367341

368-
it('should remove an item and select a new one', async () => {
369-
queryHistoryManager = await createMockQueryHistory(allHistory);
342+
// should be selected
343+
expect(queryHistoryManager.treeDataProvider.getCurrent()).to.deep.eq(selected);
370344

371-
// deleting the selected item automatically selects next item
372-
const toDelete = allHistory[1];
373-
const newSelected = allHistory[2];
374-
// avoid triggering the callback by setting the field directly
345+
// remove an item
346+
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [toDelete]);
375347

376-
// select the item we want
377-
await queryHistoryManager.treeView.reveal(toDelete, { select: true });
378-
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [toDelete]);
348+
if (toDelete.t == 'local') {
349+
expect(toDelete.completedQuery!.dispose).to.have.been.calledOnce;
350+
} else if (toDelete.t == 'remote') {
351+
expect(remoteQueriesManagerStub.removeRemoteQuery).to.have.been.calledOnceWith((toDelete as RemoteQueryHistoryItem).queryId);
352+
} else if (toDelete.t == 'variant-analysis') {
353+
expect(variantAnalysisManagerStub.removeVariantAnalysis).to.have.been.calledOnceWith((toDelete as VariantAnalysisHistoryItem).variantAnalysis.id);
354+
}
379355

380-
if (toDelete.t == 'local') {
381-
expect(toDelete.completedQuery!.dispose).to.have.been.calledOnce;
382-
} else if (toDelete.t == 'remote') {
383-
expect(remoteQueriesManagerStub.removeRemoteQuery).to.have.been.calledOnceWith((toDelete as RemoteQueryHistoryItem).queryId);
384-
} else if (toDelete.t == 'variant-analysis') {
385-
expect(variantAnalysisManagerStub.removeVariantAnalysis).to.have.been.calledOnceWith((toDelete as VariantAnalysisHistoryItem).variantAnalysis.id);
386-
}
356+
// the same item should be selected
357+
if (selected.t == 'local') {
358+
expect(localQueriesResultsViewStub.showResults).to.have.been.calledOnceWith(selected);
359+
} else if (toDelete.t == 'remote') {
360+
expect(remoteQueriesManagerStub.openRemoteQueryResults).to.have.been.calledOnceWith((selected as RemoteQueryHistoryItem).queryId);
361+
} else if (toDelete.t == 'variant-analysis') {
362+
expect(variantAnalysisManagerStub.showView).to.have.been.calledOnceWith((selected as VariantAnalysisHistoryItem).variantAnalysis.id);
363+
}
387364

388-
// the current item should have been selected
389-
if (newSelected.t == 'local') {
390-
expect(localQueriesResultsViewStub.showResults).to.have.been.calledOnceWith(newSelected);
391-
} else if (toDelete.t == 'remote') {
392-
expect(remoteQueriesManagerStub.openRemoteQueryResults).to.have.been.calledOnceWith((newSelected as RemoteQueryHistoryItem).queryId);
393-
} else if (toDelete.t == 'variant-analysis') {
394-
expect(variantAnalysisManagerStub.showView).to.have.been.calledOnceWith((newSelected as VariantAnalysisHistoryItem).variantAnalysis.id);
395-
}
365+
expect(queryHistoryManager.treeDataProvider.getCurrent()).to.deep.eq(selected);
366+
expect(queryHistoryManager.treeDataProvider.allHistory).not.to.contain(toDelete);
367+
});
368+
369+
it('should remove an item and select a new one', async () => {
370+
queryHistoryManager = await createMockQueryHistory(allHistory);
371+
372+
// deleting the selected item automatically selects next item
373+
const toDelete = allHistory[1];
374+
const newSelected = allHistory[2];
375+
// avoid triggering the callback by setting the field directly
376+
377+
// select the item we want
378+
await queryHistoryManager.treeView.reveal(toDelete, { select: true });
379+
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [toDelete]);
380+
381+
if (toDelete.t == 'local') {
382+
expect(toDelete.completedQuery!.dispose).to.have.been.calledOnce;
383+
} else if (toDelete.t == 'remote') {
384+
expect(remoteQueriesManagerStub.removeRemoteQuery).to.have.been.calledOnceWith((toDelete as RemoteQueryHistoryItem).queryId);
385+
} else if (toDelete.t == 'variant-analysis') {
386+
expect(variantAnalysisManagerStub.removeVariantAnalysis).to.have.been.calledOnceWith((toDelete as VariantAnalysisHistoryItem).variantAnalysis.id);
387+
}
388+
389+
// the current item should have been selected
390+
if (newSelected.t == 'local') {
391+
expect(localQueriesResultsViewStub.showResults).to.have.been.calledOnceWith(newSelected);
392+
} else if (toDelete.t == 'remote') {
393+
expect(remoteQueriesManagerStub.openRemoteQueryResults).to.have.been.calledOnceWith((newSelected as RemoteQueryHistoryItem).queryId);
394+
} else if (toDelete.t == 'variant-analysis') {
395+
expect(variantAnalysisManagerStub.showView).to.have.been.calledOnceWith((newSelected as VariantAnalysisHistoryItem).variantAnalysis.id);
396+
}
396397

397-
expect(queryHistoryManager.treeDataProvider.getCurrent()).to.eq(newSelected);
398-
expect(queryHistoryManager.treeDataProvider.allHistory).not.to.contain(toDelete);
398+
expect(queryHistoryManager.treeDataProvider.getCurrent()).to.eq(newSelected);
399+
expect(queryHistoryManager.treeDataProvider.allHistory).not.to.contain(toDelete);
400+
});
399401
});
400402

401403
describe('HistoryTreeDataProvider', () => {

0 commit comments

Comments
 (0)