|
| 1 | +/// <reference types="jest" /> |
| 2 | + |
| 3 | +import { getClosestValue } from "../src/media.utils" |
| 4 | + |
| 5 | +describe("`getClosestValue` function", () => { |
| 6 | + test("should get the closest responsive value", () => { |
| 7 | + expect(getClosestValue({ base: "40px", md: "500px" }, "xl")).toBe("500px") |
| 8 | + expect(getClosestValue({ base: "40px", md: "500px" }, "sm")).toBe("40px") |
| 9 | + expect(getClosestValue({ base: "40px" }, "lg")).toBe("40px") |
| 10 | + expect(getClosestValue({ sm: "40px", md: "500px" }, "sm")).toBe("40px") |
| 11 | + expect(getClosestValue({ sm: "40px", md: "500px" }, "base")).toBe(undefined) |
| 12 | + expect(getClosestValue({}, "")).toBe(undefined) |
| 13 | + }) |
| 14 | + |
| 15 | + test("should get the closest responsive value even if values contains nullable value", () => { |
| 16 | + expect(getClosestValue({ base: "40px", md: undefined }, "xl")).toBe( |
| 17 | + undefined |
| 18 | + ) |
| 19 | + expect(getClosestValue({ base: "40px", md: null }, "xl")).toBe(null) |
| 20 | + expect(getClosestValue({ sm: "40px", md: undefined }, "xl")).toBe(undefined) |
| 21 | + expect(getClosestValue({ sm: "40px", md: null }, "xl")).toBe(null) |
| 22 | + }) |
| 23 | + |
| 24 | + test("should get the closest responsive value with custom breakpoints", () => { |
| 25 | + const customBreakPoints = ["base", "sm", "md", "custom", "xl"] |
| 26 | + expect( |
| 27 | + getClosestValue( |
| 28 | + { base: "40px", md: "500px", custom: "600px" }, |
| 29 | + "xl", |
| 30 | + customBreakPoints |
| 31 | + ) |
| 32 | + ).toBe("600px") |
| 33 | + expect( |
| 34 | + getClosestValue({ base: "40px", md: "500px" }, "sm", customBreakPoints) |
| 35 | + ).toBe("40px") |
| 36 | + expect(getClosestValue({ base: "40px" }, "custom", customBreakPoints)).toBe( |
| 37 | + "40px" |
| 38 | + ) |
| 39 | + expect( |
| 40 | + getClosestValue({ sm: "40px", md: "500px" }, "sm", customBreakPoints) |
| 41 | + ).toBe("40px") |
| 42 | + expect( |
| 43 | + getClosestValue({ sm: "40px", md: "500px" }, "base", customBreakPoints) |
| 44 | + ).toBe(undefined) |
| 45 | + expect(getClosestValue({}, "")).toBe(undefined) |
| 46 | + }) |
| 47 | +}) |
0 commit comments