forked from rjsf-team/react-jsonschema-form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectFieldTemplate_test.js
77 lines (65 loc) · 1.88 KB
/
ObjectFieldTemplate_test.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React, { PureComponent } from "react";
import { expect } from "chai";
import { createFormComponent, createSandbox } from "./test_utils";
describe("ObjectFieldTemplate", () => {
let sandbox;
const formData = { foo: "bar", bar: "foo" };
beforeEach(() => {
sandbox = createSandbox();
});
afterEach(() => {
sandbox.restore();
});
class ObjectFieldTemplate extends PureComponent {
render() {
const {
TitleField,
DescriptionField,
properties,
title,
description,
} = this.props;
return (
<div className="root">
<TitleField title={title} />
<DescriptionField description={description} />
<div>
{properties.map(({ content }, index) => (
<div key={index} className="property">
{content}
</div>
))}
</div>
</div>
);
}
}
const TitleField = () => <div className="title-field" />;
const DescriptionField = ({ description }) =>
description ? <div className="description-field" /> : null;
const { node } = createFormComponent({
schema: {
type: "object",
properties: { foo: { type: "string" }, bar: { type: "string" } },
},
uiSchema: { "ui:description": "foobar" },
formData,
ObjectFieldTemplate,
fields: {
TitleField,
DescriptionField,
},
});
it("should render one root element", () => {
expect(node.querySelectorAll(".root")).to.have.length.of(1);
});
it("should render one title", () => {
expect(node.querySelectorAll(".title-field")).to.have.length.of(1);
});
it("should render one description", () => {
expect(node.querySelectorAll(".description-field")).to.have.length.of(1);
});
it("should render two property containers", () => {
expect(node.querySelectorAll(".property")).to.have.length.of(2);
});
});