parent
ed1bfd464a
commit
a804ce9cab
1 changed files with 69 additions and 40 deletions
|
@ -2,24 +2,55 @@ import {describe, expect, test} from "vitest";
|
||||||
import {s, StringType} from "../../../src/library";
|
import {s, StringType} from "../../../src/library";
|
||||||
|
|
||||||
describe("string type", () => {
|
describe("string type", () => {
|
||||||
test("string type definition", () => {
|
test("definition", () => {
|
||||||
const stringType = s.property.string();
|
const stringType = s.property.string();
|
||||||
expect(stringType.type).toBeInstanceOf(StringType);
|
expect(stringType.type).toBeInstanceOf(StringType);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("string type functions", () => {
|
test("serialize", () => {
|
||||||
expect(s.property.string().type.serialize("test")).toBe("test");
|
expect(s.property.string().type.serialize("test")).toBe("test");
|
||||||
expect(s.property.string().type.deserialize("test")).toBe("test");
|
|
||||||
expect(s.property.string().type.serializeDiff("test")).toBe("test");
|
|
||||||
|
|
||||||
expect(s.property.string().type.serialize(null)).toBe(null);
|
expect(s.property.string().type.serialize(null)).toBe(null);
|
||||||
expect(s.property.string().type.deserialize(null)).toBe(null);
|
|
||||||
expect(s.property.string().type.serializeDiff(null)).toBe(null);
|
|
||||||
|
|
||||||
expect(s.property.string().type.serialize(undefined)).toBe(undefined);
|
expect(s.property.string().type.serialize(undefined)).toBe(undefined);
|
||||||
|
|
||||||
|
test("invalid parameters", () => {
|
||||||
|
const testDate = new Date();
|
||||||
|
expect(s.property.string().type.serialize({} as any)).toBe(
|
||||||
|
"[object Object]",
|
||||||
|
);
|
||||||
|
expect(s.property.string().type.serialize(2120 as any)).toBe("2120");
|
||||||
|
expect(s.property.string().type.serialize(testDate as any)).toBe(
|
||||||
|
testDate.toString(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("deserialize", () => {
|
||||||
|
expect(s.property.string().type.deserialize("test")).toBe("test");
|
||||||
|
expect(s.property.string().type.deserialize(null)).toBe(null);
|
||||||
expect(s.property.string().type.deserialize(undefined)).toBe(undefined);
|
expect(s.property.string().type.deserialize(undefined)).toBe(undefined);
|
||||||
|
|
||||||
|
test("invalid parameters", () => {
|
||||||
|
expect(s.property.string().type.deserialize({} as any)).toBe(
|
||||||
|
"[object Object]",
|
||||||
|
);
|
||||||
|
expect(s.property.string().type.deserialize(2120 as any)).toBe("2120");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("serializeDiff", () => {
|
||||||
|
expect(s.property.string().type.serializeDiff("test")).toBe("test");
|
||||||
|
expect(s.property.string().type.serializeDiff(null)).toBe(null);
|
||||||
expect(s.property.string().type.serializeDiff(undefined)).toBe(undefined);
|
expect(s.property.string().type.serializeDiff(undefined)).toBe(undefined);
|
||||||
|
|
||||||
|
test("invalid parameters", () => {
|
||||||
|
expect(s.property.string().type.serializeDiff({} as any)).toBe(
|
||||||
|
"[object Object]",
|
||||||
|
);
|
||||||
|
expect(s.property.string().type.serializeDiff(2120 as any)).toBe("2120");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("hasChanged", () => {
|
||||||
expect(s.property.string().type.hasChanged("test", "test")).toBeFalsy();
|
expect(s.property.string().type.hasChanged("test", "test")).toBeFalsy();
|
||||||
expect(s.property.string().type.hasChanged(null, null)).toBeFalsy();
|
expect(s.property.string().type.hasChanged(null, null)).toBeFalsy();
|
||||||
expect(
|
expect(
|
||||||
|
@ -32,6 +63,17 @@ describe("string type", () => {
|
||||||
expect(s.property.string().type.hasChanged("test", null)).toBeTruthy();
|
expect(s.property.string().type.hasChanged("test", null)).toBeTruthy();
|
||||||
expect(s.property.string().type.hasChanged("test", undefined)).toBeTruthy();
|
expect(s.property.string().type.hasChanged("test", undefined)).toBeTruthy();
|
||||||
|
|
||||||
|
test("invalid parameters", () => {
|
||||||
|
expect(
|
||||||
|
s.property.string().type.hasChanged({} as any, {} as any),
|
||||||
|
).toBeTruthy();
|
||||||
|
expect(
|
||||||
|
s.property.string().type.hasChanged(false as any, false as any),
|
||||||
|
).toBeFalsy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("serializedHasChanged", () => {
|
||||||
expect(
|
expect(
|
||||||
s.property.string().type.serializedHasChanged("test", "test"),
|
s.property.string().type.serializedHasChanged("test", "test"),
|
||||||
).toBeFalsy();
|
).toBeFalsy();
|
||||||
|
@ -60,10 +102,29 @@ describe("string type", () => {
|
||||||
s.property.string().type.serializedHasChanged("test", undefined),
|
s.property.string().type.serializedHasChanged("test", undefined),
|
||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
|
|
||||||
|
test("invalid parameters", () => {
|
||||||
|
expect(
|
||||||
|
s.property.string().type.serializedHasChanged({} as any, {} as any),
|
||||||
|
).toBeTruthy();
|
||||||
|
expect(
|
||||||
|
s.property
|
||||||
|
.string()
|
||||||
|
.type.serializedHasChanged(false as any, false as any),
|
||||||
|
).toBeFalsy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("resetDiff", () => {
|
||||||
s.property.string().type.resetDiff("test");
|
s.property.string().type.resetDiff("test");
|
||||||
s.property.string().type.resetDiff(undefined);
|
s.property.string().type.resetDiff(undefined);
|
||||||
s.property.string().type.resetDiff(null);
|
s.property.string().type.resetDiff(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("clone", () => {
|
||||||
|
expect(s.property.string().type.clone({} as any)).toStrictEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("applyPatch", () => {
|
||||||
expect(s.property.string().type.applyPatch("another", "test", false)).toBe(
|
expect(s.property.string().type.applyPatch("another", "test", false)).toBe(
|
||||||
"test",
|
"test",
|
||||||
);
|
);
|
||||||
|
@ -78,36 +139,4 @@ describe("string type", () => {
|
||||||
).toBeUndefined();
|
).toBeUndefined();
|
||||||
expect(s.property.string().type.applyPatch("test", null, false)).toBeNull();
|
expect(s.property.string().type.applyPatch("test", null, false)).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("invalid parameters types", () => {
|
|
||||||
const testDate = new Date();
|
|
||||||
expect(s.property.string().type.serialize({} as any)).toBe(
|
|
||||||
"[object Object]",
|
|
||||||
);
|
|
||||||
expect(s.property.string().type.serialize(2120 as any)).toBe("2120");
|
|
||||||
expect(s.property.string().type.serialize(testDate as any)).toBe(
|
|
||||||
testDate.toString(),
|
|
||||||
);
|
|
||||||
expect(s.property.string().type.deserialize({} as any)).toBe(
|
|
||||||
"[object Object]",
|
|
||||||
);
|
|
||||||
expect(s.property.string().type.deserialize(2120 as any)).toBe("2120");
|
|
||||||
expect(s.property.string().type.serializeDiff({} as any)).toBe(
|
|
||||||
"[object Object]",
|
|
||||||
);
|
|
||||||
expect(s.property.string().type.serializeDiff(2120 as any)).toBe("2120");
|
|
||||||
expect(
|
|
||||||
s.property.string().type.hasChanged({} as any, {} as any),
|
|
||||||
).toBeTruthy();
|
|
||||||
expect(
|
|
||||||
s.property.string().type.hasChanged(false as any, false as any),
|
|
||||||
).toBeFalsy();
|
|
||||||
expect(
|
|
||||||
s.property.string().type.serializedHasChanged({} as any, {} as any),
|
|
||||||
).toBeTruthy();
|
|
||||||
expect(
|
|
||||||
s.property.string().type.serializedHasChanged(false as any, false as any),
|
|
||||||
).toBeFalsy();
|
|
||||||
expect(s.property.string().type.clone({} as any)).toStrictEqual({});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue