|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { test, build } from "../../src/options/blurAreas"; |
| 3 | + |
| 4 | +describe("blurAreas", () => { |
| 5 | + describe("test", () => { |
| 6 | + it("should return true if blur_areas option is defined", () => { |
| 7 | + expect( |
| 8 | + test({ |
| 9 | + blur_areas: { |
| 10 | + sigma: 2, |
| 11 | + areas: [{ left: 0, top: 0, width: 0.5, height: 0.5 }], |
| 12 | + }, |
| 13 | + }) |
| 14 | + ).toEqual(true); |
| 15 | + }); |
| 16 | + |
| 17 | + it("should return true if ba option is defined", () => { |
| 18 | + expect( |
| 19 | + test({ |
| 20 | + ba: { |
| 21 | + sigma: 2, |
| 22 | + areas: [{ left: 0, top: 0, width: 0.5, height: 0.5 }], |
| 23 | + }, |
| 24 | + }) |
| 25 | + ).toEqual(true); |
| 26 | + }); |
| 27 | + |
| 28 | + it("should return false if blur_areas option is undefined", () => { |
| 29 | + expect(test({})).toEqual(false); |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + describe("build", () => { |
| 34 | + it("should throw an error if blur_areas option is undefined", () => { |
| 35 | + expect(() => build({})).toThrow("blur_areas option is undefined"); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should throw an error if blur_areas.sigma option is undefined", () => { |
| 39 | + // @ts-expect-error: Let's ignore an error (check for users with vanilla js). |
| 40 | + expect(() => build({ blur_areas: { areas: [] } })).toThrow( |
| 41 | + "blur_areas.sigma is not a number" |
| 42 | + ); |
| 43 | + }); |
| 44 | + |
| 45 | + it("should throw an error if blur_areas.sigma is not a number", () => { |
| 46 | + expect(() => |
| 47 | + build({ |
| 48 | + // @ts-expect-error: Let's ignore an error (check for users with vanilla js). |
| 49 | + blur_areas: { sigma: "2", areas: [] }, |
| 50 | + }) |
| 51 | + ).toThrow("blur_areas.sigma is not a number"); |
| 52 | + }); |
| 53 | + |
| 54 | + it("should throw an error if blur_areas.sigma is less than 0", () => { |
| 55 | + expect(() => build({ blur_areas: { sigma: -1, areas: [] } })).toThrow( |
| 56 | + "blur_areas.sigma value can't be less than 0" |
| 57 | + ); |
| 58 | + }); |
| 59 | + |
| 60 | + it("should throw an error if blur_areas.areas is not an array", () => { |
| 61 | + // @ts-expect-error: Let's ignore an error (check for users with vanilla js). |
| 62 | + expect(() => build({ blur_areas: { sigma: 2 } })).toThrow( |
| 63 | + "blur_areas.areas is not an array" |
| 64 | + ); |
| 65 | + }); |
| 66 | + |
| 67 | + it("should throw an error if blur_areas.areas is empty", () => { |
| 68 | + expect(() => build({ blur_areas: { sigma: 2, areas: [] } })).toThrow( |
| 69 | + "blur_areas.areas is empty" |
| 70 | + ); |
| 71 | + }); |
| 72 | + |
| 73 | + it("should throw an error if area.left is not a number", () => { |
| 74 | + expect(() => |
| 75 | + build({ |
| 76 | + blur_areas: { |
| 77 | + sigma: 2, |
| 78 | + // @ts-expect-error: Let's ignore an error (check for users with vanilla js). |
| 79 | + areas: [{ top: 0, width: 0.1, height: 0.1 }], |
| 80 | + }, |
| 81 | + }) |
| 82 | + ).toThrow("blur_areas.areas[0].left is not a number"); |
| 83 | + }); |
| 84 | + |
| 85 | + it("should throw an error if area.left is out of range", () => { |
| 86 | + expect(() => |
| 87 | + build({ |
| 88 | + blur_areas: { |
| 89 | + sigma: 2, |
| 90 | + areas: [{ left: 1.5, top: 0, width: 0.1, height: 0.1 }], |
| 91 | + }, |
| 92 | + }) |
| 93 | + ).toThrow("blur_areas.areas[0].left value can't be more than 1"); |
| 94 | + }); |
| 95 | + |
| 96 | + it("should build a url with a single area", () => { |
| 97 | + expect( |
| 98 | + build({ |
| 99 | + blur_areas: { |
| 100 | + sigma: 2, |
| 101 | + areas: [{ left: 0.1, top: 0.2, width: 0.3, height: 0.4 }], |
| 102 | + }, |
| 103 | + }) |
| 104 | + ).toEqual("ba:2:0.1:0.2:0.3:0.4"); |
| 105 | + }); |
| 106 | + |
| 107 | + it("should build a url with multiple areas using `ba` alias", () => { |
| 108 | + expect( |
| 109 | + build({ |
| 110 | + ba: { |
| 111 | + sigma: 5, |
| 112 | + areas: [ |
| 113 | + { left: 0, top: 0, width: 0.5, height: 0.5 }, |
| 114 | + { left: 0.5, top: 0.5, width: 0.25, height: 0.25 }, |
| 115 | + ], |
| 116 | + }, |
| 117 | + }) |
| 118 | + ).toEqual("ba:5:0:0:0.5:0.5:0.5:0.5:0.25:0.25"); |
| 119 | + }); |
| 120 | + }); |
| 121 | +}); |
0 commit comments