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

threadSidebarWidth.test.ts

48 lines1.7 KB

1// @effect-diagnostics nodeBuiltinImport:off - Regression coverage compares the sidebar component with its width contract.
2import * as NodeFS from "node:fs";
3​
4import { describe, expect, it } from "vite-plus/test";
5​
6import {
7 resolveInitialThreadSidebarWidth,
8 THREAD_MAIN_CONTENT_MIN_WIDTH,
9 THREAD_SIDEBAR_DEFAULT_WIDTH,
10 THREAD_SIDEBAR_MIN_WIDTH,
11} from "./threadSidebarWidth";
12​
13describe("thread sidebar width", () => {
14 it("uses the default width when no preference is stored", () => {
15 expect(resolveInitialThreadSidebarWidth(null, 1200)).toBe(THREAD_SIDEBAR_DEFAULT_WIDTH);
16 });
17​
18 it("uses a stored width in the initial render", () => {
19 expect(resolveInitialThreadSidebarWidth(360, 1200)).toBe(360);
20 });
21​
22 it("clamps a stored width to the sidebar minimum", () => {
23 expect(resolveInitialThreadSidebarWidth(120, 1200)).toBe(THREAD_SIDEBAR_MIN_WIDTH);
24 });
25​
26 it("leaves enough room for the main content on a smaller window", () => {
27 const viewportWidth = 1000;
28​
29 expect(resolveInitialThreadSidebarWidth(900, viewportWidth)).toBe(
30 viewportWidth - THREAD_MAIN_CONTENT_MIN_WIDTH,
31 );
32 });
33​
34 it("keeps the sidebar minimum when the whole layout is narrower than its minimums", () => {
35 expect(resolveInitialThreadSidebarWidth(900, 700)).toBe(THREAD_SIDEBAR_MIN_WIDTH);
36 });
37​
38 it("shows the desktop wordmark across the sidebar's full legal width range", () => {
39 const sidebarSource = NodeFS.readFileSync(
40 new URL("./sidebar/SidebarChrome.tsx", import.meta.url),
41 "utf8",
42 );
43​
44 expect(sidebarSource).toContain("hidden h-7 w-fit min-w-0 shrink-0 items-center gap-1");
45 expect(sidebarSource).toContain("md:flex");
46 expect(THREAD_SIDEBAR_MIN_WIDTH).toBe(13 * 16);
47 });
48});