-
Notifications
You must be signed in to change notification settings - Fork 2
/
graph.spec.ts
42 lines (35 loc) · 1.31 KB
/
graph.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { createForm, isField } from "@formily/core";
import { attach } from "./shared";
// 获取表单模型,设置表单模型
test("getGraph/setGraph", () => {
const form = attach(createForm());
attach(form.createField({ name: "normal" }));
attach(form.createArrayField({ name: "array" }));
attach(form.createObjectField({ name: "object" }));
attach(form.createVoidField({ name: "void" }));
form.query("normal").take(field => {
if (isField(field)) field.selfErrors = ["error"];
});
const graph = form.getFormGraph();
form.clearFormGraph();
form.setFormGraph(graph);
const graph2 = form.getFormGraph();
expect(graph).toEqual(graph2);
form.setFormGraph({
object: {
value: { input: 123 }
}
});
expect(form.getFieldState("normal", state => state.selfErrors)).toEqual(["error"]);
expect(form.values.object).toEqual({ input: 123 });
});
// 回收表单、字段模型
test("clearFormGraph", () => {
const form = attach(createForm());
attach(form.createField({ name: "normal" }));
attach(form.createArrayField({ name: "array" }));
attach(form.createObjectField({ name: "object" }));
form.clearFormGraph("normal");
expect(form.fields.normal).toBeUndefined();
expect(form.fields.array).toBeDefined();
});