feat(scenarios): show last run status and timestamp on scenarios list
- extend findAll to join latest run per scenario via correlated subquery - return lastRunStatus and lastRunAt fields in GET /scenarios response - add Last Run column with badge and timestamp to ScenariosPage - add integration tests for null and populated lastRunStatus
This commit is contained in:
@@ -90,6 +90,8 @@ export interface Scenario {
|
|||||||
environment?: Pick<Environment, 'id' | 'name'>;
|
environment?: Pick<Environment, 'id' | 'name'>;
|
||||||
steps?: ScenarioStep[];
|
steps?: ScenarioStep[];
|
||||||
scenarioCredentials?: ScenarioCredential[];
|
scenarioCredentials?: ScenarioCredential[];
|
||||||
|
lastRunStatus?: ScenarioRunStatus | null;
|
||||||
|
lastRunAt?: string | null;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,6 +127,7 @@
|
|||||||
"col_id": "ID",
|
"col_id": "ID",
|
||||||
"col_name": "Name",
|
"col_name": "Name",
|
||||||
"col_description": "Description",
|
"col_description": "Description",
|
||||||
|
"col_last_run": "Last Run",
|
||||||
"col_updated": "Updated",
|
"col_updated": "Updated",
|
||||||
"empty": "No scenarios yet.",
|
"empty": "No scenarios yet.",
|
||||||
"loading": "Loading…",
|
"loading": "Loading…",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { parse as yamlParse } from 'yaml';
|
|||||||
import { environments, scenarios } from '../../api';
|
import { environments, scenarios } from '../../api';
|
||||||
import type { Environment, Scenario } from '../../api';
|
import type { Environment, Scenario } from '../../api';
|
||||||
import {
|
import {
|
||||||
|
Badge,
|
||||||
Breadcrumbs,
|
Breadcrumbs,
|
||||||
Button,
|
Button,
|
||||||
Modal,
|
Modal,
|
||||||
@@ -17,8 +18,24 @@ import {
|
|||||||
UuidBadge,
|
UuidBadge,
|
||||||
useToast,
|
useToast,
|
||||||
} from '../../ui';
|
} from '../../ui';
|
||||||
|
import type { BadgeVariant } from '../../ui';
|
||||||
|
import type { ScenarioRunStatus } from '../../api';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
|
const LAST_RUN_VARIANT: Record<ScenarioRunStatus, BadgeVariant> = {
|
||||||
|
pending: 'neutral',
|
||||||
|
in_progress: 'info',
|
||||||
|
pass: 'success',
|
||||||
|
fail: 'error',
|
||||||
|
};
|
||||||
|
|
||||||
|
const LAST_RUN_LABEL: Record<ScenarioRunStatus, string> = {
|
||||||
|
pending: 'Pending',
|
||||||
|
in_progress: 'Running',
|
||||||
|
pass: 'Pass',
|
||||||
|
fail: 'Fail',
|
||||||
|
};
|
||||||
|
|
||||||
export function ScenariosPage() {
|
export function ScenariosPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -135,6 +152,24 @@ export function ScenariosPage() {
|
|||||||
const columns: TableColumn<Scenario>[] = [
|
const columns: TableColumn<Scenario>[] = [
|
||||||
{ key: 'id', header: t('scenarios.col_id'), render: (s) => <UuidBadge id={s.id} />, width: 60 },
|
{ key: 'id', header: t('scenarios.col_id'), render: (s) => <UuidBadge id={s.id} />, width: 60 },
|
||||||
{ key: 'name', header: t('scenarios.col_name'), render: (s) => s.name, sortable: true },
|
{ key: 'name', header: t('scenarios.col_name'), render: (s) => s.name, sortable: true },
|
||||||
|
{
|
||||||
|
key: 'lastRunStatus',
|
||||||
|
header: t('scenarios.col_last_run'),
|
||||||
|
width: 160,
|
||||||
|
render: (s) =>
|
||||||
|
s.lastRunStatus ? (
|
||||||
|
<span style={{ display: 'inline-flex', alignItems: 'center', gap: 6 }}>
|
||||||
|
<span style={{ display: 'inline-flex', minWidth: 62 }}>
|
||||||
|
<Badge variant={LAST_RUN_VARIANT[s.lastRunStatus]}>
|
||||||
|
{LAST_RUN_LABEL[s.lastRunStatus]}
|
||||||
|
</Badge>
|
||||||
|
</span>
|
||||||
|
{s.lastRunAt && <Timestamp value={s.lastRunAt} />}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span style={{ color: 'var(--color-text-muted)', fontSize: '0.8em' }}>—</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'updatedAt',
|
key: 'updatedAt',
|
||||||
header: t('scenarios.col_updated'),
|
header: t('scenarios.col_updated'),
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ export class ScenarioService {
|
|||||||
|
|
||||||
async findAll(
|
async findAll(
|
||||||
query: PaginationQueryDto<ScenarioOrderBy>,
|
query: PaginationQueryDto<ScenarioOrderBy>,
|
||||||
): Promise<PaginatedResult<ScenarioEntity>> {
|
): Promise<PaginatedResult<ScenarioEntity & { lastRunStatus: string | null; lastRunAt: string | null }>> {
|
||||||
const page = query.page ?? 1;
|
const page = query.page ?? 1;
|
||||||
const limit = query.limit ?? 20;
|
const limit = query.limit ?? 20;
|
||||||
const orderBy = query.orderBy ?? "id";
|
const orderBy = query.orderBy ?? "id";
|
||||||
@@ -73,7 +73,39 @@ export class ScenarioService {
|
|||||||
skip: (page - 1) * limit,
|
skip: (page - 1) * limit,
|
||||||
take: limit,
|
take: limit,
|
||||||
});
|
});
|
||||||
return { data, total, page, limit };
|
|
||||||
|
let lastRunByScenario = new Map<string, { status: string; createdAt: Date }>();
|
||||||
|
if (data.length > 0) {
|
||||||
|
const ids = data.map((s) => s.id);
|
||||||
|
const latestRuns = await this.runRepo
|
||||||
|
.createQueryBuilder("r")
|
||||||
|
.select(["r.scenarioId", "r.status", "r.createdAt"])
|
||||||
|
.where("r.scenarioId IN (:...ids)", { ids })
|
||||||
|
.andWhere((qb) => {
|
||||||
|
const sub = qb
|
||||||
|
.subQuery()
|
||||||
|
.select("MAX(r2.createdAt)")
|
||||||
|
.from(ScenarioRunEntity, "r2")
|
||||||
|
.where("r2.scenarioId = r.scenarioId")
|
||||||
|
.getQuery();
|
||||||
|
return `r.createdAt = (${sub})`;
|
||||||
|
})
|
||||||
|
.getMany();
|
||||||
|
lastRunByScenario = new Map(
|
||||||
|
latestRuns.map((r) => [r.scenarioId, { status: r.status, createdAt: r.createdAt }]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: data.map((s) => ({
|
||||||
|
...s,
|
||||||
|
lastRunStatus: lastRunByScenario.get(s.id)?.status ?? null,
|
||||||
|
lastRunAt: lastRunByScenario.get(s.id)?.createdAt?.toISOString() ?? null,
|
||||||
|
})),
|
||||||
|
total,
|
||||||
|
page,
|
||||||
|
limit,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(id: string): Promise<ScenarioEntity> {
|
async findOne(id: string): Promise<ScenarioEntity> {
|
||||||
|
|||||||
@@ -171,6 +171,35 @@ describe("ScenarioController", () => {
|
|||||||
.get("/scenarios?orderDir=SIDEWAYS")
|
.get("/scenarios?orderDir=SIDEWAYS")
|
||||||
.expect(400);
|
.expect(400);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("returns lastRunStatus and lastRunAt as null when scenario has no runs", async () => {
|
||||||
|
await createScenario("no-runs-sc");
|
||||||
|
const res = await request(app.getHttpServer())
|
||||||
|
.get("/scenarios?orderBy=name&orderDir=ASC")
|
||||||
|
.expect(200);
|
||||||
|
const item = res.body.data.find(
|
||||||
|
(s: { name: string }) => s.name === "no-runs-sc",
|
||||||
|
);
|
||||||
|
expect(item).toBeDefined();
|
||||||
|
expect(item.lastRunStatus).toBeNull();
|
||||||
|
expect(item.lastRunAt).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns lastRunStatus and lastRunAt reflecting the most recent run", async () => {
|
||||||
|
const sc = await createScenario("last-run-status-sc");
|
||||||
|
await createRun(sc.id);
|
||||||
|
const res = await request(app.getHttpServer())
|
||||||
|
.get("/scenarios?orderBy=name&orderDir=ASC")
|
||||||
|
.expect(200);
|
||||||
|
const item = res.body.data.find(
|
||||||
|
(s: { name: string }) => s.name === "last-run-status-sc",
|
||||||
|
);
|
||||||
|
expect(item).toBeDefined();
|
||||||
|
expect(["pending", "in_progress", "pass", "fail"]).toContain(
|
||||||
|
item.lastRunStatus,
|
||||||
|
);
|
||||||
|
expect(typeof item.lastRunAt).toBe("string");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── GET /scenarios/:id ─────────────────────────────────────────────────────
|
// ── GET /scenarios/:id ─────────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user