mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 12:56:05 +00:00
public commit
This commit is contained in:
47
app/__test__/data/specs/fields/JsonField.spec.ts
Normal file
47
app/__test__/data/specs/fields/JsonField.spec.ts
Normal 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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user