|
| 1 | +import { it, expect, describe, assertType } from "vitest"; |
| 2 | +import { test, build } from "../../src/options/duotone"; |
| 3 | +import { Options } from "../../src/types"; |
| 4 | + |
| 5 | +describe("duotone", () => { |
| 6 | + describe("test", () => { |
| 7 | + it("should test true if duotone is set", () => { |
| 8 | + expect(test({ duotone: { intensity: 1 } })).toBe(true); |
| 9 | + }); |
| 10 | + |
| 11 | + it("should test true if shorthand is set", () => { |
| 12 | + expect(test({ dt: { intensity: 1 } })).toBe(true); |
| 13 | + }); |
| 14 | + |
| 15 | + it("should test false if duotone is false", () => { |
| 16 | + expect(test({})).toBe(false); |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + describe("build", () => { |
| 21 | + it("should work with various parameters", () => { |
| 22 | + expect(build({ duotone: { intensity: 0 } })).toBe("dt:0"); |
| 23 | + expect(build({ duotone: { intensity: 1 } })).toBe("dt:1"); |
| 24 | + expect(build({ duotone: { intensity: 0.4 } })).toBe("dt:0.4"); |
| 25 | + expect(build({ duotone: { intensity: 0.4, color1: "b3b3b3" } })).toBe( |
| 26 | + "dt:0.4:b3b3b3" |
| 27 | + ); |
| 28 | + expect(build({ duotone: { intensity: 0.4, color2: "b3b3b3" } })).toBe( |
| 29 | + "dt:0.4::b3b3b3" |
| 30 | + ); |
| 31 | + expect( |
| 32 | + build({ |
| 33 | + duotone: { intensity: 0.4, color1: "000000", color2: "b3b3b3" }, |
| 34 | + }) |
| 35 | + ).toBe("dt:0.4:000000:b3b3b3"); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should validate intensity", () => { |
| 39 | + expect(() => build({ duotone: { intensity: -1 } })).toThrow(); |
| 40 | + expect(() => build({ duotone: { intensity: 2 } })).toThrow(); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + describe("Check types", () => { |
| 45 | + it("check TS type declaration", () => { |
| 46 | + assertType<Options>({ |
| 47 | + duotone: { |
| 48 | + intensity: 0.5, |
| 49 | + color1: "000000", |
| 50 | + color2: "000000", |
| 51 | + }, |
| 52 | + dt: { |
| 53 | + intensity: 0.5, |
| 54 | + color1: "000000", |
| 55 | + color2: "000000", |
| 56 | + }, |
| 57 | + }); |
| 58 | + }); |
| 59 | + }); |
| 60 | +}); |
0 commit comments