From 60e9f552dbbf0fc37ab7eb452cbb92fe4a072394 Mon Sep 17 00:00:00 2001 From: shati-patel <42641846+shati-patel@users.noreply.github.com> Date: Fri, 14 Oct 2022 16:39:26 +0100 Subject: [PATCH] Add unit tests for `query-history-info` --- .../pure-tests/query-history-info.test.ts | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 extensions/ql-vscode/test/pure-tests/query-history-info.test.ts diff --git a/extensions/ql-vscode/test/pure-tests/query-history-info.test.ts b/extensions/ql-vscode/test/pure-tests/query-history-info.test.ts new file mode 100644 index 000000000..76e067d1f --- /dev/null +++ b/extensions/ql-vscode/test/pure-tests/query-history-info.test.ts @@ -0,0 +1,43 @@ +import { expect } from 'chai'; + +import { QueryStatus } from '../../src/query-status'; +import { getRawQueryName } from '../../src/query-history-info'; +import { VariantAnalysisHistoryItem } from '../../src/remote-queries/variant-analysis-history-item'; +import { createMockVariantAnalysis } from '../../src/vscode-tests/factories/remote-queries/shared/variant-analysis'; +import { createMockLocalQueryInfo } from '../../src/vscode-tests/factories/local-queries/local-query-history-item'; +import { createMockRemoteQueryHistoryItem } from '../../src/vscode-tests/factories/remote-queries/remote-query-history-item'; + +describe('Query history info', () => { + describe('getRawQueryName', () => { + it('should get the name for local history items', () => { + const date = new Date('2022-01-01T00:00:00.000Z'); + const dateStr = date.toLocaleString(); + + const queryHistoryItem = createMockLocalQueryInfo(dateStr); + + const queryName = getRawQueryName(queryHistoryItem); + + expect(queryName).to.equal(queryHistoryItem.getQueryName()); + }); + + it('should get the name for remote query history items', () => { + const queryHistoryItem = createMockRemoteQueryHistoryItem({}); + const queryName = getRawQueryName(queryHistoryItem); + + expect(queryName).to.equal(queryHistoryItem.remoteQuery.queryName); + }); + + it('should get the name for variant analysis history items', () => { + const queryHistoryItem: VariantAnalysisHistoryItem = { + t: 'variant-analysis', + status: QueryStatus.InProgress, + completed: false, + variantAnalysis: createMockVariantAnalysis() + }; + + const queryName = getRawQueryName(queryHistoryItem); + + expect(queryName).to.equal(queryHistoryItem.variantAnalysis.query.name); + }); + }); +});