Page MenuHomeSealhub

stateful-page.test.ts
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

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
application/javascript
Expires
Fri, Nov 27, 17:08 (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1200099
Default Alt Text
stateful-page.test.ts (1 KB)

Event Timeline