muddle/tests/stage.test.ts
2026-10-23 09:12:49 -04:00

36 lines
1.2 KiB
TypeScript

import { expect, test } from "bun:test";
import { compileTemplate } from "../views/engine/compiler.ts";
import { lex } from "../views/engine/lexer.ts";
import { parse } from "../views/engine/parser.ts";
import { stage } from "../views/stage.ts";
test("stage manager emits native scroll-driven scenes and portal transitions", () => {
const css = stage()
.scene("intro-in", {
selector: ".intro",
keyframes: {
"0%": { opacity: 0, transform: "translateY(2rem)" },
"100%": { opacity: 1, transform: "translateY(0)" },
},
range: "entry 0% cover 45%",
})
.portal("main", {
old: { opacity: 1 },
new: { opacity: 0 },
duration: "180ms",
})
.css();
expect(css).toContain("animation-timeline: view()");
expect(css).toContain("animation-range: entry 0% cover 45%");
expect(css).toContain("::view-transition-old(main)");
});
test("portal blocks compile to named view-transition boundaries", () => {
const parsed = parse(lex("portal main\n h1 Hello"));
const compiled = compileTemplate(parsed.nodes, {
path: "/tmp/portal.spug",
dir: "/tmp",
});
expect(compiled.source).toContain('data-muddle-portal=\\"main\\"');
expect(compiled.source).toContain("view-transition-name:main");
});