|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { test, build } from "../../src/options/cropAspectRatio"; |
| 3 | + |
| 4 | +describe("cropAspectRatio", () => { |
| 5 | + describe("test", () => { |
| 6 | + it("should return true if crop_aspect_ratio option is defined", () => { |
| 7 | + expect(test({ crop_aspect_ratio: { aspect_ratio: 1.5 } })).toEqual(true); |
| 8 | + }); |
| 9 | + |
| 10 | + it("should return true if crop_ar option is defined", () => { |
| 11 | + expect(test({ crop_ar: { aspect_ratio: 1.1 } })).toEqual(true); |
| 12 | + }); |
| 13 | + |
| 14 | + it("should return true if car option is defined", () => { |
| 15 | + expect(test({ car: { aspect_ratio: 1.1 } })).toEqual(true); |
| 16 | + }); |
| 17 | + |
| 18 | + it("should return false if crop_aspect_ratio option is undefined", () => { |
| 19 | + expect(test({})).toEqual(false); |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + describe("build", () => { |
| 24 | + it("should throw an error if crop_aspect_ratio option is undefined", () => { |
| 25 | + expect(() => build({})).toThrow("crop_aspect_ratio option is undefined"); |
| 26 | + }); |
| 27 | + |
| 28 | + it("should throw an error if aspect_ratio option is undefined", () => { |
| 29 | + // @ts-expect-error: Let's ignore an error (check for users with vanilla js). |
| 30 | + expect(() => build({ crop_aspect_ratio: {} })).toThrow( |
| 31 | + "crop_aspect_ratio.aspect_ratio is undefined" |
| 32 | + ); |
| 33 | + }); |
| 34 | + |
| 35 | + it("should throw an error if aspect_ratio is not a number", () => { |
| 36 | + expect(() => |
| 37 | + // @ts-expect-error: Let's ignore an error (check for users with vanilla js). |
| 38 | + build({ crop_aspect_ratio: { aspect_ratio: "1.5" } }) |
| 39 | + ).toThrow("crop_aspect_ratio.aspect_ratio is not a number"); |
| 40 | + }); |
| 41 | + |
| 42 | + it("should throw an error if aspect_ratio is less than 0", () => { |
| 43 | + expect(() => |
| 44 | + build({ crop_aspect_ratio: { aspect_ratio: -1 } }) |
| 45 | + ).toThrowError( |
| 46 | + "crop_aspect_ratio.aspect_ratio value can't be less then 0" |
| 47 | + ); |
| 48 | + }); |
| 49 | + |
| 50 | + it("should return crop_ar:1.5 if crop_aspect_ratio aspect_ratio is 1.5", () => { |
| 51 | + expect(build({ crop_aspect_ratio: { aspect_ratio: 1.5 } })).toEqual( |
| 52 | + "crop_ar:1.5" |
| 53 | + ); |
| 54 | + }); |
| 55 | + |
| 56 | + it("should return crop_ar:1.1 if crop_ar aspect_ratio is 1.1", () => { |
| 57 | + expect(build({ crop_ar: { aspect_ratio: 1.1 } })).toEqual("crop_ar:1.1"); |
| 58 | + }); |
| 59 | + |
| 60 | + it("should return crop_ar:0 if aspect_ratio is 0", () => { |
| 61 | + expect(build({ crop_aspect_ratio: { aspect_ratio: 0 } })).toEqual( |
| 62 | + "crop_ar:0" |
| 63 | + ); |
| 64 | + }); |
| 65 | + |
| 66 | + it("should return crop_ar:1.5:t if crop_aspect_ratio aspect_ratio is 1.5 and enlarge is true", () => { |
| 67 | + expect( |
| 68 | + build({ crop_aspect_ratio: { aspect_ratio: 1.5, enlarge: true } }) |
| 69 | + ).toEqual("crop_ar:1.5:t"); |
| 70 | + }); |
| 71 | + |
| 72 | + it("should return crop_ar:1.1:t if crop_ar aspect_ratio is 1.1 and enlarge is 1", () => { |
| 73 | + expect(build({ crop_ar: { aspect_ratio: 1.1, enlarge: 1 } })).toEqual( |
| 74 | + "crop_ar:1.1:t" |
| 75 | + ); |
| 76 | + }); |
| 77 | + |
| 78 | + it("should return crop_ar:2:t if aspect_ratio is 2.0 and enlarge is 't'", () => { |
| 79 | + expect( |
| 80 | + build({ crop_aspect_ratio: { aspect_ratio: 2.0, enlarge: "t" } }) |
| 81 | + ).toEqual("crop_ar:2:t"); |
| 82 | + }); |
| 83 | + |
| 84 | + it("should return crop_ar:1.5:f if aspect_ratio is 1.5 and enlarge is false", () => { |
| 85 | + expect( |
| 86 | + build({ crop_aspect_ratio: { aspect_ratio: 1.5, enlarge: false } }) |
| 87 | + ).toEqual("crop_ar:1.5:f"); |
| 88 | + }); |
| 89 | + |
| 90 | + it("should return crop_ar:1.1:f if aspect_ratio is 1.1 and enlarge is 'f'", () => { |
| 91 | + expect(build({ crop_ar: { aspect_ratio: 1.1, enlarge: "f" } })).toEqual( |
| 92 | + "crop_ar:1.1:f" |
| 93 | + ); |
| 94 | + }); |
| 95 | + }); |
| 96 | +}); |
0 commit comments