Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { deriveMenuHorizontalPlacement } from "./menu-placement";
4
5const base = { anchorWidth: 48, overlayWidth: 852, desiredWidth: 224, margin: 12 };
6
7describe("deriveMenuHorizontalPlacement", () => {
8 it("opens toward the roomier side of the whole screen without a hinge", () => {
9 expect(deriveMenuHorizontalPlacement({ ...base, anchorX: 300, hinge: null })).toEqual({
10 left: 300,
11 width: 224,
12 });
13 });
14
15 it("keeps a menu on its anchor's side of a creased hinge", () => {
16 // The filter button sits near the crease, so the menu right-aligns to it instead of crossing.
17 expect(
18 deriveMenuHorizontalPlacement({ ...base, anchorX: 340, hinge: { x: 426, width: 0 } }),
19 ).toEqual({ left: 164, width: 224 });
20 expect(
21 deriveMenuHorizontalPlacement({ ...base, anchorX: 430, hinge: { x: 426, width: 0 } }),
22 ).toEqual({ left: 438, width: 224 });
23 });
24});