Rebuild printable roast plans and remove machine-based adjustments
Test and deploy / test-and-deploy (push) Successful in 2m28s

This commit is contained in:
snowspeeder committed 2026-09-05 14:56:11 -04:00
1 parent e9f2393c96
commit 824a964f9d
30 files changed
+1721 -908

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
import test from "node:test";
import assert from "node:assert/strict";
import { once } from "node:events";
import { readFile } from "node:fs/promises";
import { setup } from "./helpers.js";
test(
"browser: unit toggles preserve milestone inputs; HTML download and print share the report",
{ skip: process.env.RUN_BROWSER_TESTS !== "1" },
async (t) => {
const { chromium } = await import("playwright");
const { app } = await setup();
const server = app.listen(0, "127.0.0.1");
await once(server, "listening");
t.after(() => new Promise((r) => server.close(r)));
const browser = await chromium.launch({
headless: true,
args: ["--no-sandbox"],
});
t.after(() => browser.close());
const page = await browser.newPage({
viewport: { width: 1440, height: 1100 },
});
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
const base = `http://127.0.0.1:${server.address().port}`;
const signup = await page.request.post(base + "/api/auth/signup", {
data: {
email: "[email protected]",
password: "browser regression password",
},
});
assert.equal(signup.status(), 201);
await page.goto(base + "/app");
for (const [k, v] of Object.entries({
0.1: "Burundi Kayanza Masha",
0.4: "500",
1.1: "Bourbon",
1.4: "8:45",
4.2: "12",
4.3: "1:38",
4.4: "1:15",
5.2: "761.4",
"preheat.tempC": "350",
"preheat.minutes": "20",
"temps.fc.tempC": "392",
}))
await page.locator(`#plan-form input[name="${k}"]`).fill(v);
const temp = page.locator('#plan-form input[name="temps.fc.tempC"]');
for (const [unit, value] of [
["C", "200"],
["F", "392"],
]) {
await page.evaluate((unit) => {
const input = document.querySelector(
`#temp-unit-toggle input[value="${unit}"]`,
);
input.checked = true;
input.dispatchEvent(new Event("change", { bubbles: true }));
}, unit);
assert.equal(await temp.inputValue(), value);
assert.equal(
await page.locator('#sec-machine input[name$=".tempC"]').count(),
6,
);
}
await page
.getByRole("button", { name: "Preview report", exact: true })
.click();
await page
.frameLocator('iframe[title="Printable roast report"]')
.getByRole("heading", { name: "Milestone plan" })
.waitFor();
await page.getByRole("button", { name: "Close preview" }).click();
const pending = page.waitForEvent("download");
await page.getByRole("button", { name: "Download HTML" }).click();
const download = await pending;
assert.match(download.suggestedFilename(), /Burundi.*\.html$/);
const html = await readFile(await download.path(), "utf8");
assert.ok(html.includes("440 g"));
assert.ok(html.includes("350°F"));
assert.ok(html.includes("Development · 1:15"));
assert.ok(!html.includes("°C"));
await page.emulateMedia({ media: "print" });
await page.evaluate(() => window.dispatchEvent(new Event("beforeprint")));
assert.equal(await page.locator("#report-print").isVisible(), true);
assert.equal(await page.locator("#print-sheet").isVisible(), false);
assert.equal(await page.locator("#report-print .sheet").count(), 2);
assert.equal(await page.locator("#report-print svg").count(), 1);
await page.emulateMedia({ media: "screen" });
await page.evaluate(() => window.dispatchEvent(new Event("afterprint")));
await page.goto(base + "/roasters");
assert.deepEqual(errors, []);
},
);