Skip to content
54 changes: 51 additions & 3 deletions dashboard/e2e/deliveries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ interface Backend {
redelivered: string[];
}

async function setup(page: Page, opts: { empty?: boolean } = {}): Promise<Backend> {
type Sharing = { available: boolean; enabled: boolean; payloads: boolean } | undefined;

async function setup(page: Page, opts: { empty?: boolean; sharing?: Sharing | "absent" } = {}): Promise<Backend> {
const db: Backend = { empty: !!opts.empty, lists: [], redelivered: [] };
const json = (route: Route, body: unknown, status = 200) => route.fulfill({ status, contentType: "application/json", body: JSON.stringify(body) });
await page.route((url) => url.pathname === "/runtime-config.js", (route) => route.fulfill({ contentType: "text/javascript", body: "window.__CODERHELM_CONFIG__ = {};" }));
Expand All @@ -91,7 +93,7 @@ async function setup(page: Page, opts: { empty?: boolean } = {}): Promise<Backen
summary: db.empty ? { total: 0, ok: 0, failed: 0, pending: 0, success_rate: null, oldest_pending_at: null, last_failure_at: null } : SUMMARY,
sources: db.empty ? [] : ["github", "jira", "relay", "slack"],
retention_days: 14,
sharing: { available: true, enabled: false, payloads: false },
...(opts.sharing === "absent" ? {} : { sharing: opts.sharing ?? { available: true, enabled: false, payloads: false } }),
hybrid: true,
});
}
Expand Down Expand Up @@ -126,7 +128,8 @@ test("list: health summary, relay note, sharing note and every row", async ({ pa
await expect(page.getByTestId("stat-pending")).toContainText("Oldest from 12 min ago");
await expect(page.getByTestId("relay-note")).toBeVisible();
await expect(page.getByTestId("sharing-note")).toHaveAttribute("data-enabled", "false");
await expect(page.getByTestId("sharing-note").getByRole("link", { name: "Turn on sharing" })).toHaveAttribute("href", /\/settings\/system\/?#hybrid$/);
await expect(page.getByTestId("sharing-note")).toHaveText(/Not shared with Coderhelm support/);
await expect(page.getByTestId("sharing-note").getByRole("link", { name: /Change/ })).toHaveAttribute("href", /\/settings\/system\/?#hybrid-sharing$/);
const rows = page.getByTestId("delivery-row");
await expect(rows).toHaveCount(4);
await expect(rows.nth(0)).toContainText("pull_request.opened");
Expand Down Expand Up @@ -286,3 +289,48 @@ for (const [label, viewport] of [["1440", { width: 1440, height: 1000 }], ["390"
});
});
}

// The one line at the top: shared or not, and how much; left out on the hosted
// product (sharing isn't available there, or the answer has no sharing at all).
for (const [name, sharing, words] of [
["details only", { available: true, enabled: true, payloads: false }, "Failed deliveries are shared with Coderhelm support (details only)"],
["details and payloads", { available: true, enabled: true, payloads: true }, "Failed deliveries are shared with Coderhelm support (details and payload previews)"],
["not shared", { available: true, enabled: false, payloads: false }, "Not shared with Coderhelm support"],
] as const) {
test(`sharing line: ${name}`, async ({ page }) => {
await setup(page, { sharing: { ...sharing } });
await page.goto("/settings/deliveries/");
const note = page.getByTestId("sharing-note");
await expect(note).toContainText(words);
if (sharing.payloads) await expect(note).not.toContainText("details only");
const link = note.getByRole("link", { name: /Change/ });
await expect(link).toHaveAttribute("href", /\/settings\/system\/?#hybrid-sharing$/);
// It sits above the health tiles.
const noteBox = await note.boundingBox();
const tileBox = await page.getByTestId("stat-success").boundingBox();
expect(noteBox!.y).toBeLessThan(tileBox!.y);
if (name === "details only") {
fs.mkdirSync(SHOTS_DIR, { recursive: true });
await page.addStyleTag({ content: "nextjs-portal{display:none!important}" });
for (const width of [1440, 390]) {
await page.setViewportSize({ width, height: 900 });
await page.waitForTimeout(250);
const overflow = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
expect(overflow, `deliveries scrolls sideways at ${width}px`).toBeLessThanOrEqual(0);
await page.screenshot({ path: path.join(SHOTS_DIR, `deliveries-sharing-${width}.png`), fullPage: true });
}
}
});
}

for (const [name, sharing] of [
["hosted (not available)", { available: false, enabled: false, payloads: false }],
["absent from the answer", "absent"],
] as const) {
test(`sharing line: left out when ${name}`, async ({ page }) => {
await setup(page, { sharing: sharing === "absent" ? "absent" : { ...sharing } });
await page.goto("/settings/deliveries/");
await expect(page.getByTestId("stat-success")).toBeVisible();
await expect(page.getByTestId("sharing-note")).toHaveCount(0);
});
}
Loading
Loading