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

sidebar.test.tsx

111 lines3.6 KB

1import { renderToStaticMarkup } from "react-dom/server";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 SidebarMenuAction,
6 SidebarMenuButton,
7 SidebarMenuSubButton,
8 SidebarProvider,
9 SidebarTrigger,
10} from "./sidebar";
11import { resolveSidebarState } from "./sidebarState";
12​
13function renderSidebarButton(className?: string) {
14 return renderToStaticMarkup(
15 <SidebarProvider>
16 <SidebarMenuButton className={className}>Projects</SidebarMenuButton>
17 </SidebarProvider>,
18 );
20​
21describe("sidebar interactive cursors", () => {
22 it("uses mobile sheet visibility for the shared responsive state", () => {
23 expect(resolveSidebarState({ isMobile: true, open: true, openMobile: false })).toBe(
24 "collapsed",
25 );
26 expect(resolveSidebarState({ isMobile: true, open: false, openMobile: true })).toBe("expanded");
27 expect(resolveSidebarState({ isMobile: false, open: true, openMobile: false })).toBe(
28 "expanded",
29 );
30 });
31​
32 it("exposes collapsed state for shared titlebar inset styling", () => {
33 const html = renderToStaticMarkup(
34 <SidebarProvider defaultOpen={false}>
35 <div />
36 </SidebarProvider>,
37 );
38​
39 expect(html).toContain('data-sidebar-state="collapsed"');
40 });
41​
42 it("keeps the sidebar trigger interactive inside Electron drag regions", () => {
43 const html = renderToStaticMarkup(
44 <SidebarProvider>
45 <SidebarTrigger />
46 </SidebarProvider>,
47 );
48​
49 expect(html).toContain("[-webkit-app-region:no-drag]");
50 expect(html).toContain("size-[var(--workspace-titlebar-control-size)]!");
51 });
52​
53 it("uses shared geometry and icon constraints for menu buttons by default", () => {
54 const html = renderSidebarButton();
55​
56 expect(html).toContain('data-slot="sidebar-menu-button"');
57 expect(html).toContain("h-8");
58 expect(html).toContain("rounded-[var(--control-radius)]");
59 expect(html).toContain("px-[var(--sidebar-row-content-inset)]");
60 expect(html).toContain("py-1.5");
61 expect(html).toContain("]:size-4");
62 expect(html).toContain("]:shrink-0");
63 expect(html).toContain("cursor-pointer");
64 expect(html).toContain("gap-[var(--sidebar-control-gap)]");
65 expect(html).toContain("text-[var(--sidebar-icon-color)]");
66 expect(html).not.toContain("[&amp;&gt;svg]:opacity-60");
67 });
68​
69 it("applies the shared default treatment to icon-only menu buttons", () => {
70 const html = renderToStaticMarkup(
71 <SidebarProvider>
72 <SidebarMenuButton size="icon">
73 <span>+</span>
74 </SidebarMenuButton>
75 </SidebarProvider>,
76 );
77​
78 expect(html).toContain("size-8");
79 expect(html).toContain("justify-center");
80 expect(html).toContain("p-0");
81 expect(html).toContain("font-medium");
82 expect(html).toContain("text-sidebar-muted-foreground/80");
83 });
84​
85 it("lets project drag handles override the default pointer cursor", () => {
86 const html = renderSidebarButton("cursor-grab");
87​
88 expect(html).toContain("cursor-grab");
89 expect(html).not.toContain("cursor-pointer");
90 });
91​
92 it("uses a pointer cursor for menu actions", () => {
93 const html = renderToStaticMarkup(
94 <SidebarMenuAction aria-label="Create thread">
95 <span>+</span>
96 </SidebarMenuAction>,
97 );
98​
99 expect(html).toContain('data-slot="sidebar-menu-action"');
100 expect(html).toContain("cursor-pointer");
101 });
102​
103 it("uses a pointer cursor for submenu buttons", () => {
104 const html = renderToStaticMarkup(
105 <SidebarMenuSubButton render={<button type="button" />}>Show more</SidebarMenuSubButton>,
106 );
107​
108 expect(html).toContain('data-slot="sidebar-menu-sub-button"');
109 expect(html).toContain("cursor-pointer");
110 });
111});