Skip to content

Commit e41dba7

Browse files
committed
Move createMockRemoteQueryHistoryItem into shared location
1 parent b2f4fec commit e41dba7

File tree

2 files changed

+41
-39
lines changed

2 files changed

+41
-39
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { RemoteQueryHistoryItem } from '../../../remote-queries/remote-query-history-item';
2+
3+
export function createMockRemoteQueryHistoryItem({
4+
date = new Date('2022-01-01T00:00:00.000Z'),
5+
resultCount = 16,
6+
userSpecifiedLabel = undefined,
7+
repositoryCount = 0,
8+
}: {
9+
date?: Date;
10+
resultCount?: number;
11+
userSpecifiedLabel?: string;
12+
repositoryCount?: number;
13+
}): RemoteQueryHistoryItem {
14+
return ({
15+
t: 'remote',
16+
userSpecifiedLabel,
17+
remoteQuery: {
18+
executionStartTime: date.getTime(),
19+
queryName: 'query-name',
20+
queryFilePath: 'query-file.ql',
21+
controllerRepository: {
22+
owner: 'github',
23+
name: 'vscode-codeql-integration-tests',
24+
},
25+
language: 'javascript',
26+
repositoryCount,
27+
},
28+
status: 'in progress',
29+
resultCount,
30+
} as unknown) as RemoteQueryHistoryItem;
31+
}

extensions/ql-vscode/src/vscode-tests/no-workspace/history-item-label-provider.test.ts

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { env } from 'vscode';
22
import { expect } from 'chai';
33
import { QueryHistoryConfig } from '../../config';
44
import { HistoryItemLabelProvider } from '../../history-item-label-provider';
5-
import { QueryHistoryInfo } from '../../query-history-info';
6-
import { RemoteQueryHistoryItem } from '../../remote-queries/remote-query-history-item';
75
import { createMockLocalQueryInfo } from '../factories/local-queries/local-query-history-item';
6+
import { createMockRemoteQueryHistoryItem } from '../factories/remote-queries/remote-query-history-item';
87

98

109
describe('HistoryItemLabelProvider', () => {
@@ -61,7 +60,7 @@ describe('HistoryItemLabelProvider', () => {
6160

6261
describe('remote queries', () => {
6362
it('should interpolate query when user specified', () => {
64-
const fqi = createMockRemoteQueryInfo({ userSpecifiedLabel: 'xxx' });
63+
const fqi = createMockRemoteQueryHistoryItem({ userSpecifiedLabel: 'xxx' });
6564

6665
expect(labelProvider.getLabel(fqi)).to.eq('xxx');
6766

@@ -73,7 +72,7 @@ describe('HistoryItemLabelProvider', () => {
7372
});
7473

7574
it('should interpolate query when not user-specified', () => {
76-
const fqi = createMockRemoteQueryInfo({});
75+
const fqi = createMockRemoteQueryHistoryItem({});
7776

7877
expect(labelProvider.getLabel(fqi)).to.eq('xxx query-name (javascript) xxx');
7978

@@ -86,14 +85,14 @@ describe('HistoryItemLabelProvider', () => {
8685
});
8786

8887
it('should use number of repositories instead of controller repo if available', () => {
89-
const fqi = createMockRemoteQueryInfo({ repositoryCount: 2 });
88+
const fqi = createMockRemoteQueryHistoryItem({ repositoryCount: 2 });
9089

9190
config.format = '%t %q %d %s %f %r %%';
9291
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name (javascript) 2 repositories in progress query-file.ql (16 results) %`);
9392
});
9493

9594
it('should get query short label', () => {
96-
const fqi = createMockRemoteQueryInfo({ userSpecifiedLabel: 'xxx' });
95+
const fqi = createMockRemoteQueryHistoryItem({ userSpecifiedLabel: 'xxx' });
9796

9897
// fall back on user specified if one exists.
9998
expect(labelProvider.getShortLabel(fqi)).to.eq('xxx');
@@ -105,70 +104,42 @@ describe('HistoryItemLabelProvider', () => {
105104

106105
describe('when results are present', () => {
107106
it('should display results if there are any', () => {
108-
const fqi = createMockRemoteQueryInfo({ resultCount: 16, repositoryCount: 2 });
107+
const fqi = createMockRemoteQueryHistoryItem({ resultCount: 16, repositoryCount: 2 });
109108
config.format = '%t %q %d %s %f %r %%';
110109
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name (javascript) 2 repositories in progress query-file.ql (16 results) %`);
111110
});
112111
});
113112

114113
describe('when results are not present', () => {
115114
it('should skip displaying them', () => {
116-
const fqi = createMockRemoteQueryInfo({ resultCount: 0, repositoryCount: 2 });
115+
const fqi = createMockRemoteQueryHistoryItem({ resultCount: 0, repositoryCount: 2 });
117116
config.format = '%t %q %d %s %f %r %%';
118117
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name (javascript) 2 repositories in progress query-file.ql %`);
119118
});
120119
});
121120

122121
describe('when extra whitespace is present in the middle of the label', () => {
123122
it('should squash it down to a single whitespace', () => {
124-
const fqi = createMockRemoteQueryInfo({ resultCount: 0, repositoryCount: 2 });
123+
const fqi = createMockRemoteQueryHistoryItem({ resultCount: 0, repositoryCount: 2 });
125124
config.format = '%t %q %d %s %f %r %%';
126125
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name (javascript) 2 repositories in progress query-file.ql %`);
127126
});
128127
});
129128

130129
describe('when extra whitespace is present at the start of the label', () => {
131130
it('should squash it down to a single whitespace', () => {
132-
const fqi = createMockRemoteQueryInfo({ resultCount: 0, repositoryCount: 2 });
131+
const fqi = createMockRemoteQueryHistoryItem({ resultCount: 0, repositoryCount: 2 });
133132
config.format = ' %t %q %d %s %f %r %%';
134133
expect(labelProvider.getLabel(fqi)).to.eq(` ${dateStr} query-name (javascript) 2 repositories in progress query-file.ql %`);
135134
});
136135
});
137136

138137
describe('when extra whitespace is present at the end of the label', () => {
139138
it('should squash it down to a single whitespace', () => {
140-
const fqi = createMockRemoteQueryInfo({ resultCount: 0, repositoryCount: 2 });
139+
const fqi = createMockRemoteQueryHistoryItem({ resultCount: 0, repositoryCount: 2 });
141140
config.format = '%t %q %d %s %f %r %% ';
142141
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name (javascript) 2 repositories in progress query-file.ql % `);
143142
});
144143
});
145-
146-
function createMockRemoteQueryInfo({
147-
resultCount = 16,
148-
userSpecifiedLabel = undefined,
149-
repositoryCount = 0
150-
}: {
151-
resultCount?: number;
152-
userSpecifiedLabel?: string;
153-
repositoryCount?: number;
154-
}): QueryHistoryInfo {
155-
return {
156-
t: 'remote',
157-
userSpecifiedLabel,
158-
remoteQuery: {
159-
executionStartTime: date.getTime(),
160-
queryName: 'query-name',
161-
queryFilePath: 'query-file.ql',
162-
controllerRepository: {
163-
owner: 'github',
164-
name: 'vscode-codeql-integration-tests'
165-
},
166-
language: 'javascript',
167-
repositoryCount,
168-
},
169-
status: 'in progress',
170-
resultCount,
171-
} as unknown as RemoteQueryHistoryItem;
172-
}
173144
});
174145
});

0 commit comments

Comments
 (0)