|
| 1 | +import { describe, it, expect } from "@jest/globals"; |
| 2 | +import { isSameObject, isSameObjectArray } from "./utils"; |
| 3 | + |
| 4 | +describe("isSameObject", () => { |
| 5 | + it("should return true if the objects are same", () => { |
| 6 | + expect( |
| 7 | + isSameObject( |
| 8 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 9 | + { transform: "translateX(0px)", fill: "lightskyblue" } |
| 10 | + ) |
| 11 | + ).toBe(true); |
| 12 | + }); |
| 13 | + |
| 14 | + it("should return true if the fields order is changed", () => { |
| 15 | + expect( |
| 16 | + isSameObject( |
| 17 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 18 | + { fill: "lightskyblue", transform: "translateX(0px)" } |
| 19 | + ) |
| 20 | + ).toBe(true); |
| 21 | + }); |
| 22 | + |
| 23 | + it("should return true if the objects are empty", () => { |
| 24 | + expect(isSameObject({}, {})).toBe(true); |
| 25 | + }); |
| 26 | + |
| 27 | + it("should return false if a field is changed", () => { |
| 28 | + expect( |
| 29 | + isSameObject( |
| 30 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 31 | + { transform: "translateX(100px)", fill: "lightskyblue" } |
| 32 | + ) |
| 33 | + ).toBe(false); |
| 34 | + }); |
| 35 | + |
| 36 | + it("should return false if a field name is changed", () => { |
| 37 | + expect( |
| 38 | + isSameObject( |
| 39 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 40 | + { transform: "translateX(0px)", color: "lightskyblue" } |
| 41 | + ) |
| 42 | + ).toBe(false); |
| 43 | + }); |
| 44 | + |
| 45 | + it("should return false if a field is added", () => { |
| 46 | + expect( |
| 47 | + isSameObject( |
| 48 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 49 | + { transform: "translateX(0px)", fill: "lightskyblue", color: "red" } |
| 50 | + ) |
| 51 | + ).toBe(false); |
| 52 | + }); |
| 53 | + |
| 54 | + it("should return false if a field is deleted", () => { |
| 55 | + expect( |
| 56 | + isSameObject( |
| 57 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 58 | + { transform: "translateX(0px)" } |
| 59 | + ) |
| 60 | + ).toBe(false); |
| 61 | + }); |
| 62 | +}); |
| 63 | + |
| 64 | +describe("isSameObjectArray", () => { |
| 65 | + it("should return true if the arrays are same", () => { |
| 66 | + expect( |
| 67 | + isSameObjectArray( |
| 68 | + [ |
| 69 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 70 | + { transform: "translateX(100px)", fill: "red" }, |
| 71 | + ], |
| 72 | + [ |
| 73 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 74 | + { transform: "translateX(100px)", fill: "red" }, |
| 75 | + ] |
| 76 | + ) |
| 77 | + ).toBe(true); |
| 78 | + }); |
| 79 | + |
| 80 | + it("should return true if the arrays are empty", () => { |
| 81 | + expect(isSameObjectArray([], [])).toBe(true); |
| 82 | + }); |
| 83 | + |
| 84 | + it("should return false if a field is updated", () => { |
| 85 | + expect( |
| 86 | + isSameObjectArray( |
| 87 | + [ |
| 88 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 89 | + { transform: "translateX(100px)", fill: "red" }, |
| 90 | + ], |
| 91 | + [ |
| 92 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 93 | + { transform: "translateX(50px)", fill: "red" }, |
| 94 | + ] |
| 95 | + ) |
| 96 | + ).toBe(false); |
| 97 | + }); |
| 98 | + |
| 99 | + it("should return false if a field is deleted", () => { |
| 100 | + expect( |
| 101 | + isSameObjectArray( |
| 102 | + [ |
| 103 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 104 | + { transform: "translateX(100px)", fill: "red" }, |
| 105 | + ], |
| 106 | + [ |
| 107 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 108 | + { transform: "translateX(100px)" }, |
| 109 | + ] |
| 110 | + ) |
| 111 | + ).toBe(false); |
| 112 | + }); |
| 113 | + |
| 114 | + it("should return false if a field is added", () => { |
| 115 | + expect( |
| 116 | + isSameObjectArray( |
| 117 | + [ |
| 118 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 119 | + { transform: "translateX(100px)", fill: "red" }, |
| 120 | + ], |
| 121 | + [ |
| 122 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 123 | + { transform: "translateX(100px)", fill: "red", color: "blue" }, |
| 124 | + ] |
| 125 | + ) |
| 126 | + ).toBe(false); |
| 127 | + }); |
| 128 | + |
| 129 | + it("should return false if an object is added", () => { |
| 130 | + expect( |
| 131 | + isSameObjectArray( |
| 132 | + [ |
| 133 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 134 | + { transform: "translateX(100px)", fill: "red" }, |
| 135 | + ], |
| 136 | + [ |
| 137 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 138 | + { transform: "translateX(100px)", fill: "red" }, |
| 139 | + { transform: "translateX(100px)", fill: "red" }, |
| 140 | + ] |
| 141 | + ) |
| 142 | + ).toBe(false); |
| 143 | + }); |
| 144 | + |
| 145 | + it("should return false if an object is added", () => { |
| 146 | + expect( |
| 147 | + isSameObjectArray( |
| 148 | + [ |
| 149 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 150 | + { transform: "translateX(100px)", fill: "red" }, |
| 151 | + ], |
| 152 | + [{ transform: "translateX(0px)", fill: "lightskyblue" }] |
| 153 | + ) |
| 154 | + ).toBe(false); |
| 155 | + }); |
| 156 | + |
| 157 | + it("should return false if the object order is changed", () => { |
| 158 | + expect( |
| 159 | + isSameObjectArray( |
| 160 | + [ |
| 161 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 162 | + { transform: "translateX(100px)", fill: "red" }, |
| 163 | + ], |
| 164 | + [ |
| 165 | + { transform: "translateX(100px)", fill: "red" }, |
| 166 | + { transform: "translateX(0px)", fill: "lightskyblue" }, |
| 167 | + ] |
| 168 | + ) |
| 169 | + ).toBe(false); |
| 170 | + }); |
| 171 | +}); |
0 commit comments