Add getDisplayActionName tests

This commit is contained in:
Michael B. Gale
2026-10-12 12:49:48 +01:00
parent 409be01136
commit ecfc96e0a9
3 changed files with 37 additions and 10 deletions

11
lib/entry-points.js generated
View File

@@ -171409,11 +171409,14 @@ function getAddressString(address) {
}
// src/status-report.ts
var ACTION_DISPLAY_NAMES = {
["finish" /* Analyze */]: "analyze",
["init-post" /* InitPost */]: "init post"
};
function getDisplayActionName(actionName) {
if (actionName === "finish" /* Analyze */) {
return "analyze";
} else if (actionName === "init-post" /* InitPost */) {
return "init post";
const displayName = ACTION_DISPLAY_NAMES[actionName];
if (displayName !== void 0) {
return displayName;
}
return actionName;
}

View File

@@ -19,6 +19,24 @@ import { getErrorMessage } from "./util";
setupTests(test);
for (const [key, displayName] of Object.entries(
statusReport.ACTION_DISPLAY_NAMES,
)) {
test(`getDisplayActionName - '${displayName}' instead of '${key}'`, (t) => {
t.is(statusReport.getDisplayActionName(key as ActionName), displayName);
});
}
test("getDisplayActionName - returns action name", (t) => {
for (const actionName of Object.values(ActionName)) {
if (statusReport.ACTION_DISPLAY_NAMES[actionName]) {
continue;
}
t.is(statusReport.getDisplayActionName(actionName), actionName);
}
});
interface RunInActionsTestOpts {
runFn?: () => Promise<any>;
expectedErrorMessage?: string;

View File

@@ -61,15 +61,21 @@ export enum ActionName {
UploadSarif = "upload-sarif",
}
/** A partial mapping from `ActionName` to names for actions whose display name is not the `ActionName` value. */
export const ACTION_DISPLAY_NAMES: Partial<Record<ActionName, string>> = {
[ActionName.Analyze]: "analyze",
[ActionName.InitPost]: "init post",
};
/**
* Maps an `ActionName` to its display name. Usually that is the same, except
* for `ActionName.Analyze` where it is `"analyze"` instead of `"finish"`.
* Maps an {@link ActionName} to its display name. Usually that is the same, except
* for actions which have a different display name in {@link ACTION_DISPLAY_NAMES}.
*/
export function getDisplayActionName(actionName: ActionName): string {
if (actionName === ActionName.Analyze) {
return "analyze";
} else if (actionName === ActionName.InitPost) {
return "init post";
const displayName = ACTION_DISPLAY_NAMES[actionName];
if (displayName !== undefined) {
return displayName;
}
return actionName;
}