public commit

This commit is contained in:
dswbx
2024-11-16 12:01:47 +01:00
commit 90f80c4280
582 changed files with 49291 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
import { describe, expect, test } from "bun:test";
import { JsonField } from "../../../../src/data";
import { runBaseFieldTests, transformPersist } from "./inc";
describe("[data] JsonField", async () => {
const field = new JsonField("test");
runBaseFieldTests(JsonField, {
defaultValue: { a: 1 },
sampleValues: ["string", { test: 1 }, 1],
schemaType: "text"
});
test("transformPersist (no config)", async () => {
expect(transformPersist(field, Function)).rejects.toThrow();
expect(transformPersist(field, undefined)).resolves.toBeUndefined();
});
test("isSerializable", async () => {
expect(field.isSerializable(1)).toBe(true);
expect(field.isSerializable("test")).toBe(true);
expect(field.isSerializable({ test: 1 })).toBe(true);
expect(field.isSerializable({ test: [1, 2] })).toBe(true);
expect(field.isSerializable(Function)).toBe(false);
expect(field.isSerializable(undefined)).toBe(false);
});
test("isSerialized", async () => {
expect(field.isSerialized(1)).toBe(false);
expect(field.isSerialized({ test: 1 })).toBe(false);
expect(field.isSerialized('{"test":1}')).toBe(true);
expect(field.isSerialized("1")).toBe(true);
});
test("getValue", async () => {
expect(field.getValue({ test: 1 }, "form")).toBe('{"test":1}');
expect(field.getValue("string", "form")).toBe('"string"');
expect(field.getValue(1, "form")).toBe("1");
expect(field.getValue('{"test":1}', "submit")).toEqual({ test: 1 });
expect(field.getValue('"string"', "submit")).toBe("string");
expect(field.getValue("1", "submit")).toBe(1);
expect(field.getValue({ test: 1 }, "table")).toBe('{"test":1}');
expect(field.getValue("string", "table")).toBe('"string"');
expect(field.getValue(1, "form")).toBe("1");
});
});