import { Context } from "koa"; import { Templatable, tempstream } from "tempstream"; import { ExtractStatefulPageActionArgs, StatefulPage, StatefulPageActionArgument, } from "./stateful-page.js"; describe("stateful page", () => { it("has types that allow for extracting action argument types", () => { type TestState = {}; const action = async ({}: StatefulPageActionArgument) => {}; type Args = ExtractStatefulPageActionArgs; const a = [2] as Args; // should not throw a typescript error; }); it("handles a basic case with action buttons", () => { type TestState = {}; const actions = { some_action: async ({}: StatefulPageActionArgument) => {}, }; new (class extends StatefulPage { actions = actions; getInitialState(_ctx: Context) { return {}; } wrapInLayout(_ctx: Context, content: Templatable, _state: TestState): Templatable { return content; } render(_ctx: Context, state: TestState) { return tempstream`
${this.makeActionButton(state, "some_action", 2)}
`; } })(); }); });