45 lines
1.9 KiB
TypeScript
45 lines
1.9 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { generate, parse } from "../src/index.ts";
|
|
|
|
test("server-only loader data renders native input attributes without client state", async () => {
|
|
const code = generate(
|
|
parse(`page Profile {
|
|
load server account { return {} }
|
|
view {
|
|
<h1>{account.name}</h1>
|
|
{#if account.readonly}<p>Read only</p>{:else}<p>Editable</p>{/if}
|
|
{#each account.items as item}<strong>{item}</strong>{/each}
|
|
<input value="{account.name}" readonly="{account.readonly}" />
|
|
<select><option value="light" selected="{account.theme === 'light'}">Light</option><option value="dark" selected="{account.theme === 'dark'}">Dark</option></select>
|
|
<div data-component="ProfileShell" identity="{account.identity}"></div>
|
|
}
|
|
}`),
|
|
);
|
|
const javascript = new Bun.Transpiler({ loader: "ts" }).transformSync(code);
|
|
const page = await import(
|
|
`data:text/javascript;base64,${Buffer.from(javascript).toString("base64")}`
|
|
);
|
|
const html = await page.default({
|
|
account: {
|
|
items: ["Example record"],
|
|
name: 'A "<User>"',
|
|
readonly: false,
|
|
theme: "dark",
|
|
identity: { name: "Alice" },
|
|
},
|
|
});
|
|
expect(html).toContain('value="A "<User>""');
|
|
expect(html).not.toContain(" readonly");
|
|
expect(html).toContain('<option value="light">Light</option>');
|
|
expect(html).toContain('<option value="dark" selected>Dark</option>');
|
|
expect(html).toContain('identity="{"name":"Alice"}"');
|
|
expect(html).not.toContain("data-wrn-bind");
|
|
expect(html).not.toContain("{account.");
|
|
expect(html).toContain("<h1>A "<User>"</h1>");
|
|
expect(html).toContain("<p>Editable</p>");
|
|
expect(html).toContain("<strong>Example record</strong>");
|
|
expect(html).not.toContain("data-wrn-if");
|
|
expect(html).not.toContain("data-wrn-each");
|
|
expect(html).not.toContain("data-text");
|
|
});
|