Don't show parentheses when results are not yet fetched

We missed a place where we needed to check if results are present
before attempting to show them.

Let's also add tests for this.
This commit is contained in:
Elena Tanasoiu
2022-07-21 18:19:35 +01:00
parent cba188b4db
commit 52484f1211
2 changed files with 18 additions and 1 deletions

View File

@@ -77,11 +77,12 @@ export class HistoryItemLabelProvider {
}
private getRemoteInterpolateReplacements(item: RemoteQueryHistoryItem): InterpolateReplacements {
const resultCount = item.resultCount ? `(${pluralize(item.resultCount, 'result', 'results')})` : '';
return {
t: new Date(item.remoteQuery.executionStartTime).toLocaleString(env.language),
q: `${item.remoteQuery.queryName} (${item.remoteQuery.language})`,
d: this.buildRepoLabel(item),
r: `(${pluralize(item.resultCount, 'result', 'results')})`,
r: resultCount,
s: item.status,
f: path.basename(item.remoteQuery.queryFilePath),
'%': '%'

View File

@@ -126,6 +126,22 @@ describe('HistoryItemLabelProvider', () => {
expect(labelProvider.getShortLabel(fqi)).to.eq('query-name');
});
describe('when results are present', () => {
it('should display results if there are any', () => {
const fqi = createMockRemoteQueryInfo({ resultCount: 16, repositoryCount: 2 });
config.format = '%t %q %d %s %f %r %%';
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name (javascript) 2 repositories in progress query-file.ql (16 results) %`);
});
});
describe('when results are not present', () => {
it('should skip displaying them', () => {
const fqi = createMockRemoteQueryInfo({ resultCount: 0, repositoryCount: 2 });
config.format = '%t %q %d %s %f %r %%';
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name (javascript) 2 repositories in progress query-file.ql %`);
});
});
function createMockRemoteQueryInfo({
resultCount = 16,
userSpecifiedLabel = undefined,