|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { test, build } from "../../src/options/flip"; |
| 3 | + |
| 4 | +describe("flip", () => { |
| 5 | + describe("test", () => { |
| 6 | + it("should return true if flip option is defined", () => { |
| 7 | + expect(test({ flip: { horizontal: true } })).toEqual(true); |
| 8 | + }); |
| 9 | + |
| 10 | + it("should return true if fl option is defined", () => { |
| 11 | + expect(test({ fl: { vertical: true } })).toEqual(true); |
| 12 | + }); |
| 13 | + |
| 14 | + it("should return false if flip option is undefined", () => { |
| 15 | + expect(test({})).toEqual(false); |
| 16 | + }); |
| 17 | + }); |
| 18 | + |
| 19 | + describe("build", () => { |
| 20 | + it("should throw an error if flip is undefined", () => { |
| 21 | + expect(() => build({})).toThrow("flip option is undefined"); |
| 22 | + }); |
| 23 | + |
| 24 | + it("should return fl:f:f if both horizontal and vertical are false", () => { |
| 25 | + expect(build({ flip: { horizontal: false, vertical: false } })).toEqual( |
| 26 | + "fl:f:f" |
| 27 | + ); |
| 28 | + }); |
| 29 | + |
| 30 | + it("should return fl:f:f if flip object is empty (defaults)", () => { |
| 31 | + expect(build({ flip: {} })).toEqual("fl:f:f"); |
| 32 | + }); |
| 33 | + |
| 34 | + it("should return fl:t:f if horizontal is true", () => { |
| 35 | + expect(build({ flip: { horizontal: true } })).toEqual("fl:t:f"); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should return fl:f:t if vertical is true", () => { |
| 39 | + expect(build({ flip: { vertical: true } })).toEqual("fl:f:t"); |
| 40 | + }); |
| 41 | + |
| 42 | + it("should return fl:t:t if both are true", () => { |
| 43 | + expect(build({ flip: { horizontal: true, vertical: true } })).toEqual( |
| 44 | + "fl:t:t" |
| 45 | + ); |
| 46 | + }); |
| 47 | + |
| 48 | + it("should support horizontal as 1", () => { |
| 49 | + expect(build({ flip: { horizontal: 1 } })).toEqual("fl:t:f"); |
| 50 | + }); |
| 51 | + |
| 52 | + it("should support horizontal as 't'", () => { |
| 53 | + expect(build({ flip: { horizontal: "t" } })).toEqual("fl:t:f"); |
| 54 | + }); |
| 55 | + |
| 56 | + it("should support vertical as 1", () => { |
| 57 | + expect(build({ flip: { vertical: 1 } })).toEqual("fl:f:t"); |
| 58 | + }); |
| 59 | + |
| 60 | + it("should support vertical as 't'", () => { |
| 61 | + expect(build({ flip: { vertical: "t" } })).toEqual("fl:f:t"); |
| 62 | + }); |
| 63 | + |
| 64 | + it("should support both with various truthy values", () => { |
| 65 | + expect(build({ flip: { horizontal: 1, vertical: "t" } })).toEqual( |
| 66 | + "fl:t:t" |
| 67 | + ); |
| 68 | + }); |
| 69 | + |
| 70 | + it("should support 0 as false for horizontal", () => { |
| 71 | + expect(build({ flip: { horizontal: 0, vertical: true } })).toEqual( |
| 72 | + "fl:f:t" |
| 73 | + ); |
| 74 | + }); |
| 75 | + |
| 76 | + it("should work with fl shorthand", () => { |
| 77 | + expect(build({ fl: { horizontal: true, vertical: false } })).toEqual( |
| 78 | + "fl:t:f" |
| 79 | + ); |
| 80 | + }); |
| 81 | + |
| 82 | + it("should work with both horizontal and vertical using different value types", () => { |
| 83 | + expect(build({ flip: { horizontal: true, vertical: 1 } })).toEqual( |
| 84 | + "fl:t:t" |
| 85 | + ); |
| 86 | + }); |
| 87 | + }); |
| 88 | +}); |
0 commit comments