|
| 1 | +import { it, expect, describe, assertType } from "vitest"; |
| 2 | +import { test, build } from "../../src/options/colorize"; |
| 3 | +import { Options } from "../../src/types"; |
| 4 | + |
| 5 | +describe("colorize", () => { |
| 6 | + describe("test", () => { |
| 7 | + it("should test true if colorize is set", () => { |
| 8 | + expect(test({ colorize: { opacity: 0.5 } })).toBe(true); |
| 9 | + }); |
| 10 | + |
| 11 | + it("should test true if col is set", () => { |
| 12 | + expect(test({ col: { opacity: 0.5 } })).toBe(true); |
| 13 | + }); |
| 14 | + |
| 15 | + it("should test false if colorize is not set", () => { |
| 16 | + expect(test({})).toBe(false); |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + describe("build", () => { |
| 21 | + it("should work with opacity only", () => { |
| 22 | + expect(build({ colorize: { opacity: 0 } })).toBe("col:0"); |
| 23 | + expect(build({ colorize: { opacity: 1 } })).toBe("col:1"); |
| 24 | + expect(build({ colorize: { opacity: 0.4 } })).toBe("col:0.4"); |
| 25 | + }); |
| 26 | + |
| 27 | + it("should work with opacity and color", () => { |
| 28 | + expect(build({ colorize: { opacity: 0.5, color: "ff0000" } })).toBe( |
| 29 | + "col:0.5:ff0000" |
| 30 | + ); |
| 31 | + }); |
| 32 | + |
| 33 | + it("should work with opacity, color, and keepAlpha", () => { |
| 34 | + expect( |
| 35 | + build({ colorize: { opacity: 0.5, color: "ff0000", keepAlpha: true } }) |
| 36 | + ).toBe("col:0.5:ff0000:1"); |
| 37 | + expect( |
| 38 | + build({ colorize: { opacity: 0.5, color: "ff0000", keepAlpha: false } }) |
| 39 | + ).toBe("col:0.5:ff0000:0"); |
| 40 | + }); |
| 41 | + |
| 42 | + it("should work with opacity and keepAlpha without color", () => { |
| 43 | + expect(build({ colorize: { opacity: 0.5, keepAlpha: true } })).toBe( |
| 44 | + "col:0.5::1" |
| 45 | + ); |
| 46 | + expect(build({ colorize: { opacity: 0.5, keepAlpha: false } })).toBe( |
| 47 | + "col:0.5::0" |
| 48 | + ); |
| 49 | + }); |
| 50 | + |
| 51 | + it("should validate opacity", () => { |
| 52 | + expect(() => build({ colorize: { opacity: -1 } })).toThrow(); |
| 53 | + expect(() => build({ colorize: { opacity: 2 } })).toThrow(); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + describe("Check types", () => { |
| 58 | + it("check TS type declaration", () => { |
| 59 | + assertType<Options>({ |
| 60 | + colorize: { |
| 61 | + opacity: 0.5, |
| 62 | + color: "ff0000", |
| 63 | + keepAlpha: true, |
| 64 | + }, |
| 65 | + col: { |
| 66 | + opacity: 0.5, |
| 67 | + color: "ff0000", |
| 68 | + keepAlpha: false, |
| 69 | + }, |
| 70 | + }); |
| 71 | + }); |
| 72 | + }); |
| 73 | +}); |
0 commit comments