forked from mem9-ai/mem9
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui-dialog-layout.test.ts
More file actions
64 lines (55 loc) · 1.84 KB
/
ui-dialog-layout.test.ts
File metadata and controls
64 lines (55 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { describe, expect, it } from "vitest";
import {
computePixelFarmDialogPlacement,
type PixelFarmDialogPlacementInput,
} from "./ui-dialog-layout";
function createInput(
overrides: Partial<PixelFarmDialogPlacementInput> = {},
): PixelFarmDialogPlacementInput {
return {
viewportWidth: 1280,
viewportHeight: 720,
anchorX: 640,
anchorY: 260,
dialogWidth: 320,
dialogHeight: 140,
marginX: 16,
marginTop: 16,
marginBottom: 24,
offsetAboveAnchor: 18,
...overrides,
};
}
describe("computePixelFarmDialogPlacement", () => {
it("keeps the dialog above the target when the rect fits", () => {
const placement = computePixelFarmDialogPlacement(createInput());
expect(placement.mode).toBe("anchor");
expect(placement.tail).toBe("bottom-left");
expect(placement.x).toBe(480);
expect(placement.y).toBe(102);
});
it("falls back into the safe area when the anchored rect would clip the top edge", () => {
const placement = computePixelFarmDialogPlacement(
createInput({ anchorY: 48 }),
);
expect(placement.mode).toBe("safe-area");
expect(placement.x).toBe(480);
expect(placement.y).toBe(16);
});
it("flips the tail when the target sits to the right of the fallback dialog center", () => {
const placement = computePixelFarmDialogPlacement(
createInput({ anchorX: 1180, anchorY: 40 }),
);
expect(placement.mode).toBe("safe-area");
expect(placement.tail).toBe("bottom-right");
});
it("uses the top center safe slot before edge-aligned fallback positions", () => {
const placement = computePixelFarmDialogPlacement(
createInput({ anchorX: 80, anchorY: 60 }),
);
expect(placement.mode).toBe("safe-area");
expect(placement.x).toBe(480);
expect(placement.y).toBe(16);
expect(placement.tail).toBe("bottom-left");
});
});