import assert from "node:assert/strict";
import test from "node:test";

test("renders the calculator shell", async () => {
  const workerUrl = new URL("../dist/server/index.js", import.meta.url);
  workerUrl.searchParams.set("test", `${process.pid}-${Date.now()}`);
  const { default: worker } = await import(workerUrl.href);

  const response = await worker.fetch(
    new Request("http://localhost/", {
      headers: { accept: "text/html" },
    }),
    {
      ASSETS: {
        fetch: async () => new Response("Not found", { status: 404 }),
      },
    },
    {
      waitUntil() {},
      passThroughOnException() {},
    },
  );

  assert.equal(response.status, 200);
  assert.match(
    response.headers.get("content-type") ?? "",
    /^text\/html\b/i,
  );
  const html = await response.text();
  assert.match(html, /Factorio Production Calculator/);
  assert.match(html, /No product selected yet/);
  assert.match(html, /324(?:<!-- -->)?\s*(?:<!-- -->)?player recipes/);
  assert.match(html, /Quality recycling/);
  assert.match(html, />Energy</);
  assert.match(html, /Rocket freight/);
  assert.match(html, />Help</);
  assert.doesNotMatch(html, /Blue-outlined fields are editable/);
});
