Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 clampPreviewMiniPlayerPosition,
5 clampPreviewMiniPlayerSize,
6 defaultPreviewMiniPlayerPosition,
7 PREVIEW_MINI_PLAYER_EDGE_GAP,
8} from "./previewMiniPlayerLayout";
9
10describe("defaultPreviewMiniPlayerPosition", () => {
11 it("keeps the top-right fallback when the inline details panel is closed", () => {
12 expect(
13 defaultPreviewMiniPlayerPosition({
14 fallback: { x: 664, y: 16 },
15 parentRect: { left: 300, top: 60 },
16 playerWidth: 320,
17 detailsCardRect: null,
18 }),
19 ).toEqual({ x: 664, y: 16 });
20 });
21
22 it("slides under the inline details card with right edges aligned", () => {
23 expect(
24 defaultPreviewMiniPlayerPosition({
25 fallback: { x: 664, y: 16 },
26 parentRect: { left: 300, top: 60 },
27 playerWidth: 320,
28 detailsCardRect: { right: 1280, bottom: 320 },
29 }),
30 ).toEqual({
31 x: 1280 - 300 - 320,
32 y: 320 - 60 + PREVIEW_MINI_PLAYER_EDGE_GAP,
33 });
34 });
35});
36
37describe("clampPreviewMiniPlayerPosition", () => {
38 it("keeps a dragged player within the chat viewport", () => {
39 expect(
40 clampPreviewMiniPlayerPosition(
41 { x: 900, y: -40 },
42 { width: 1_000, height: 700 },
43 { width: 360, height: 240 },
44 ),
45 ).toEqual({
46 x: 628,
47 y: PREVIEW_MINI_PLAYER_EDGE_GAP,
48 });
49 });
50
51 it("keeps an edge gap when the player is larger than its container", () => {
52 expect(
53 clampPreviewMiniPlayerPosition(
54 { x: 20, y: 30 },
55 { width: 200, height: 160 },
56 { width: 360, height: 240 },
57 ),
58 ).toEqual({
59 x: PREVIEW_MINI_PLAYER_EDGE_GAP,
60 y: PREVIEW_MINI_PLAYER_EDGE_GAP,
61 });
62 });
63
64 it("keeps the player above a growing composer inset", () => {
65 expect(
66 clampPreviewMiniPlayerPosition(
67 { x: 500, y: 448 },
68 { width: 1_000, height: 700 },
69 { width: 360, height: 240 },
70 160,
71 ),
72 ).toEqual({
73 x: 500,
74 y: 288,
75 });
76 });
77});
78
79describe("clampPreviewMiniPlayerSize", () => {
80 it("allows resizing within the available chat viewport", () => {
81 expect(
82 clampPreviewMiniPlayerSize({ width: 520, height: 360 }, { width: 1_000, height: 700 }, 120),
83 ).toEqual({ width: 520, height: 360 });
84 });
85
86 it("bounds oversized players above the composer", () => {
87 expect(
88 clampPreviewMiniPlayerSize(
89 { width: 2_000, height: 2_000 },
90 { width: 1_000, height: 700 },
91 120,
92 ),
93 ).toEqual({ width: 976, height: 556 });
94 });
95
96 it("lets a tiny container win over the preferred minimum", () => {
97 expect(
98 clampPreviewMiniPlayerSize({ width: 360, height: 239 }, { width: 250, height: 180 }, 20),
99 ).toEqual({ width: 226, height: 136 });
100 });
101});