|
| 1 | +import { |
| 2 | + PEEK_CLOSE_MARGIN, |
| 3 | + PEEK_REVEAL_THRESHOLD, |
| 4 | + shouldCloseOnExit, |
| 5 | + shouldRevealOnEdge, |
| 6 | +} from "@posthog/ui/primitives/hooks/useSidebarEdgeHoverPeek"; |
| 7 | +import { describe, expect, it } from "vitest"; |
| 8 | + |
| 9 | +describe("shouldRevealOnEdge", () => { |
| 10 | + const threshold = PEEK_REVEAL_THRESHOLD; |
| 11 | + |
| 12 | + it.each([ |
| 13 | + ["crosses into the zone from outside", 10, false, true], |
| 14 | + ["already inside the zone (no re-trigger)", 10, true, false], |
| 15 | + ["outside the zone", 100, false, false], |
| 16 | + ["flick from outside straight to the edge in one sample", 0, false, true], |
| 17 | + ["exactly on the threshold, crossing in", threshold, false, true], |
| 18 | + ["just past the threshold", threshold + 1, false, false], |
| 19 | + ])("%s", (_name, pointer, wasInside, expected) => { |
| 20 | + expect(shouldRevealOnEdge({ pointer, wasInside, threshold })).toBe( |
| 21 | + expected, |
| 22 | + ); |
| 23 | + }); |
| 24 | +}); |
| 25 | + |
| 26 | +describe("shouldCloseOnExit", () => { |
| 27 | + const margin = PEEK_CLOSE_MARGIN; |
| 28 | + |
| 29 | + it.each([ |
| 30 | + ["inside the panel", 100, 240, false], |
| 31 | + ["between the panel edge and the margin", 280, 240, false], |
| 32 | + ["exactly on the far edge (right edge)", 240, 240, false], |
| 33 | + ["exactly on the close boundary", 240 + margin, 240, false], |
| 34 | + ["past the close boundary into content", 240 + margin + 1, 240, true], |
| 35 | + ["stays open at the left edge / off-window", 0, 240, false], |
| 36 | + ["wide panel still open before its boundary", 400 + margin, 400, false], |
| 37 | + ["wide panel closes past its boundary", 400 + margin + 1, 400, true], |
| 38 | + ])("%s", (_name, pointer, width, expected) => { |
| 39 | + expect(shouldCloseOnExit({ pointer, width, margin })).toBe(expected); |
| 40 | + }); |
| 41 | +}); |
0 commit comments