|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { test, build } from "../../src/options/avifOptions"; |
| 3 | + |
| 4 | +describe("avifOptions", () => { |
| 5 | + describe("test", () => { |
| 6 | + it("should return true if avif_options option is defined", () => { |
| 7 | + expect(test({ avif_options: "auto" })).toEqual(true); |
| 8 | + }); |
| 9 | + |
| 10 | + it("should return true if avifo option is defined", () => { |
| 11 | + expect(test({ avifo: "on" })).toEqual(true); |
| 12 | + }); |
| 13 | + |
| 14 | + it("should return false if avif_options option is undefined", () => { |
| 15 | + expect(test({})).toEqual(false); |
| 16 | + }); |
| 17 | + }); |
| 18 | + |
| 19 | + describe("build", () => { |
| 20 | + it("should throw an error if avif_options is undefined", () => { |
| 21 | + expect(() => build({})).toThrow("avif_options option is undefined"); |
| 22 | + }); |
| 23 | + |
| 24 | + it("should throw an error if avif_options is invalid", () => { |
| 25 | + // @ts-expect-error: Let's ignore an error (check for users with vanilla js). |
| 26 | + expect(() => build({ avif_options: "invalid" })).toThrow( |
| 27 | + "avif_options option is invalid. Valid values are: auto, on, off" |
| 28 | + ); |
| 29 | + }); |
| 30 | + |
| 31 | + it("should throw an error if avif_options is a number", () => { |
| 32 | + // @ts-expect-error: Let's ignore an error (check for users with vanilla js). |
| 33 | + expect(() => build({ avif_options: 1 })).toThrow( |
| 34 | + "avif_options option is invalid. Valid values are: auto, on, off" |
| 35 | + ); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should return avifo:auto if avif_options is auto", () => { |
| 39 | + expect(build({ avif_options: "auto" })).toEqual("avifo:auto"); |
| 40 | + }); |
| 41 | + |
| 42 | + it("should return avifo:on if avifo option is on", () => { |
| 43 | + expect(build({ avifo: "on" })).toEqual("avifo:on"); |
| 44 | + }); |
| 45 | + |
| 46 | + it("should return avifo:off if avif_options is off", () => { |
| 47 | + expect(build({ avif_options: "off" })).toEqual("avifo:off"); |
| 48 | + }); |
| 49 | + |
| 50 | + it("should support object notation with subsample property", () => { |
| 51 | + expect(build({ avif_options: { subsample: "auto" } })).toEqual( |
| 52 | + "avifo:auto" |
| 53 | + ); |
| 54 | + |
| 55 | + expect(build({ avif_options: { subsample: "on" } })).toEqual("avifo:on"); |
| 56 | + |
| 57 | + expect(build({ avif_options: { subsample: "off" } })).toEqual( |
| 58 | + "avifo:off" |
| 59 | + ); |
| 60 | + }); |
| 61 | + |
| 62 | + it("should throw an error if subsample is invalid in object notation", () => { |
| 63 | + expect(() => |
| 64 | + // @ts-expect-error: Let's ignore an error (check for users with vanilla js). |
| 65 | + build({ avif_options: { subsample: "invalid" } }) |
| 66 | + ).toThrow( |
| 67 | + "avif_options option is invalid. Valid values are: auto, on, off" |
| 68 | + ); |
| 69 | + }); |
| 70 | + }); |
| 71 | +}); |
0 commit comments