web: run history list, filter and sort (R1/R2)
Day-grouped run list with sticky day headers (Today / Yesterday / d MMM yyyy / Unknown date), a usage roll-up block, the app's row hierarchy and a bounded filter/sort menu — mirroring RunHistoryScreen.kt, ListFilter.kt and ListSort.kt. New pure helpers live in src/runs.js with focused unit tests; app.js keeps the wiring and sets server strings with textContent. R1 done, R2 partial: no per-row "needs you" mark exists in the Android app; its wording is deferred to R15 (separate attention surface).
This commit is contained in:
@@ -0,0 +1,393 @@
|
||||
// Pure unit tests for the runs-list helpers: filtering (status/pipeline/time,
|
||||
// AND-combined), every sort comparator with its id tie-break, day grouping,
|
||||
// the wording helpers and the list's slot model. No server, no DOM.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import {
|
||||
RUN_STATES,
|
||||
RUN_TIME_RANGES,
|
||||
RUN_SORTS,
|
||||
runStateOf,
|
||||
runIdentity,
|
||||
versionLabel,
|
||||
visitCount,
|
||||
progressText,
|
||||
metaText,
|
||||
formatDuration,
|
||||
secondsSince,
|
||||
durationSeconds,
|
||||
localDayKey,
|
||||
dayLabel,
|
||||
defaultRunFilters,
|
||||
runFiltersActiveCount,
|
||||
runMatchesTimeRange,
|
||||
filterRuns,
|
||||
pipelineFilterOptions,
|
||||
runComparator,
|
||||
sortRuns,
|
||||
groupRunsByDay,
|
||||
runListEntries,
|
||||
NO_RUNS_MESSAGE,
|
||||
NO_MATCH_MESSAGE,
|
||||
} from "../src/runs.js";
|
||||
|
||||
/** A finished run on the Today of the tests, with every field the list reads. */
|
||||
function run(overrides = {}) {
|
||||
return {
|
||||
id: 1,
|
||||
pipeline_id: 1,
|
||||
name: "Pipe",
|
||||
title: null,
|
||||
version: 1,
|
||||
status: "succeeded",
|
||||
executing: false,
|
||||
current_stage: "",
|
||||
completed_steps: 0,
|
||||
created_at: "2026-10-19T10:00:00Z",
|
||||
finished_at: "2026-10-19T10:01:00Z",
|
||||
diagnostic: "",
|
||||
resource_wait: null,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
const TODAY = "2026-10-19";
|
||||
const ZONE = "UTC";
|
||||
const TIME_OPTS = { zone: ZONE, locale: "en-GB" };
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Vocabulary and wording
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("runStateOf maps the server vocabulary and the outcome synonyms", () => {
|
||||
assert.equal(runStateOf("running"), "running");
|
||||
assert.equal(runStateOf("succeeded"), "succeeded");
|
||||
assert.equal(runStateOf("success"), "succeeded");
|
||||
assert.equal(runStateOf("completed"), "succeeded");
|
||||
assert.equal(runStateOf("done"), "succeeded");
|
||||
assert.equal(runStateOf("error"), "failed");
|
||||
assert.equal(runStateOf("cancelled"), "canceled");
|
||||
assert.equal(runStateOf(" INTERRUPTED "), "interrupted");
|
||||
assert.equal(runStateOf(""), "unknown");
|
||||
assert.equal(runStateOf("nonsense"), "unknown");
|
||||
});
|
||||
|
||||
test("RUN_STATES is exactly the server run vocabulary in display order", () => {
|
||||
assert.deepEqual(RUN_STATES, [
|
||||
"queued",
|
||||
"running",
|
||||
"waiting",
|
||||
"succeeded",
|
||||
"failed",
|
||||
"canceled",
|
||||
"interrupted",
|
||||
]);
|
||||
});
|
||||
|
||||
test("runIdentity falls back to the pipeline name and only splits when titled", () => {
|
||||
assert.deepEqual(runIdentity(" Fix the thing ", "Plan and land"), {
|
||||
label: "Fix the thing",
|
||||
pipeline: "Plan and land",
|
||||
});
|
||||
assert.deepEqual(runIdentity(null, "Plan and land"), { label: "Plan and land", pipeline: null });
|
||||
assert.deepEqual(runIdentity(" ", "Plan and land"), { label: "Plan and land", pipeline: null });
|
||||
});
|
||||
|
||||
test("versionLabel and visitCount use the app's singular/plural spelling", () => {
|
||||
assert.equal(versionLabel(5), "v5");
|
||||
assert.equal(visitCount(1, "completed"), "1 completed visit");
|
||||
assert.equal(visitCount(0, "completed"), "0 completed visits");
|
||||
assert.equal(visitCount(3, "completed"), "3 completed visits");
|
||||
});
|
||||
|
||||
test("progressText carries resource wait, completed visits and the stage", () => {
|
||||
assert.equal(
|
||||
progressText(run({ completed_steps: 2, current_stage: "implementer" })),
|
||||
"2 completed visits · stage implementer",
|
||||
);
|
||||
assert.equal(
|
||||
progressText(
|
||||
run({ completed_steps: 1, current_stage: "reviewer", resource_wait: { resource: "pixel-9" } }),
|
||||
),
|
||||
"Waiting for resource pixel-9 · 1 completed visit · stage reviewer",
|
||||
);
|
||||
assert.equal(progressText(run({ completed_steps: 0 })), "0 completed visits");
|
||||
});
|
||||
|
||||
test("metaText shows a live elapsed while executing and id/start/duration at rest", () => {
|
||||
const executing = run({
|
||||
id: 7,
|
||||
executing: true,
|
||||
created_at: "2026-10-19T09:30:00Z",
|
||||
finished_at: "",
|
||||
});
|
||||
assert.equal(metaText(executing, Date.parse("2026-10-19T09:31:05Z"), TIME_OPTS), "run 7 · 1m 5s");
|
||||
// A future start (clock skew) reads as 0s, never a negative.
|
||||
assert.equal(metaText(executing, Date.parse("2026-10-19T09:00:00Z"), TIME_OPTS), "run 7 · 0s");
|
||||
|
||||
const done = run({
|
||||
id: 7,
|
||||
created_at: "2026-10-19T09:30:00Z",
|
||||
finished_at: "2026-10-19T09:32:05Z",
|
||||
});
|
||||
assert.equal(metaText(done, 0, TIME_OPTS), "run 7 · 19 Oct 09:30 · 2m 5s");
|
||||
});
|
||||
|
||||
test("formatDuration, secondsSince and durationSeconds mirror Format.kt", () => {
|
||||
assert.equal(formatDuration(0), "0s");
|
||||
assert.equal(formatDuration(59), "59s");
|
||||
assert.equal(formatDuration(60), "1m 0s");
|
||||
assert.equal(formatDuration(125), "2m 5s");
|
||||
assert.equal(formatDuration(3725), "1h 2m");
|
||||
assert.equal(formatDuration(-5), "0s");
|
||||
|
||||
assert.equal(secondsSince("2026-10-19T09:30:00Z", Date.parse("2026-10-19T09:31:05Z")), 65);
|
||||
assert.equal(secondsSince("bad", 0), null);
|
||||
assert.equal(durationSeconds("2026-10-19T09:30:00Z", "2026-10-19T09:32:05Z"), 125);
|
||||
assert.equal(durationSeconds("2026-10-19T09:32:05Z", "2026-10-19T09:30:00Z"), null);
|
||||
assert.equal(durationSeconds("", ""), null);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Filters
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("default filters change nothing and count as zero active facets", () => {
|
||||
const runs = [run({ id: 1 }), run({ id: 2, status: "failed" })];
|
||||
const filters = defaultRunFilters();
|
||||
assert.equal(runFiltersActiveCount(filters), 0);
|
||||
assert.equal(filterRuns(runs, filters, TODAY, ZONE), runs);
|
||||
});
|
||||
|
||||
test("status filter narrows to the selected states; an empty set is any status", () => {
|
||||
const runs = [
|
||||
run({ id: 1, status: "succeeded" }),
|
||||
run({ id: 2, status: "failed" }),
|
||||
run({ id: 3, status: "canceled" }),
|
||||
];
|
||||
const filters = { ...defaultRunFilters(), statuses: new Set(["failed"]) };
|
||||
assert.deepEqual(
|
||||
filterRuns(runs, filters, TODAY, ZONE).map((r) => r.id),
|
||||
[2],
|
||||
);
|
||||
// "success" resolves to the succeeded state, so selecting it matches.
|
||||
const succeeded = { ...defaultRunFilters(), statuses: new Set(["succeeded"]) };
|
||||
assert.deepEqual(
|
||||
filterRuns([run({ id: 9, status: "success" })], succeeded, TODAY, ZONE).map((r) => r.id),
|
||||
[9],
|
||||
);
|
||||
assert.equal(runFiltersActiveCount(filters), 1);
|
||||
});
|
||||
|
||||
test("pipeline filter is a single-select; null means any pipeline", () => {
|
||||
const runs = [run({ id: 1, pipeline_id: 3 }), run({ id: 2, pipeline_id: 4 })];
|
||||
const filters = { ...defaultRunFilters(), pipelineId: 4 };
|
||||
assert.deepEqual(
|
||||
filterRuns(runs, filters, TODAY, ZONE).map((r) => r.id),
|
||||
[2],
|
||||
);
|
||||
assert.equal(runFiltersActiveCount(filters), 1);
|
||||
});
|
||||
|
||||
test("time range is inclusive calendar days ending today and rejects future/blank", () => {
|
||||
const at = (created_at) => run({ created_at });
|
||||
assert.equal(runMatchesTimeRange(at("2026-10-19T00:00:00Z"), "today", TODAY, ZONE), true);
|
||||
assert.equal(runMatchesTimeRange(at("2026-10-18T23:59:59Z"), "today", TODAY, ZONE), false);
|
||||
// last 7 days covers today and the six days before it (>= 13 Oct).
|
||||
assert.equal(runMatchesTimeRange(at("2026-10-13T00:00:00Z"), "last_7_days", TODAY, ZONE), true);
|
||||
assert.equal(runMatchesTimeRange(at("2026-10-12T23:00:00Z"), "last_7_days", TODAY, ZONE), false);
|
||||
// last 30 days covers >= 20 Sep.
|
||||
assert.equal(runMatchesTimeRange(at("2026-09-20T00:00:00Z"), "last_30_days", TODAY, ZONE), true);
|
||||
assert.equal(runMatchesTimeRange(at("2026-09-19T00:00:00Z"), "last_30_days", TODAY, ZONE), false);
|
||||
// A future-dated run and a blank/unparseable timestamp never match a window.
|
||||
assert.equal(runMatchesTimeRange(at("2026-10-20T00:00:00Z"), "today", TODAY, ZONE), false);
|
||||
assert.equal(runMatchesTimeRange(at("not-a-date"), "today", TODAY, ZONE), false);
|
||||
assert.equal(runMatchesTimeRange(at(""), "last_30_days", TODAY, ZONE), false);
|
||||
// Any time matches everything, including blank.
|
||||
assert.equal(runMatchesTimeRange(at(""), "any_time", TODAY, ZONE), true);
|
||||
});
|
||||
|
||||
test("the three facets AND-combine and the count is one per facet", () => {
|
||||
const runs = [
|
||||
run({ id: 1, pipeline_id: 3, status: "failed", created_at: "2026-10-19T10:00:00Z" }),
|
||||
run({ id: 2, pipeline_id: 3, status: "succeeded", created_at: "2026-10-19T10:00:00Z" }),
|
||||
run({ id: 3, pipeline_id: 4, status: "failed", created_at: "2026-10-19T10:00:00Z" }),
|
||||
run({ id: 4, pipeline_id: 3, status: "failed", created_at: "2026-08-01T10:00:00Z" }),
|
||||
];
|
||||
const filters = {
|
||||
statuses: new Set(["failed"]),
|
||||
pipelineId: 3,
|
||||
timeRange: "last_7_days",
|
||||
};
|
||||
assert.equal(runFiltersActiveCount(filters), 3);
|
||||
assert.deepEqual(
|
||||
filterRuns(runs, filters, TODAY, ZONE).map((r) => r.id),
|
||||
[1],
|
||||
);
|
||||
});
|
||||
|
||||
test("pipelineFilterOptions names each pipeline from its newest non-blank run and sorts by name then id", () => {
|
||||
const options = pipelineFilterOptions([
|
||||
run({ pipeline_id: 5, name: "beta" }),
|
||||
run({ pipeline_id: 5, name: "" }),
|
||||
run({ pipeline_id: 2, name: "Alpha" }),
|
||||
run({ pipeline_id: 9, name: "" }),
|
||||
]);
|
||||
assert.deepEqual(options, [
|
||||
{ id: 2, name: "Alpha" },
|
||||
{ id: 5, name: "beta" },
|
||||
{ id: 9, name: "Pipeline 9" },
|
||||
]);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Sort: every comparator plus an id tie-break
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("newest first orders by start descending, then id descending", () => {
|
||||
const a = run({ id: 1, created_at: "2026-10-19T10:00:00Z" });
|
||||
const b = run({ id: 2, created_at: "2026-10-19T10:00:00Z" });
|
||||
const c = run({ id: 3, created_at: "2026-10-19T11:00:00Z" });
|
||||
assert.deepEqual(
|
||||
sortRuns([a, b, c], "newest_first").map((r) => r.id),
|
||||
[3, 2, 1],
|
||||
);
|
||||
});
|
||||
|
||||
test("oldest first orders by start ascending, then id ascending", () => {
|
||||
const a = run({ id: 1, created_at: "2026-10-19T10:00:00Z" });
|
||||
const b = run({ id: 2, created_at: "2026-10-19T10:00:00Z" });
|
||||
const c = run({ id: 3, created_at: "2026-10-19T11:00:00Z" });
|
||||
assert.deepEqual(
|
||||
sortRuns([a, b, c], "oldest_first").map((r) => r.id),
|
||||
[1, 2, 3],
|
||||
);
|
||||
});
|
||||
|
||||
test("longest duration puts a missing duration last, then duration desc, created desc, id desc", () => {
|
||||
const a = run({ id: 1, created_at: "2026-10-19T10:00:00Z", finished_at: "2026-10-19T10:05:00Z" }); // 300
|
||||
const b = run({ id: 2, executing: true, created_at: "2026-10-19T10:00:00Z", finished_at: "" }); // null
|
||||
const c = run({ id: 3, created_at: "2026-10-19T09:00:00Z", finished_at: "2026-10-19T09:10:00Z" }); // 600
|
||||
const d = run({ id: 4, created_at: "2026-10-19T08:00:00Z", finished_at: "2026-10-19T08:05:00Z" }); // 300
|
||||
assert.deepEqual(
|
||||
sortRuns([a, b, c, d], "longest_duration").map((r) => r.id),
|
||||
[3, 1, 4, 2],
|
||||
);
|
||||
});
|
||||
|
||||
test("shortest duration puts a missing duration last, then duration asc, created desc, id desc", () => {
|
||||
const a = run({ id: 1, created_at: "2026-10-19T10:00:00Z", finished_at: "2026-10-19T10:05:00Z" }); // 300
|
||||
const b = run({ id: 2, executing: true, created_at: "2026-10-19T10:00:00Z", finished_at: "" }); // null
|
||||
const c = run({ id: 3, created_at: "2026-10-19T09:00:00Z", finished_at: "2026-10-19T09:10:00Z" }); // 600
|
||||
const d = run({ id: 4, created_at: "2026-10-19T08:00:00Z", finished_at: "2026-10-19T08:05:00Z" }); // 300
|
||||
assert.deepEqual(
|
||||
sortRuns([a, b, c, d], "shortest_duration").map((r) => r.id),
|
||||
[1, 4, 3, 2],
|
||||
);
|
||||
});
|
||||
|
||||
test("pipeline name sorts case-insensitively, then created desc, id desc", () => {
|
||||
const x = run({ id: 1, name: "beta", created_at: "2026-10-19T10:00:00Z" });
|
||||
const y = run({ id: 2, name: "Alpha", created_at: "2026-10-19T10:00:00Z" });
|
||||
const z = run({ id: 3, name: "alpha", created_at: "2026-10-19T11:00:00Z" });
|
||||
assert.deepEqual(
|
||||
sortRuns([x, y, z], "pipeline_name").map((r) => r.id),
|
||||
[3, 2, 1],
|
||||
);
|
||||
});
|
||||
|
||||
test("status sorts case-insensitively, then created desc, id desc", () => {
|
||||
const p = run({ id: 1, status: "succeeded", created_at: "2026-10-19T10:00:00Z" });
|
||||
const q = run({ id: 2, status: "failed", created_at: "2026-10-19T10:00:00Z" });
|
||||
const r = run({ id: 3, status: "failed", created_at: "2026-10-19T11:00:00Z" });
|
||||
assert.deepEqual(
|
||||
sortRuns([p, q, r], "status").map((r) => r.id),
|
||||
[3, 2, 1],
|
||||
);
|
||||
});
|
||||
|
||||
test("an unknown sort falls back to newest first", () => {
|
||||
const a = run({ id: 1, created_at: "2026-10-19T10:00:00Z" });
|
||||
const b = run({ id: 2, created_at: "2026-10-19T11:00:00Z" });
|
||||
assert.deepEqual(
|
||||
sortRuns([a, b], "not_a_sort").map((r) => r.id),
|
||||
[2, 1],
|
||||
);
|
||||
});
|
||||
|
||||
test("RUN_SORTS and RUN_TIME_RANGES carry the app's exact labels", () => {
|
||||
assert.deepEqual(
|
||||
RUN_SORTS.map((s) => s.label),
|
||||
["Newest first", "Oldest first", "Longest duration", "Shortest duration", "Pipeline name", "Status"],
|
||||
);
|
||||
assert.deepEqual(
|
||||
RUN_TIME_RANGES.map((r) => r.label),
|
||||
["Any time", "Today", "Last 7 days", "Last 30 days"],
|
||||
);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Day grouping
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("dayLabel renders Today / Yesterday / d MMM yyyy / Unknown date", () => {
|
||||
assert.equal(dayLabel("2026-10-19T01:00:00Z", TODAY, ZONE), "Today");
|
||||
assert.equal(dayLabel("2026-10-18T23:00:00Z", TODAY, ZONE), "Yesterday");
|
||||
assert.equal(dayLabel("2026-10-16T23:00:00Z", TODAY, ZONE), "16 Oct 2026");
|
||||
assert.equal(dayLabel("", TODAY, ZONE), "Unknown date");
|
||||
assert.equal(dayLabel("not-a-date", TODAY, ZONE), "Unknown date");
|
||||
assert.equal(localDayKey("2026-10-19T01:00:00Z", ZONE), "2026-10-19");
|
||||
assert.equal(localDayKey("", ZONE), null);
|
||||
});
|
||||
|
||||
test("groupRunsByDay follows the sort order and preserves it within a day", () => {
|
||||
const r1 = run({ id: 1, created_at: "2026-10-19T10:00:00Z" });
|
||||
const r2 = run({ id: 2, created_at: "2026-10-19T09:00:00Z" });
|
||||
const r3 = run({ id: 3, created_at: "2026-10-18T12:00:00Z" });
|
||||
const r4 = run({ id: 4, created_at: "" });
|
||||
const groups = groupRunsByDay([r2, r1, r4, r3], TODAY, ZONE, runComparator("newest_first"));
|
||||
assert.deepEqual(
|
||||
groups.map((g) => g.label),
|
||||
["Today", "Yesterday", "Unknown date"],
|
||||
);
|
||||
assert.deepEqual(
|
||||
groups[0].runs.map((r) => r.id),
|
||||
[1, 2],
|
||||
);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// The list's slots
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("runListEntries orders usage, the empty state, groups and the inline error", () => {
|
||||
const usage = { total: 3 };
|
||||
const recorded = runListEntries(usage, true, true, [], null);
|
||||
assert.deepEqual(
|
||||
recorded.map((e) => e.kind),
|
||||
["usage", "empty"],
|
||||
);
|
||||
assert.equal(recorded[1].message, NO_RUNS_MESSAGE);
|
||||
assert.equal(recorded[1].actionLabel, null);
|
||||
|
||||
const matched = runListEntries(null, false, true, [], "boom");
|
||||
assert.deepEqual(
|
||||
matched.map((e) => e.kind),
|
||||
["empty", "error"],
|
||||
);
|
||||
assert.equal(matched[0].message, NO_MATCH_MESSAGE);
|
||||
assert.equal(matched[0].actionLabel, "Clear filters");
|
||||
|
||||
const groups = [{ label: "Today", runs: [run({ id: 1 }), run({ id: 2 })] }];
|
||||
const body = runListEntries(null, false, false, groups, null);
|
||||
assert.deepEqual(
|
||||
body.map((e) => e.kind),
|
||||
["day", "run", "run"],
|
||||
);
|
||||
assert.equal(body[0].label, "Today");
|
||||
assert.deepEqual(
|
||||
body.filter((e) => e.kind === "run").map((e) => e.run.id),
|
||||
[1, 2],
|
||||
);
|
||||
});
|
||||
+170
-3
@@ -79,10 +79,177 @@ try {
|
||||
await page.waitForSelector(".detail h2");
|
||||
shots.push(await page.screenshot(`${out}/02-pipeline-detail.png`));
|
||||
|
||||
step("switching to Runs and opening a run detail");
|
||||
step("switching to Runs: day-grouped list + usage roll-up");
|
||||
await page.clickText("nav.tabs button.tab", "Runs");
|
||||
await page.waitForSelector(".list button.row", { timeout: 25000 });
|
||||
await page.click(".list button.row");
|
||||
await page.waitForSelector(".list.runs .day-header", { timeout: 25000 });
|
||||
await page.waitForSelector(".metrics .metric", { timeout: 25000 });
|
||||
const usageLabels = await page.evaluate(
|
||||
`[...document.querySelectorAll(".metrics .metric-label")].map((n) => n.textContent)`,
|
||||
);
|
||||
for (const label of ["Total", "Succeeded", "Failed", "Canceled", "Interrupted", "Active"]) {
|
||||
if (!usageLabels.includes(label)) throw new Error(`usage metric missing: ${label}`);
|
||||
}
|
||||
const dayHeaders = await page.evaluate(
|
||||
`[...document.querySelectorAll(".list.runs .day-header")].map((n) => n.textContent)`,
|
||||
);
|
||||
if (!dayHeaders.length) throw new Error("no day header rendered");
|
||||
if (!dayHeaders.includes("Today")) {
|
||||
throw new Error(`the list does not start with Today: ${dayHeaders.join(" | ")}`);
|
||||
}
|
||||
const fullDateHeader = dayHeaders.find((label) => /^\d{1,2} \w{3} \d{4}$/.test(label));
|
||||
if (!fullDateHeader) throw new Error(`no full-date day header: ${dayHeaders.join(" | ")}`);
|
||||
shots.push(await page.screenshot(`${out}/04-runs-day-groups.png`));
|
||||
console.log(` usage: ${usageLabels.join(", ")}`);
|
||||
console.log(` day headers: ${dayHeaders.slice(0, 3).join(" | ")}`);
|
||||
|
||||
step(`scrolling the list to the older day group (${fullDateHeader})`);
|
||||
const scrolledTo = await page.evaluate(`(() => {
|
||||
const scroll = document.querySelector(".run-scroll");
|
||||
const header = [...document.querySelectorAll(".list.runs .day-header")]
|
||||
.find((n) => /^\\d{1,2} \\w{3} \\d{4}$/.test(n.textContent));
|
||||
if (!scroll || !header) return null;
|
||||
scroll.scrollTop += header.getBoundingClientRect().top - scroll.getBoundingClientRect().top;
|
||||
return header.textContent;
|
||||
})()`);
|
||||
if (!scrolledTo) throw new Error("could not scroll to the older day group");
|
||||
shots.push(await page.screenshot(`${out}/07-runs-older-day-group.png`));
|
||||
console.log(` scrolled to: ${scrolledTo}`);
|
||||
|
||||
step("opening the filter menu: it must stay in the viewport and be reachable");
|
||||
await page.click("#runFilterBtn");
|
||||
await page.waitForSelector("#runFilterMenu");
|
||||
const menuLabels = await page.evaluate(
|
||||
`[...document.querySelectorAll("#runFilterMenu .filter-check span")].map((n) => n.textContent)`,
|
||||
);
|
||||
for (const label of [
|
||||
"queued",
|
||||
"running",
|
||||
"waiting",
|
||||
"succeeded",
|
||||
"failed",
|
||||
"canceled",
|
||||
"interrupted",
|
||||
"Any pipeline",
|
||||
"Any time",
|
||||
"Today",
|
||||
"Last 7 days",
|
||||
"Last 30 days",
|
||||
]) {
|
||||
if (!menuLabels.includes(label)) throw new Error(`filter menu missing: ${label}`);
|
||||
}
|
||||
const menuActions = await page.evaluate(
|
||||
`[...document.querySelectorAll("#runFilterMenu .menu-actions button")].map((n) => n.textContent)`,
|
||||
);
|
||||
for (const label of ["Clear filters", "Done"]) {
|
||||
if (!menuActions.includes(label)) throw new Error(`filter menu action missing: ${label}`);
|
||||
}
|
||||
// The gate is reachability, not DOM presence: with a busy history the menu is
|
||||
// taller than the viewport, so it must be bounded and scroll its own box rather
|
||||
// than being clipped by an ancestor with no way for a user to reach the actions.
|
||||
const reach = await page.evaluate(`(() => {
|
||||
const menu = document.querySelector("#runFilterMenu");
|
||||
const overflowY = getComputedStyle(menu).overflowY;
|
||||
const rect = menu.getBoundingClientRect();
|
||||
menu.scrollTop = menu.scrollHeight;
|
||||
const actions = menu.querySelector(".menu-actions").getBoundingClientRect();
|
||||
return {
|
||||
overflowY,
|
||||
height: Math.round(rect.height),
|
||||
viewport: window.innerHeight,
|
||||
fitsViewport: rect.height <= window.innerHeight && rect.bottom <= window.innerHeight + 1,
|
||||
actionsReachable: actions.bottom <= window.innerHeight + 1 && actions.top >= -1,
|
||||
};
|
||||
})()`);
|
||||
if (reach.overflowY !== "auto" && reach.overflowY !== "scroll") {
|
||||
throw new Error(`the filter menu does not scroll its own box: overflow-y=${reach.overflowY}`);
|
||||
}
|
||||
if (!reach.fitsViewport) {
|
||||
throw new Error(`the filter menu overflows the viewport: ${JSON.stringify(reach)}`);
|
||||
}
|
||||
if (!reach.actionsReachable) {
|
||||
throw new Error(`the filter menu actions are unreachable: ${JSON.stringify(reach)}`);
|
||||
}
|
||||
shots.push(await page.screenshot(`${out}/08-runs-filter-menu.png`));
|
||||
console.log(` filter menu ${reach.height}px tall in a ${reach.viewport}px viewport; actions reachable`);
|
||||
|
||||
step("applying a status filter");
|
||||
await page.evaluate(
|
||||
`document.querySelector('#runFilterMenu input[data-status="failed"]').click()`,
|
||||
);
|
||||
const filterLabel = await page.evaluate(`document.querySelector("#runFilterBtn").textContent`);
|
||||
if (!filterLabel.includes("(1)")) {
|
||||
throw new Error(`filter control is missing the active count: ${filterLabel}`);
|
||||
}
|
||||
await page.click("#runFilterBtn"); // close the menu so the list is unobstructed
|
||||
const filteredChips = await page.evaluate(
|
||||
`[...document.querySelectorAll(".list.runs .run-row .run-row-head .chip")].map((n) => n.textContent)`,
|
||||
);
|
||||
if (!filteredChips.length) throw new Error("the status filter produced no rows");
|
||||
if (!filteredChips.every((chip) => chip === "failed")) {
|
||||
throw new Error(`filtered rows are not all failed: ${filteredChips.join(",")}`);
|
||||
}
|
||||
shots.push(await page.screenshot(`${out}/05-runs-filtered.png`));
|
||||
console.log(` filtered rows: ${filteredChips.length}, all failed`);
|
||||
|
||||
step("filtering to a state with no runs: the filtered-empty state + Clear filters");
|
||||
await page.click("#runFilterBtn");
|
||||
await page.waitForSelector("#runFilterMenu");
|
||||
await page.evaluate(
|
||||
`document.querySelector('#runFilterMenu input[data-status="failed"]').click()`,
|
||||
);
|
||||
await page.evaluate(
|
||||
`document.querySelector('#runFilterMenu input[data-status="interrupted"]').click()`,
|
||||
);
|
||||
await page.click("#runFilterBtn"); // close the menu to see the list
|
||||
await page.waitForSelector(".list.runs .empty-state");
|
||||
const emptyMessage = await page.evaluate(
|
||||
`document.querySelector(".list.runs .empty-state span")?.textContent ?? ""`,
|
||||
);
|
||||
if (emptyMessage !== "No runs match the current filters.") {
|
||||
throw new Error(`unexpected filtered-empty message: ${emptyMessage}`);
|
||||
}
|
||||
const clearAction = await page.evaluate(
|
||||
`document.querySelector(".list.runs .empty-state button")?.textContent ?? null`,
|
||||
);
|
||||
if (clearAction !== "Clear filters") {
|
||||
throw new Error(`the filtered-empty state should offer Clear filters, got: ${clearAction}`);
|
||||
}
|
||||
shots.push(await page.screenshot(`${out}/09-runs-filtered-empty.png`));
|
||||
console.log(` empty state: ${emptyMessage} (+ ${clearAction})`);
|
||||
|
||||
step("clearing the filters from the empty state and changing the sort");
|
||||
await page.click(".list.runs .empty-state button");
|
||||
await page.waitForSelector(".list.runs .day-header", { timeout: 25000 });
|
||||
const resetLabel = await page.evaluate(`document.querySelector("#runFilterBtn").textContent`);
|
||||
if (resetLabel.includes("(")) throw new Error(`Clear filters did not reset the count: ${resetLabel}`);
|
||||
await page.click("#runSortBtn");
|
||||
await page.waitForSelector("#runSortMenu");
|
||||
const sortItems = await page.evaluate(
|
||||
`[...document.querySelectorAll("#runSortMenu .menu-item")].map((n) => n.textContent)`,
|
||||
);
|
||||
for (const label of [
|
||||
"Newest first",
|
||||
"Oldest first",
|
||||
"Longest duration",
|
||||
"Shortest duration",
|
||||
"Pipeline name",
|
||||
"Status",
|
||||
"Reset",
|
||||
]) {
|
||||
if (!sortItems.includes(label)) throw new Error(`sort menu missing: ${label}`);
|
||||
}
|
||||
shots.push(await page.screenshot(`${out}/10-runs-sort-menu.png`));
|
||||
await page.clickText("#runSortMenu .menu-item", "Pipeline name");
|
||||
const sortLabel = await page.evaluate(`document.querySelector("#runSortBtn").textContent`);
|
||||
if (!sortLabel.includes("Pipeline name")) {
|
||||
throw new Error(`the sort control did not change: ${sortLabel}`);
|
||||
}
|
||||
await page.waitForSelector(".list.runs .run-row", { timeout: 25000 });
|
||||
shots.push(await page.screenshot(`${out}/06-runs-sorted.png`));
|
||||
console.log(` sort control now: ${sortLabel}`);
|
||||
|
||||
step("opening a run detail");
|
||||
await page.click(".list.runs .run-row");
|
||||
await page.waitForSelector(".detail h2", { timeout: 25000 });
|
||||
shots.push(await page.screenshot(`${out}/03-run-detail.png`));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user