Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 clampPreviewMiniPlayerPosition,
5 clampPreviewMiniPlayerSize,
6 PREVIEW_MINI_PLAYER_EDGE_GAP,
7} from "./previewMiniPlayerLayout";
8
9describe("clampPreviewMiniPlayerPosition", () => {
10 it("keeps a dragged player within the chat viewport", () => {
11 expect(
12 clampPreviewMiniPlayerPosition(
13 { x: 900, y: -40 },
14 { width: 1_000, height: 700 },
15 { width: 360, height: 240 },
16 ),
17 ).toEqual({
18 x: 628,
19 y: PREVIEW_MINI_PLAYER_EDGE_GAP,
20 });
21 });
22
23 it("keeps an edge gap when the player is larger than its container", () => {
24 expect(
25 clampPreviewMiniPlayerPosition(
26 { x: 20, y: 30 },
27 { width: 200, height: 160 },
28 { width: 360, height: 240 },
29 ),
30 ).toEqual({
31 x: PREVIEW_MINI_PLAYER_EDGE_GAP,
32 y: PREVIEW_MINI_PLAYER_EDGE_GAP,
33 });
34 });
35
36 it("keeps the player above a growing composer inset", () => {
37 expect(
38 clampPreviewMiniPlayerPosition(
39 { x: 500, y: 448 },
40 { width: 1_000, height: 700 },
41 { width: 360, height: 240 },
42 160,
43 ),
44 ).toEqual({
45 x: 500,
46 y: 288,
47 });
48 });
49});
50
51describe("clampPreviewMiniPlayerSize", () => {
52 it("allows resizing within the available chat viewport", () => {
53 expect(
54 clampPreviewMiniPlayerSize({ width: 520, height: 360 }, { width: 1_000, height: 700 }, 120),
55 ).toEqual({ width: 520, height: 360 });
56 });
57
58 it("bounds oversized players above the composer", () => {
59 expect(
60 clampPreviewMiniPlayerSize(
61 { width: 2_000, height: 2_000 },
62 { width: 1_000, height: 700 },
63 120,
64 ),
65 ).toEqual({ width: 976, height: 556 });
66 });
67
68 it("lets a tiny container win over the preferred minimum", () => {
69 expect(
70 clampPreviewMiniPlayerSize({ width: 360, height: 239 }, { width: 250, height: 180 }, 20),
71 ).toEqual({ width: 226, height: 136 });
72 });
73});