Use standard configuration variable format for history item labels

This commit is contained in:
Koen Vlaswinkel
2024-11-08 13:40:40 +01:00
parent b44c6024f4
commit eeeeadd06d
3 changed files with 500 additions and 223 deletions

View File

@@ -302,8 +302,8 @@
"properties": { "properties": {
"codeQL.queryHistory.format": { "codeQL.queryHistory.format": {
"type": "string", "type": "string",
"default": "%q on %d - %s %r [%t]", "default": "${queryName} on ${databaseName} - ${status} ${resultCount} [${startTime}]",
"markdownDescription": "Default string for how to label query history items.\n* %t is the time of the query\n* %q is the human-readable query name\n* %f is the query file name\n* %d is the database name\n* %r is the number of results\n* %s is a status string" "markdownDescription": "Default string for how to label query history items.\n\nThe following variables are supported:\n* **${startTime}** - the time of the query\n* **${queryName}** - the human-readable query name\n* **${queryFileBasename}** - the query file's base name\n* **${queryLanguage}** - the query language\n* **${databaseName}** - the database name\n* **${resultCount}** - the number of results\n* **${status}** - a status string"
}, },
"codeQL.queryHistory.ttl": { "codeQL.queryHistory.ttl": {
"type": "number", "type": "number",

View File

@@ -12,17 +12,36 @@ import type { VariantAnalysisHistoryItem } from "./variant-analysis-history-item
import { assertNever } from "../common/helpers-pure"; import { assertNever } from "../common/helpers-pure";
import { pluralize } from "../common/word"; import { pluralize } from "../common/word";
import { humanizeQueryStatus } from "./query-status"; import { humanizeQueryStatus } from "./query-status";
import { substituteConfigVariables } from "../common/config-template";
interface InterpolateReplacements { type LabelVariables = {
t: string; // Start time startTime: string;
q: string; // Query name queryName: string;
d: string; // Database/repositories count databaseName: string;
r: string; // Result count/Empty resultCount: string;
s: string; // Status status: string;
f: string; // Query file name queryFileBasename: string;
l: string; // Query language queryLanguage: string;
"%": "%"; // Percent sign };
}
const legacyVariableInterpolateReplacements: Record<
keyof LabelVariables,
string
> = {
startTime: "t",
queryName: "q",
databaseName: "d",
resultCount: "r",
status: "s",
queryFileBasename: "f",
queryLanguage: "l",
};
// If any of the "legacy" variables are used, we need to use legacy interpolation.
const legacyLabelRegex = new RegExp(
`%([${Object.values(legacyVariableInterpolateReplacements).join("")}%])`,
"g",
);
export class HistoryItemLabelProvider { export class HistoryItemLabelProvider {
constructor(private config: QueryHistoryConfig) { constructor(private config: QueryHistoryConfig) {
@@ -30,21 +49,26 @@ export class HistoryItemLabelProvider {
} }
getLabel(item: QueryHistoryInfo) { getLabel(item: QueryHistoryInfo) {
let replacements: InterpolateReplacements; let variables: LabelVariables;
switch (item.t) { switch (item.t) {
case "local": case "local":
replacements = this.getLocalInterpolateReplacements(item); variables = this.getLocalVariables(item);
break; break;
case "variant-analysis": case "variant-analysis":
replacements = this.getVariantAnalysisInterpolateReplacements(item); variables = this.getVariantAnalysisVariables(item);
break; break;
default: default:
assertNever(item); assertNever(item);
} }
const rawLabel = item.userSpecifiedLabel ?? (this.config.format || "%q"); const rawLabel =
item.userSpecifiedLabel ?? (this.config.format || "${queryName}");
return this.interpolate(rawLabel, replacements); if (legacyLabelRegex.test(rawLabel)) {
return this.legacyInterpolate(rawLabel, variables);
}
return substituteConfigVariables(rawLabel, variables).replace(/\s+/g, " ");
} }
/** /**
@@ -59,55 +83,60 @@ export class HistoryItemLabelProvider {
: getRawQueryName(item); : getRawQueryName(item);
} }
private interpolate( private legacyInterpolate(
rawLabel: string, rawLabel: string,
replacements: InterpolateReplacements, variables: LabelVariables,
): string { ): string {
const label = rawLabel.replace( const replacements = Object.entries(variables).reduce(
/%(.)/g, (acc, [key, value]) => {
(match, key: keyof InterpolateReplacements) => { acc[
const replacement = replacements[key]; legacyVariableInterpolateReplacements[key as keyof LabelVariables]
return replacement !== undefined ? replacement : match; ] = value;
return acc;
}, },
{
"%": "%",
} as Record<string, string>,
); );
const label = rawLabel.replace(/%(.)/g, (match, key: string) => {
const replacement = replacements[key];
return replacement !== undefined ? replacement : match;
});
return label.replace(/\s+/g, " "); return label.replace(/\s+/g, " ");
} }
private getLocalInterpolateReplacements( private getLocalVariables(item: LocalQueryInfo): LabelVariables {
item: LocalQueryInfo,
): InterpolateReplacements {
const { resultCount = 0, message = "in progress" } = const { resultCount = 0, message = "in progress" } =
item.completedQuery || {}; item.completedQuery || {};
return { return {
t: item.startTime, startTime: item.startTime,
q: item.getQueryName(), queryName: item.getQueryName(),
d: item.databaseName, databaseName: item.databaseName,
r: `(${resultCount} results)`, resultCount: `(${resultCount} results)`,
s: message, status: message,
f: item.getQueryFileName(), queryFileBasename: item.getQueryFileName(),
l: this.getLanguageLabel(item), queryLanguage: this.getLanguageLabel(item),
"%": "%",
}; };
} }
private getVariantAnalysisInterpolateReplacements( private getVariantAnalysisVariables(
item: VariantAnalysisHistoryItem, item: VariantAnalysisHistoryItem,
): InterpolateReplacements { ): LabelVariables {
const resultCount = item.resultCount const resultCount = item.resultCount
? `(${pluralize(item.resultCount, "result", "results")})` ? `(${pluralize(item.resultCount, "result", "results")})`
: ""; : "";
return { return {
t: new Date(item.variantAnalysis.executionStartTime).toLocaleString( startTime: new Date(
env.language, item.variantAnalysis.executionStartTime,
), ).toLocaleString(env.language),
q: `${item.variantAnalysis.query.name} (${item.variantAnalysis.language})`, queryName: `${item.variantAnalysis.query.name} (${item.variantAnalysis.language})`,
d: buildRepoLabel(item), databaseName: buildRepoLabel(item),
r: resultCount, resultCount,
s: humanizeQueryStatus(item.status), status: humanizeQueryStatus(item.status),
f: basename(item.variantAnalysis.query.filePath), queryFileBasename: basename(item.variantAnalysis.query.filePath),
l: this.getLanguageLabel(item), queryLanguage: this.getLanguageLabel(item),
"%": "%",
}; };
} }

View File

@@ -21,241 +21,489 @@ describe("HistoryItemLabelProvider", () => {
beforeEach(() => { beforeEach(() => {
config = { config = {
format: "xxx %q xxx", format: "xxx ${queryName} xxx",
ttlInMillis: 0, ttlInMillis: 0,
onDidChangeConfiguration: jest.fn(), onDidChangeConfiguration: jest.fn(),
}; };
labelProvider = new HistoryItemLabelProvider(config); labelProvider = new HistoryItemLabelProvider(config);
}); });
describe("local queries", () => { describe("modern format", () => {
it("should interpolate query when user specified", () => { describe("local queries", () => {
const fqi = createMockLocalQueryInfo({ it("should interpolate query when user specified", () => {
startTime: date, const fqi = createMockLocalQueryInfo({
userSpecifiedLabel, startTime: date,
resultCount: 456, userSpecifiedLabel,
hasMetadata: true, resultCount: 456,
hasMetadata: true,
});
expect(labelProvider.getLabel(fqi)).toBe("user-specified-name");
fqi.userSpecifiedLabel =
"${startTime} ${queryName} ${databaseName} ${status} ${queryFileBasename} ${resultCount} %";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %`,
);
fqi.userSpecifiedLabel = "%t %q %d %s %f %r %%::%t %q %d %s %f %r %%";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %::${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %`,
);
}); });
expect(labelProvider.getLabel(fqi)).toBe("user-specified-name"); it("should interpolate query when not user specified", () => {
const fqi = createMockLocalQueryInfo({
startTime: date,
resultCount: 456,
hasMetadata: true,
});
fqi.userSpecifiedLabel = "%t %q %d %s %f %r %%"; expect(labelProvider.getLabel(fqi)).toBe("xxx query-name xxx");
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %`,
);
fqi.userSpecifiedLabel = "%t %q %d %s %f %r %%::%t %q %d %s %f %r %%"; config.format =
expect(labelProvider.getLabel(fqi)).toBe( "${startTime} ${queryName} ${databaseName} ${status} ${queryFileBasename} ${resultCount} %";
`${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %::${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %`, expect(labelProvider.getLabel(fqi)).toBe(
); `${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %`,
);
config.format =
"${startTime} ${queryName} ${databaseName} ${status} ${queryFileBasename} ${resultCount} %::${startTime} ${queryName} ${databaseName} ${status} ${queryFileBasename} ${resultCount} %";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %::${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %`,
);
});
it("should get query short label", () => {
const fqi = createMockLocalQueryInfo({
startTime: date,
userSpecifiedLabel,
hasMetadata: true,
resultCount: 456,
});
// fall back on user specified if one exists.
expect(labelProvider.getShortLabel(fqi)).toBe("user-specified-name");
// use query name if no user-specified label exists
fqi.userSpecifiedLabel = undefined;
expect(labelProvider.getShortLabel(fqi)).toBe("query-name");
// use file name if no user-specified label exists and the query is not yet completed (meaning it has no results)
const fqi2 = createMockLocalQueryInfo({
startTime: date,
hasMetadata: true,
});
expect(labelProvider.getShortLabel(fqi2)).toBe("query-file.ql");
});
}); });
it("should interpolate query when not user specified", () => { describe("variant analyses", () => {
const fqi = createMockLocalQueryInfo({ it("should interpolate query when user specified", () => {
startTime: date, const fqi = createMockVariantAnalysisHistoryItem({
resultCount: 456, userSpecifiedLabel,
hasMetadata: true, executionStartTime,
});
expect(labelProvider.getLabel(fqi)).toBe(userSpecifiedLabel);
fqi.userSpecifiedLabel =
"${startTime} ${queryName} ${databaseName} ${status} %";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 1/3 repositories in progress %`,
);
fqi.userSpecifiedLabel =
"${startTime} ${queryName} ${databaseName} ${status} %::${startTime} ${queryName} ${databaseName} ${status} %";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 1/3 repositories in progress %::${dateStr} a-query-name (javascript) 1/3 repositories in progress %`,
);
}); });
expect(labelProvider.getLabel(fqi)).toBe("xxx query-name xxx"); it("should interpolate query when not user-specified", () => {
const fqi = createMockVariantAnalysisHistoryItem({
historyItemStatus: QueryStatus.Completed,
variantAnalysisStatus: VariantAnalysisStatus.Succeeded,
executionStartTime,
resultCount: 16,
});
config.format = "%t %q %d %s %f %r %%"; expect(labelProvider.getLabel(fqi)).toBe(
expect(labelProvider.getLabel(fqi)).toBe( "xxx a-query-name (javascript) xxx",
`${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %`, );
);
config.format = "%t %q %d %s %f %r %%::%t %q %d %s %f %r %%"; config.format =
expect(labelProvider.getLabel(fqi)).toBe( "${startTime} ${queryName} ${databaseName} ${status} ${queryFileBasename} ${resultCount} %";
`${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %::${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %`, expect(labelProvider.getLabel(fqi)).toBe(
); `${dateStr} a-query-name (javascript) 1/3 repositories completed a-query-file-path (16 results) %`,
}); );
it("should get query short label", () => { config.format =
const fqi = createMockLocalQueryInfo({ "${startTime} ${queryName} ${databaseName} ${status} ${queryFileBasename} ${resultCount} %::${startTime} ${queryName} ${databaseName} ${status} ${queryFileBasename} ${resultCount} %";
startTime: date, expect(labelProvider.getLabel(fqi)).toBe(
userSpecifiedLabel, `${dateStr} a-query-name (javascript) 1/3 repositories completed a-query-file-path (16 results) %::${dateStr} a-query-name (javascript) 1/3 repositories completed a-query-file-path (16 results) %`,
hasMetadata: true, );
resultCount: 456,
}); });
// fall back on user specified if one exists. it("should get query short label", () => {
expect(labelProvider.getShortLabel(fqi)).toBe("user-specified-name"); const fqi = createMockVariantAnalysisHistoryItem({
historyItemStatus: QueryStatus.Completed,
variantAnalysisStatus: VariantAnalysisStatus.Succeeded,
executionStartTime,
userSpecifiedLabel,
});
// use query name if no user-specified label exists // fall back on user specified if one exists.
fqi.userSpecifiedLabel = undefined; expect(labelProvider.getShortLabel(fqi)).toBe("user-specified-name");
expect(labelProvider.getShortLabel(fqi)).toBe("query-name");
// use file name if no user-specified label exists and the query is not yet completed (meaning it has no results) // use query name if no user-specified label exists
const fqi2 = createMockLocalQueryInfo({ const fqi2 = createMockVariantAnalysisHistoryItem({});
startTime: date,
hasMetadata: true, expect(labelProvider.getShortLabel(fqi2)).toBe("a-query-name");
});
describe("when results are present", () => {
it("should display results if there are any", () => {
const fqi = createMockVariantAnalysisHistoryItem({
historyItemStatus: QueryStatus.Completed,
resultCount: 16,
variantAnalysis: createMockVariantAnalysis({
status: VariantAnalysisStatus.Succeeded,
executionStartTime,
scannedRepos: createMockScannedRepos([
VariantAnalysisRepoStatus.Succeeded,
VariantAnalysisRepoStatus.Succeeded,
]),
}),
});
config.format =
"${startTime} ${queryName} ${databaseName} ${status} ${queryFileBasename} ${resultCount} %";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 2/2 repositories completed a-query-file-path (16 results) %`,
);
});
});
describe("when results are not present", () => {
it("should skip displaying them", () => {
const fqi = createMockVariantAnalysisHistoryItem({
historyItemStatus: QueryStatus.Completed,
resultCount: 0,
variantAnalysis: createMockVariantAnalysis({
status: VariantAnalysisStatus.Succeeded,
executionStartTime,
scannedRepos: createMockScannedRepos([
VariantAnalysisRepoStatus.Succeeded,
VariantAnalysisRepoStatus.Succeeded,
]),
}),
});
config.format =
"${startTime} ${queryName} ${databaseName} ${status} ${queryFileBasename} ${resultCount} %";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 2/2 repositories completed a-query-file-path %`,
);
});
});
describe("when extra whitespace is present in the middle of the label", () => {
it("should squash it down to a single whitespace", () => {
const fqi = createMockVariantAnalysisHistoryItem({
historyItemStatus: QueryStatus.Completed,
resultCount: 0,
variantAnalysis: createMockVariantAnalysis({
status: VariantAnalysisStatus.Succeeded,
executionStartTime,
scannedRepos: createMockScannedRepos([
VariantAnalysisRepoStatus.Succeeded,
VariantAnalysisRepoStatus.Succeeded,
]),
}),
});
config.format =
"${startTime} ${queryName} ${databaseName} ${status} ${queryFileBasename} ${resultCount} %";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 2/2 repositories completed a-query-file-path %`,
);
});
});
describe("when extra whitespace is present at the start of the label", () => {
it("should squash it down to a single whitespace", () => {
const fqi = createMockVariantAnalysisHistoryItem({
historyItemStatus: QueryStatus.Completed,
resultCount: 0,
variantAnalysis: createMockVariantAnalysis({
status: VariantAnalysisStatus.Succeeded,
executionStartTime,
scannedRepos: createMockScannedRepos([
VariantAnalysisRepoStatus.Succeeded,
VariantAnalysisRepoStatus.Succeeded,
]),
}),
});
config.format =
" ${startTime} ${queryName} ${databaseName} ${status} ${queryFileBasename} ${resultCount} %";
expect(labelProvider.getLabel(fqi)).toBe(
` ${dateStr} a-query-name (javascript) 2/2 repositories completed a-query-file-path %`,
);
});
});
describe("when extra whitespace is present at the end of the label", () => {
it("should squash it down to a single whitespace", () => {
const fqi = createMockVariantAnalysisHistoryItem({
historyItemStatus: QueryStatus.Completed,
resultCount: 0,
variantAnalysis: createMockVariantAnalysis({
status: VariantAnalysisStatus.Succeeded,
executionStartTime,
scannedRepos: createMockScannedRepos([
VariantAnalysisRepoStatus.Succeeded,
VariantAnalysisRepoStatus.Succeeded,
]),
}),
});
config.format =
"${startTime} ${queryName} ${databaseName} ${status} ${queryFileBasename} ${resultCount} % ";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 2/2 repositories completed a-query-file-path % `,
);
});
}); });
expect(labelProvider.getShortLabel(fqi2)).toBe("query-file.ql");
}); });
}); });
describe("variant analyses", () => { describe("legacy format", () => {
it("should interpolate query when user specified", () => { describe("local queries", () => {
const fqi = createMockVariantAnalysisHistoryItem({ it("should interpolate query when user specified", () => {
userSpecifiedLabel, const fqi = createMockLocalQueryInfo({
executionStartTime, startTime: date,
userSpecifiedLabel,
resultCount: 456,
hasMetadata: true,
});
expect(labelProvider.getLabel(fqi)).toBe("user-specified-name");
fqi.userSpecifiedLabel = "%t %q %d %s %f %r %%";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %`,
);
fqi.userSpecifiedLabel = "%t %q %d %s %f %r %%::%t %q %d %s %f %r %%";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %::${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %`,
);
}); });
expect(labelProvider.getLabel(fqi)).toBe(userSpecifiedLabel); it("should interpolate query when not user specified", () => {
const fqi = createMockLocalQueryInfo({
startTime: date,
resultCount: 456,
hasMetadata: true,
});
fqi.userSpecifiedLabel = "%t %q %d %s %%"; expect(labelProvider.getLabel(fqi)).toBe("xxx query-name xxx");
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 1/3 repositories in progress %`,
);
fqi.userSpecifiedLabel = "%t %q %d %s %%::%t %q %d %s %%"; config.format = "%t %q %d %s %f %r %%";
expect(labelProvider.getLabel(fqi)).toBe( expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 1/3 repositories in progress %::${dateStr} a-query-name (javascript) 1/3 repositories in progress %`, `${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %`,
); );
});
it("should interpolate query when not user-specified", () => { config.format = "%t %q %d %s %f %r %%::%t %q %d %s %f %r %%";
const fqi = createMockVariantAnalysisHistoryItem({ expect(labelProvider.getLabel(fqi)).toBe(
historyItemStatus: QueryStatus.Completed, `${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %::${dateStr} query-name db-name finished in 0 seconds query-file.ql (456 results) %`,
variantAnalysisStatus: VariantAnalysisStatus.Succeeded, );
executionStartTime,
resultCount: 16,
}); });
expect(labelProvider.getLabel(fqi)).toBe( it("should get query short label", () => {
"xxx a-query-name (javascript) xxx", const fqi = createMockLocalQueryInfo({
); startTime: date,
userSpecifiedLabel,
hasMetadata: true,
resultCount: 456,
});
config.format = "%t %q %d %s %f %r %%"; // fall back on user specified if one exists.
expect(labelProvider.getLabel(fqi)).toBe( expect(labelProvider.getShortLabel(fqi)).toBe("user-specified-name");
`${dateStr} a-query-name (javascript) 1/3 repositories completed a-query-file-path (16 results) %`,
);
config.format = "%t %q %d %s %f %r %%::%t %q %d %s %f %r %%"; // use query name if no user-specified label exists
expect(labelProvider.getLabel(fqi)).toBe( fqi.userSpecifiedLabel = undefined;
`${dateStr} a-query-name (javascript) 1/3 repositories completed a-query-file-path (16 results) %::${dateStr} a-query-name (javascript) 1/3 repositories completed a-query-file-path (16 results) %`, expect(labelProvider.getShortLabel(fqi)).toBe("query-name");
);
// use file name if no user-specified label exists and the query is not yet completed (meaning it has no results)
const fqi2 = createMockLocalQueryInfo({
startTime: date,
hasMetadata: true,
});
expect(labelProvider.getShortLabel(fqi2)).toBe("query-file.ql");
});
}); });
it("should get query short label", () => { describe("variant analyses", () => {
const fqi = createMockVariantAnalysisHistoryItem({ it("should interpolate query when user specified", () => {
historyItemStatus: QueryStatus.Completed, const fqi = createMockVariantAnalysisHistoryItem({
variantAnalysisStatus: VariantAnalysisStatus.Succeeded, userSpecifiedLabel,
executionStartTime, executionStartTime,
userSpecifiedLabel, });
expect(labelProvider.getLabel(fqi)).toBe(userSpecifiedLabel);
fqi.userSpecifiedLabel = "%t %q %d %s %%";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 1/3 repositories in progress %`,
);
fqi.userSpecifiedLabel = "%t %q %d %s %%::%t %q %d %s %%";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 1/3 repositories in progress %::${dateStr} a-query-name (javascript) 1/3 repositories in progress %`,
);
}); });
// fall back on user specified if one exists. it("should interpolate query when not user-specified", () => {
expect(labelProvider.getShortLabel(fqi)).toBe("user-specified-name");
// use query name if no user-specified label exists
const fqi2 = createMockVariantAnalysisHistoryItem({});
expect(labelProvider.getShortLabel(fqi2)).toBe("a-query-name");
});
describe("when results are present", () => {
it("should display results if there are any", () => {
const fqi = createMockVariantAnalysisHistoryItem({ const fqi = createMockVariantAnalysisHistoryItem({
historyItemStatus: QueryStatus.Completed, historyItemStatus: QueryStatus.Completed,
variantAnalysisStatus: VariantAnalysisStatus.Succeeded,
executionStartTime,
resultCount: 16, resultCount: 16,
variantAnalysis: createMockVariantAnalysis({
status: VariantAnalysisStatus.Succeeded,
executionStartTime,
scannedRepos: createMockScannedRepos([
VariantAnalysisRepoStatus.Succeeded,
VariantAnalysisRepoStatus.Succeeded,
]),
}),
}); });
expect(labelProvider.getLabel(fqi)).toBe(
"xxx a-query-name (javascript) xxx",
);
config.format = "%t %q %d %s %f %r %%"; config.format = "%t %q %d %s %f %r %%";
expect(labelProvider.getLabel(fqi)).toBe( expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 2/2 repositories completed a-query-file-path (16 results) %`, `${dateStr} a-query-name (javascript) 1/3 repositories completed a-query-file-path (16 results) %`,
);
config.format = "%t %q %d %s %f %r %%::%t %q %d %s %f %r %%";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 1/3 repositories completed a-query-file-path (16 results) %::${dateStr} a-query-name (javascript) 1/3 repositories completed a-query-file-path (16 results) %`,
); );
}); });
});
describe("when results are not present", () => { it("should get query short label", () => {
it("should skip displaying them", () => {
const fqi = createMockVariantAnalysisHistoryItem({ const fqi = createMockVariantAnalysisHistoryItem({
historyItemStatus: QueryStatus.Completed, historyItemStatus: QueryStatus.Completed,
resultCount: 0, variantAnalysisStatus: VariantAnalysisStatus.Succeeded,
variantAnalysis: createMockVariantAnalysis({ executionStartTime,
status: VariantAnalysisStatus.Succeeded, userSpecifiedLabel,
executionStartTime,
scannedRepos: createMockScannedRepos([
VariantAnalysisRepoStatus.Succeeded,
VariantAnalysisRepoStatus.Succeeded,
]),
}),
}); });
config.format = "%t %q %d %s %f %r %%";
expect(labelProvider.getLabel(fqi)).toBe( // fall back on user specified if one exists.
`${dateStr} a-query-name (javascript) 2/2 repositories completed a-query-file-path %`, expect(labelProvider.getShortLabel(fqi)).toBe("user-specified-name");
);
// use query name if no user-specified label exists
const fqi2 = createMockVariantAnalysisHistoryItem({});
expect(labelProvider.getShortLabel(fqi2)).toBe("a-query-name");
}); });
});
describe("when extra whitespace is present in the middle of the label", () => { describe("when results are present", () => {
it("should squash it down to a single whitespace", () => { it("should display results if there are any", () => {
const fqi = createMockVariantAnalysisHistoryItem({ const fqi = createMockVariantAnalysisHistoryItem({
historyItemStatus: QueryStatus.Completed, historyItemStatus: QueryStatus.Completed,
resultCount: 0, resultCount: 16,
variantAnalysis: createMockVariantAnalysis({ variantAnalysis: createMockVariantAnalysis({
status: VariantAnalysisStatus.Succeeded, status: VariantAnalysisStatus.Succeeded,
executionStartTime, executionStartTime,
scannedRepos: createMockScannedRepos([ scannedRepos: createMockScannedRepos([
VariantAnalysisRepoStatus.Succeeded, VariantAnalysisRepoStatus.Succeeded,
VariantAnalysisRepoStatus.Succeeded, VariantAnalysisRepoStatus.Succeeded,
]), ]),
}), }),
});
config.format = "%t %q %d %s %f %r %%";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 2/2 repositories completed a-query-file-path (16 results) %`,
);
}); });
config.format = "%t %q %d %s %f %r %%";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 2/2 repositories completed a-query-file-path %`,
);
}); });
});
describe("when extra whitespace is present at the start of the label", () => { describe("when results are not present", () => {
it("should squash it down to a single whitespace", () => { it("should skip displaying them", () => {
const fqi = createMockVariantAnalysisHistoryItem({ const fqi = createMockVariantAnalysisHistoryItem({
historyItemStatus: QueryStatus.Completed, historyItemStatus: QueryStatus.Completed,
resultCount: 0, resultCount: 0,
variantAnalysis: createMockVariantAnalysis({ variantAnalysis: createMockVariantAnalysis({
status: VariantAnalysisStatus.Succeeded, status: VariantAnalysisStatus.Succeeded,
executionStartTime, executionStartTime,
scannedRepos: createMockScannedRepos([ scannedRepos: createMockScannedRepos([
VariantAnalysisRepoStatus.Succeeded, VariantAnalysisRepoStatus.Succeeded,
VariantAnalysisRepoStatus.Succeeded, VariantAnalysisRepoStatus.Succeeded,
]), ]),
}), }),
});
config.format = "%t %q %d %s %f %r %%";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 2/2 repositories completed a-query-file-path %`,
);
}); });
config.format = " %t %q %d %s %f %r %%";
expect(labelProvider.getLabel(fqi)).toBe(
` ${dateStr} a-query-name (javascript) 2/2 repositories completed a-query-file-path %`,
);
}); });
});
describe("when extra whitespace is present at the end of the label", () => { describe("when extra whitespace is present in the middle of the label", () => {
it("should squash it down to a single whitespace", () => { it("should squash it down to a single whitespace", () => {
const fqi = createMockVariantAnalysisHistoryItem({ const fqi = createMockVariantAnalysisHistoryItem({
historyItemStatus: QueryStatus.Completed, historyItemStatus: QueryStatus.Completed,
resultCount: 0, resultCount: 0,
variantAnalysis: createMockVariantAnalysis({ variantAnalysis: createMockVariantAnalysis({
status: VariantAnalysisStatus.Succeeded, status: VariantAnalysisStatus.Succeeded,
executionStartTime, executionStartTime,
scannedRepos: createMockScannedRepos([ scannedRepos: createMockScannedRepos([
VariantAnalysisRepoStatus.Succeeded, VariantAnalysisRepoStatus.Succeeded,
VariantAnalysisRepoStatus.Succeeded, VariantAnalysisRepoStatus.Succeeded,
]), ]),
}), }),
});
config.format = "%t %q %d %s %f %r %%";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 2/2 repositories completed a-query-file-path %`,
);
});
});
describe("when extra whitespace is present at the start of the label", () => {
it("should squash it down to a single whitespace", () => {
const fqi = createMockVariantAnalysisHistoryItem({
historyItemStatus: QueryStatus.Completed,
resultCount: 0,
variantAnalysis: createMockVariantAnalysis({
status: VariantAnalysisStatus.Succeeded,
executionStartTime,
scannedRepos: createMockScannedRepos([
VariantAnalysisRepoStatus.Succeeded,
VariantAnalysisRepoStatus.Succeeded,
]),
}),
});
config.format = " %t %q %d %s %f %r %%";
expect(labelProvider.getLabel(fqi)).toBe(
` ${dateStr} a-query-name (javascript) 2/2 repositories completed a-query-file-path %`,
);
});
});
describe("when extra whitespace is present at the end of the label", () => {
it("should squash it down to a single whitespace", () => {
const fqi = createMockVariantAnalysisHistoryItem({
historyItemStatus: QueryStatus.Completed,
resultCount: 0,
variantAnalysis: createMockVariantAnalysis({
status: VariantAnalysisStatus.Succeeded,
executionStartTime,
scannedRepos: createMockScannedRepos([
VariantAnalysisRepoStatus.Succeeded,
VariantAnalysisRepoStatus.Succeeded,
]),
}),
});
config.format = "%t %q %d %s %f %r %% ";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 2/2 repositories completed a-query-file-path % `,
);
}); });
config.format = "%t %q %d %s %f %r %% ";
expect(labelProvider.getLabel(fqi)).toBe(
`${dateStr} a-query-name (javascript) 2/2 repositories completed a-query-file-path % `,
);
}); });
}); });
}); });