@sealcode/sealgen 0.14.13 → 0.14.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/src/page/mountable-with-fields.d.ts +2 -1
- package/dist/forms/form.js +1 -1
- package/dist/forms/form.test.js +40 -0
- package/dist/page/mountable-with-fields.js +4 -1
- package/package.json +1 -1
- package/src/forms/controls/checkboxed-list-input.test.ts +0 -1
- package/src/forms/form.test.ts +46 -1
- package/src/forms/form.ts +3 -1
- package/src/page/mountable-with-fields.ts +8 -2
|
@@ -18,10 +18,11 @@ export declare abstract class MountableWithFields<F extends Fields = Fields> ext
|
|
|
18
18
|
constructor();
|
|
19
19
|
init(): void;
|
|
20
20
|
makeFormControlContext(ctx: Context, data: FormData, validate: boolean, field_name_prefix?: string, form_id?: string): FormControlContext;
|
|
21
|
-
validateValues(
|
|
21
|
+
validateValues(_ctx: Context, _data: Record<string, FormDataValue>): Promise<{
|
|
22
22
|
valid: boolean;
|
|
23
23
|
error: string;
|
|
24
24
|
}>;
|
|
25
|
+
getInitialValues(_ctx: Context): Promise<Record<string, FormDataValue>>;
|
|
25
26
|
validate(ctx: Context, values: Record<string, FormDataValue>): Promise<{
|
|
26
27
|
valid: boolean;
|
|
27
28
|
field_errors: Partial<Record<keyof Fields, string>>;
|
package/dist/forms/form.js
CHANGED
|
@@ -194,7 +194,7 @@ class Form extends MountableWithFields {
|
|
|
194
194
|
router.use(path, subrouter.routes(), subrouter.allowedMethods());
|
|
195
195
|
}
|
|
196
196
|
async extractRawValues(ctx) {
|
|
197
|
-
return ctx.$body;
|
|
197
|
+
return Object.keys(ctx.$body).length ? ctx.$body : this.getInitialValues(ctx);
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
export {
|
package/dist/forms/form.test.js
CHANGED
|
@@ -8,6 +8,8 @@ import { locator_is_visible } from "../test_utils/locator_is_visible.js";
|
|
|
8
8
|
import { getBrowser } from "../utils/browser-creator.js";
|
|
9
9
|
import { assertThrowsAsync } from "../utils/utils.js";
|
|
10
10
|
import getPort from "get-port";
|
|
11
|
+
import { SimpleFormField } from "./fields/simple-form-field.js";
|
|
12
|
+
import { expect as PlaywritghtExpect } from "@playwright/test";
|
|
11
13
|
const fields = {
|
|
12
14
|
text: new Fields.SimpleFormField(true)
|
|
13
15
|
};
|
|
@@ -311,6 +313,44 @@ describe("form test", () => {
|
|
|
311
313
|
});
|
|
312
314
|
});
|
|
313
315
|
});
|
|
316
|
+
describe("getInitialValues tests", async () => {
|
|
317
|
+
let server;
|
|
318
|
+
afterEach(async () => {
|
|
319
|
+
server.close();
|
|
320
|
+
});
|
|
321
|
+
it("fills the form with values from getInitialValues", async () => {
|
|
322
|
+
const app = new Koa();
|
|
323
|
+
const router = new Router();
|
|
324
|
+
const fields2 = {
|
|
325
|
+
title: new SimpleFormField(true)
|
|
326
|
+
};
|
|
327
|
+
mount(
|
|
328
|
+
router,
|
|
329
|
+
"/",
|
|
330
|
+
new class extends Form {
|
|
331
|
+
constructor() {
|
|
332
|
+
super(...arguments);
|
|
333
|
+
this.fields = fields2;
|
|
334
|
+
this.controls = [new Controls.SimpleInput(fields2.title)];
|
|
335
|
+
}
|
|
336
|
+
async getInitialValues() {
|
|
337
|
+
return { title: "Hello" };
|
|
338
|
+
}
|
|
339
|
+
onSubmit() {
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
}(),
|
|
343
|
+
true
|
|
344
|
+
);
|
|
345
|
+
app.use(router.routes()).use(router.allowedMethods());
|
|
346
|
+
server = app.listen(port);
|
|
347
|
+
const response = await page.goto(`http://localhost:${port}`);
|
|
348
|
+
if (response?.status() != 200) {
|
|
349
|
+
throw new Error(`Should return 200 status and it returns ${response?.status()}`);
|
|
350
|
+
}
|
|
351
|
+
await PlaywritghtExpect(page.getByLabel("title")).toHaveValue("Hello");
|
|
352
|
+
});
|
|
353
|
+
});
|
|
314
354
|
});
|
|
315
355
|
export {
|
|
316
356
|
form_factory
|
|
@@ -28,12 +28,15 @@ class MountableWithFields extends Mountable {
|
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
30
|
// this one is meant to be overwritten
|
|
31
|
-
async validateValues(
|
|
31
|
+
async validateValues(_ctx, _data) {
|
|
32
32
|
return {
|
|
33
33
|
valid: true,
|
|
34
34
|
error: ""
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
+
async getInitialValues(_ctx) {
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
37
40
|
async validate(ctx, values) {
|
|
38
41
|
const field_errors = {};
|
|
39
42
|
let valid = true;
|
package/package.json
CHANGED
|
@@ -8,7 +8,6 @@ import { CheckboxedListField } from "../fields/checkboxed-list.js";
|
|
|
8
8
|
import { Form } from "../form.js";
|
|
9
9
|
import { CheckboxedListInput } from "./checkboxed-list-input.js";
|
|
10
10
|
import { getBrowser } from "../../utils/browser-creator.js";
|
|
11
|
-
import { sleep } from "../../utils/sleep.js";
|
|
12
11
|
|
|
13
12
|
describe.only("checkboxed-list", () => {
|
|
14
13
|
describe("basic tests", async () => {
|
package/src/forms/form.test.ts
CHANGED
|
@@ -7,9 +7,11 @@ import { Controls, Fields, Form, Mountable } from "../index.js";
|
|
|
7
7
|
import { mount } from "../mount.js";
|
|
8
8
|
import { locator_is_visible } from "../test_utils/locator_is_visible.js";
|
|
9
9
|
import { getBrowser } from "../utils/browser-creator.js";
|
|
10
|
-
import { assertThrowsAsync } from "../utils/utils.js";
|
|
10
|
+
import { assertThrowsAsync, sleep } from "../utils/utils.js";
|
|
11
11
|
import { FormDataValue } from "./form-types.js";
|
|
12
12
|
import getPort from "get-port";
|
|
13
|
+
import { SimpleFormField } from "./fields/simple-form-field.js";
|
|
14
|
+
import { expect as PlaywritghtExpect } from "@playwright/test";
|
|
13
15
|
|
|
14
16
|
const fields = {
|
|
15
17
|
text: new Fields.SimpleFormField(true),
|
|
@@ -355,4 +357,47 @@ describe("form test", () => {
|
|
|
355
357
|
});
|
|
356
358
|
});
|
|
357
359
|
});
|
|
360
|
+
|
|
361
|
+
describe("getInitialValues tests", async () => {
|
|
362
|
+
let server: ReturnType<Koa["listen"]>;
|
|
363
|
+
|
|
364
|
+
afterEach(async () => {
|
|
365
|
+
server.close();
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it("fills the form with values from getInitialValues", async () => {
|
|
369
|
+
const app = new Koa();
|
|
370
|
+
const router = new Router();
|
|
371
|
+
|
|
372
|
+
const fields = {
|
|
373
|
+
title: new SimpleFormField(true),
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
mount(
|
|
377
|
+
router,
|
|
378
|
+
"/",
|
|
379
|
+
new (class extends Form<typeof fields, null> {
|
|
380
|
+
fields = fields;
|
|
381
|
+
controls = [new Controls.SimpleInput(fields.title)];
|
|
382
|
+
|
|
383
|
+
async getInitialValues() {
|
|
384
|
+
return { title: "Hello" };
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
onSubmit() {
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
})(),
|
|
391
|
+
true
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
app.use(router.routes()).use(router.allowedMethods());
|
|
395
|
+
server = app.listen(port);
|
|
396
|
+
const response = await page.goto(`http://localhost:${port}`);
|
|
397
|
+
if (response?.status() != 200) {
|
|
398
|
+
throw new Error(`Should return 200 status and it returns ${response?.status()}`);
|
|
399
|
+
}
|
|
400
|
+
await PlaywritghtExpect(page.getByLabel("title")).toHaveValue("Hello");
|
|
401
|
+
});
|
|
402
|
+
});
|
|
358
403
|
});
|
package/src/forms/form.ts
CHANGED
|
@@ -55,8 +55,8 @@ export abstract class MountableWithFields<
|
|
|
55
55
|
|
|
56
56
|
// this one is meant to be overwritten
|
|
57
57
|
async validateValues(
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
_ctx: Context,
|
|
59
|
+
_data: Record<string, FormDataValue>
|
|
60
60
|
): Promise<{ valid: boolean; error: string }> {
|
|
61
61
|
return {
|
|
62
62
|
valid: true,
|
|
@@ -64,6 +64,12 @@ export abstract class MountableWithFields<
|
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
async getInitialValues(
|
|
68
|
+
_ctx: Context
|
|
69
|
+
): Promise<Record<string, FormDataValue>> {
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
72
|
+
|
|
67
73
|
async validate(
|
|
68
74
|
ctx: Context,
|
|
69
75
|
values: Record<string, FormDataValue>
|