|
1 | 1 | import React, { PureComponent } from "react"; |
2 | | - |
3 | 2 | import { expect } from "chai"; |
4 | 3 | import { createFormComponent, createSandbox } from "./test_utils"; |
5 | 4 |
|
@@ -39,31 +38,6 @@ describe("ArrayFieldTemplate", () => { |
39 | 38 | ); |
40 | 39 | } |
41 | 40 |
|
42 | | - describe("Stateful ArrayFieldTemplate", () => { |
43 | | - class ArrayFieldTemplate extends PureComponent { |
44 | | - render() { |
45 | | - return ( |
46 | | - <div className="field-content"> |
47 | | - {this.props.items.map((item, i) => ( |
48 | | - <div key={i}>item.children</div> |
49 | | - ))} |
50 | | - </div> |
51 | | - ); |
52 | | - } |
53 | | - } |
54 | | - |
55 | | - it("should render a stateful custom component", () => { |
56 | | - const { node } = createFormComponent({ |
57 | | - schema: { type: "array", items: { type: "string" } }, |
58 | | - formData, |
59 | | - ArrayFieldTemplate, |
60 | | - }); |
61 | | - expect( |
62 | | - node.querySelectorAll(".field-array .field-content div") |
63 | | - ).to.have.length.of(3); |
64 | | - }); |
65 | | - }); |
66 | | - |
67 | 41 | describe("not fixed items", () => { |
68 | 42 | const schema = { |
69 | 43 | type: "array", |
@@ -176,4 +150,45 @@ describe("ArrayFieldTemplate", () => { |
176 | 150 | }); |
177 | 151 | }); |
178 | 152 | }); |
| 153 | + |
| 154 | + describe("Stateful ArrayFieldTemplate", () => { |
| 155 | + class ArrayFieldTemplate extends PureComponent { |
| 156 | + render() { |
| 157 | + return ( |
| 158 | + <div className="field-content"> |
| 159 | + {this.props.items.map((item, i) => ( |
| 160 | + <div key={i}>item.children</div> |
| 161 | + ))} |
| 162 | + </div> |
| 163 | + ); |
| 164 | + } |
| 165 | + } |
| 166 | + |
| 167 | + it("should render a stateful custom component", () => { |
| 168 | + const { node } = createFormComponent({ |
| 169 | + schema: { type: "array", items: { type: "string" } }, |
| 170 | + formData, |
| 171 | + ArrayFieldTemplate, |
| 172 | + }); |
| 173 | + expect( |
| 174 | + node.querySelectorAll(".field-array .field-content div") |
| 175 | + ).to.have.length.of(3); |
| 176 | + }); |
| 177 | + }); |
| 178 | + |
| 179 | + describe("pass right props to ArrayFieldTemplate", () => { |
| 180 | + it("should pass registry prop", () => { |
| 181 | + const ArrayFieldTemplate = ({ registry }) => { |
| 182 | + if (!registry) { |
| 183 | + throw "Error"; |
| 184 | + } |
| 185 | + return null; |
| 186 | + }; |
| 187 | + createFormComponent({ |
| 188 | + schema: { type: "array", items: { type: "string" } }, |
| 189 | + formData, |
| 190 | + ArrayFieldTemplate, |
| 191 | + }); |
| 192 | + }); |
| 193 | + }); |
179 | 194 | }); |
0 commit comments