Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

PreviewPanelShell.test.ts

49 lines1.9 KB

1import { jsx } from "react/jsx-runtime";
2import { renderToStaticMarkup } from "react-dom/server";
3import { describe, expect, it } from "vite-plus/test";
4​
5import { getPreviewPanelMaxWidth, PreviewPanelShell } from "./PreviewPanelShell";
6​
7describe("getPreviewPanelMaxWidth", () => {
8 it("allows the panel to use 70% of an ultra-wide viewport without a pixel ceiling", () => {
9 expect(getPreviewPanelMaxWidth(6_000)).toBe(4_200);
10 });
11​
12 it("rounds fractional CSS pixels down", () => {
13 expect(getPreviewPanelMaxWidth(2_001)).toBe(1_400);
14 });
15​
16 it("keeps inline panels inside their containing workspace", () => {
17 const markup = renderToStaticMarkup(
18 jsx(PreviewPanelShell, { mode: "inline", defaultWidth: 1_000, children: "Panel" }),
19 );
20​
21 expect(markup).toContain("max-w-full");
22 });
23​
24 it("reserves the sibling column minimum when the flex row is known", () => {
25 // Fullscreen 14" MacBook: viewport 1512, sidebar ~256 → row of 1256.
26 // The 70% fraction (1058) would leave the chat column only ~198px;
27 // the container clamp caps the panel at 1256 − 360 instead.
28 expect(getPreviewPanelMaxWidth(1_512, 1_256)).toBe(896);
29 });
30​
31 it("keeps the fraction cap when the row is wide enough for both columns", () => {
32 expect(getPreviewPanelMaxWidth(3_000, 2_900)).toBe(2_100);
33 });
34​
35 it("rounds fractional row widths down", () => {
36 expect(getPreviewPanelMaxWidth(1_512, 1_256.6)).toBe(896);
37 });
38​
39 it("never drops below the panel minimum when the row cannot fit both columns", () => {
40 // ~1000px window with an expanded sidebar → row of 700. The sibling
41 // reservation (700 − 360 = 340) would undercut the panel's own 360
42 // minimum and invert the resize clamp, so the floor wins.
43 expect(getPreviewPanelMaxWidth(1_000, 700)).toBe(360);
44 });
45​
46 it("stays at the panel minimum even when the row is narrower than the reservation", () => {
47 expect(getPreviewPanelMaxWidth(1_512, 300)).toBe(360);
48 });
49});