UNPKG

stitch-ui

Version:

34 lines (31 loc) 904 B
/* global it, describe, expect */ import Rule from "../rule"; describe("field rules", () => { it("must be able to marshal/unmarshal a rule", () => { const raw = { _id: "sdgsgsdG", actions: ["put", "post"], when: { x: "y" } }; let r = Rule.fromRawRule(raw); expect(r.toRawRule()).toEqual(raw); r = r.updateWhenInput("blah"); expect(r.dirty).toBe(true); r = r.parse(); expect(r.hasError()).toBe(true); r = r.updateWhenInput("{x:5}"); r = r.parse(); expect(r.hasError()).toBe(false); expect(r.dirty).toBe(true); r = r.set("dirty", false); r = r.setAction("blah", true); expect(r.dirty).toBe(true); expect(r.actions.toObject()).toEqual({ put: "put", post: "post", blah: "blah" }); r = r.setAction("put", false); expect(r.actions.toObject()).toEqual({ post: "post", blah: "blah" }); }); });