Page MenuHomeSealhub

field.test.ts
No OneTemporary

field.test.ts

import Router from "@koa/router";
import getPort from "get-port";
import { Browser, Page } from "playwright";
import type { Context } from "koa";
import Koa from "koa";
import { mount } from "../../mount.js";
import { Form } from "../form.js";
import { getBrowser } from "../../utils/browser-creator.js";
import assert from "assert";
import { SimpleFormField } from "./simple-form-field.js";
import { SimpleInput } from "../controls/simple-input.js";
import { FormData } from "../form-types.js";
describe("basic field", () => {
describe("basic tests", async () => {
let server: ReturnType<Koa["listen"]>;
let browser: Browser;
let page: Page;
afterEach(() => {
server.close();
});
it("sends the values", async () => {
const port = await getPort();
console.log(`Using port ${port} form checkboxed-list-input.test.ts`);
const app = new Koa();
const router = new Router();
const fields = {
text: new SimpleFormField(true),
};
let received_values: unknown;
mount(
router,
"/",
new (class extends Form<typeof fields, unknown> {
fields = fields;
controls = [new SimpleInput(fields.text)];
async onSubmit(ctx: Context, data: FormData) {
received_values = await this.getParsedValues(ctx);
const { parsed: email } = await this.fields.text.getValue(
ctx,
data.raw_values
);
email?.padStart(2, "0"); // if the typechecks are ok, this will not throw
}
async canAccess(_: Context) {
return { canAccess: true, message: "" };
}
})(),
true
);
app.use(router.routes()).use(router.allowedMethods());
server = app.listen(port);
browser = await getBrowser();
const context = await browser.newContext();
page = await context.newPage();
await page.goto(`http://localhost:${port}`);
});
});
});

File Metadata

Mime Type
text/x-java
Expires
Tue, Dec 24, 14:06 (10 m, 34 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
557345
Default Alt Text
field.test.ts (1 KB)

Event Timeline