Page MenuHomeSealhub

stateful-page.test.ts
No OneTemporary

stateful-page.test.ts

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<TestState, [number]>) => {};
type Args = ExtractStatefulPageActionArgs<typeof action>;
const a = [2] as Args; // should not throw a typescript error;
});
it("handles a basic case with action buttons", () => {
type TestState = {};
const actions = <const>{
some_action: async ({}: StatefulPageActionArgument<TestState, [number]>) => {},
};
new (class extends StatefulPage<TestState, typeof actions> {
actions = actions;
getInitialState(_ctx: Context) {
return {};
}
wrapInLayout(_ctx: Context, content: Templatable, _state: TestState): Templatable {
return content;
}
render(_ctx: Context, state: TestState) {
return tempstream`<div>${this.makeActionButton(state, "some_action", 2)}</div>`;
}
})();
});
});

File Metadata

Mime Type
text/x-java
Expires
Fri, Jan 24, 15:15 (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
599851
Default Alt Text
stateful-page.test.ts (1 KB)

Event Timeline