import { expect, test } from "bun:test";
import { partialPrerender, streamPartialDocument } from "../src/index.ts";

test("partial prerender extracts and streams dynamic regions after the shell", async () => {
  const result = partialPrerender(
    '<header>Static</header><wrn-dynamic-region data-wrn-dynamic="true"><b>User</b></wrn-dynamic-region><footer>Static</footer>',
  );
  expect(result.shell).toContain("data-wrn-dynamic-placeholder");
  expect(result.regions).toEqual([{ id: "wrn-region-0", html: "<b>User</b>" }]);
  const output = await new Response(streamPartialDocument(result)).text();
  expect(output.indexOf("<header>Static</header>")).toBeLessThan(output.indexOf("<b>User</b>"));
});
