|
6 | 6 | deepEquals,
|
7 | 7 | getDefaultFormState,
|
8 | 8 | isFilesArray,
|
| 9 | + isConstant, |
| 10 | + toConstant, |
9 | 11 | isMultiSelect,
|
10 | 12 | mergeObjects,
|
11 | 13 | pad,
|
@@ -269,6 +271,49 @@ describe("utils", () => {
|
269 | 271 | });
|
270 | 272 | });
|
271 | 273 |
|
| 274 | + describe("isConstant", () => { |
| 275 | + it("should return false when neither enum nor const is defined", () => { |
| 276 | + const schema = {}; |
| 277 | + expect(isConstant(schema)).to.be.false; |
| 278 | + }); |
| 279 | + |
| 280 | + it("should return true when schema enum is an array of one item", () => { |
| 281 | + const schema = { enum: ["foo"] }; |
| 282 | + expect(isConstant(schema)).to.be.true; |
| 283 | + }); |
| 284 | + |
| 285 | + it("should return false when schema enum contains several items", () => { |
| 286 | + const schema = { enum: ["foo", "bar", "baz"] }; |
| 287 | + expect(isConstant(schema)).to.be.false; |
| 288 | + }); |
| 289 | + |
| 290 | + it("should return true when schema const is defined", () => { |
| 291 | + const schema = { const: "foo" }; |
| 292 | + expect(isConstant(schema)).to.be.true; |
| 293 | + }); |
| 294 | + }); |
| 295 | + |
| 296 | + describe("toConstant()", () => { |
| 297 | + describe("schema contains an enum array", () => { |
| 298 | + it("should return its first value when it contains a unique element", () => { |
| 299 | + const schema = { enum: ["foo"] }; |
| 300 | + expect(toConstant(schema)).eql("foo"); |
| 301 | + }); |
| 302 | + |
| 303 | + it("should return schema const value when it exists", () => { |
| 304 | + const schema = { const: "bar" }; |
| 305 | + expect(toConstant(schema)).eql("bar"); |
| 306 | + }); |
| 307 | + |
| 308 | + it("should throw when it contains more than one element", () => { |
| 309 | + const schema = { enum: ["foo", "bar"] }; |
| 310 | + expect(() => { |
| 311 | + toConstant(schema); |
| 312 | + }).to.Throw(Error, "cannot be inferred"); |
| 313 | + }); |
| 314 | + }); |
| 315 | + }); |
| 316 | + |
272 | 317 | describe("isMultiSelect()", () => {
|
273 | 318 | describe("uniqueItems is true", () => {
|
274 | 319 | describe("schema items enum is an array", () => {
|
|
0 commit comments