Skip to content

Commit 3cd025f

Browse files
committed
Add a unit test for building repo labels
1 parent add5417 commit 3cd025f

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

extensions/ql-vscode/test/pure-tests/query-history-info.test.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { expect } from 'chai';
22

33
import { QueryStatus } from '../../src/query-status';
4-
import { getQueryHistoryItemId, getQueryText, getRawQueryName } from '../../src/query-history-info';
4+
import { buildRepoLabel, getQueryHistoryItemId, getQueryText, getRawQueryName } from '../../src/query-history-info';
55
import { VariantAnalysisHistoryItem } from '../../src/remote-queries/variant-analysis-history-item';
66
import { createMockVariantAnalysis } from '../../src/vscode-tests/factories/remote-queries/shared/variant-analysis';
7+
import { createMockScannedRepos } from '../../src/vscode-tests/factories/remote-queries/shared/scanned-repositories';
78
import { createMockLocalQueryInfo } from '../../src/vscode-tests/factories/local-queries/local-query-history-item';
89
import { createMockRemoteQueryHistoryItem } from '../../src/vscode-tests/factories/remote-queries/remote-query-history-item';
10+
import { VariantAnalysisRepoStatus, VariantAnalysisStatus } from '../../src/remote-queries/shared/variant-analysis';
911

1012
describe('Query history info', () => {
1113

@@ -18,7 +20,15 @@ describe('Query history info', () => {
1820
status: QueryStatus.InProgress,
1921
completed: false,
2022
historyItemId: 'abc123',
21-
variantAnalysis: createMockVariantAnalysis()
23+
variantAnalysis: createMockVariantAnalysis(
24+
VariantAnalysisStatus.InProgress,
25+
createMockScannedRepos([
26+
VariantAnalysisRepoStatus.Succeeded,
27+
VariantAnalysisRepoStatus.Pending,
28+
VariantAnalysisRepoStatus.InProgress,
29+
VariantAnalysisRepoStatus.Canceled,
30+
])
31+
),
2232
};
2333

2434
describe('getRawQueryName', () => {
@@ -80,4 +90,24 @@ describe('Query history info', () => {
8090
expect(queryText).to.equal(variantAnalysisHistoryItem.variantAnalysis.query.text);
8191
});
8292
});
93+
94+
describe('buildRepoLabel', () => {
95+
it('should build the repo label for remote query history items', () => {
96+
const repoLabel = buildRepoLabel(remoteQueryHistoryItem);
97+
const expectedRepoLabel = `${remoteQueryHistoryItem.remoteQuery.controllerRepository.owner}/${remoteQueryHistoryItem.remoteQuery.controllerRepository.name}`;
98+
99+
expect(repoLabel).to.equal(expectedRepoLabel);
100+
101+
const remoteQueryHistoryItem2 = createMockRemoteQueryHistoryItem({repositoryCount: 3});
102+
const repoLabel2 = buildRepoLabel(remoteQueryHistoryItem2);
103+
const expectedRepoLabel2 = '3 repositories';
104+
105+
expect(repoLabel2).to.equal(expectedRepoLabel2);
106+
});
107+
it('should build the repo label for variant analysis history items', () => {
108+
const repoLabel = buildRepoLabel(variantAnalysisHistoryItem);
109+
110+
expect(repoLabel).to.equal('2/4 repositories');
111+
});
112+
});
83113
});

0 commit comments

Comments
 (0)