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

sidebar.test.tsx

108 lines3.4 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-md");
59 expect(html).toContain("px-2");
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 });
65​
66 it("applies the shared default treatment to icon-only menu buttons", () => {
67 const html = renderToStaticMarkup(
68 <SidebarProvider>
69 <SidebarMenuButton size="icon">
70 <span>+</span>
71 </SidebarMenuButton>
72 </SidebarProvider>,
73 );
74​
75 expect(html).toContain("size-8");
76 expect(html).toContain("justify-center");
77 expect(html).toContain("p-0");
78 expect(html).toContain("font-medium");
79 expect(html).toContain("text-sidebar-muted-foreground/80");
80 });
81​
82 it("lets project drag handles override the default pointer cursor", () => {
83 const html = renderSidebarButton("cursor-grab");
84​
85 expect(html).toContain("cursor-grab");
86 expect(html).not.toContain("cursor-pointer");
87 });
88​
89 it("uses a pointer cursor for menu actions", () => {
90 const html = renderToStaticMarkup(
91 <SidebarMenuAction aria-label="Create thread">
92 <span>+</span>
93 </SidebarMenuAction>,
94 );
95​
96 expect(html).toContain('data-slot="sidebar-menu-action"');
97 expect(html).toContain("cursor-pointer");
98 });
99​
100 it("uses a pointer cursor for submenu buttons", () => {
101 const html = renderToStaticMarkup(
102 <SidebarMenuSubButton render={<button type="button" />}>Show more</SidebarMenuSubButton>,
103 );
104​
105 expect(html).toContain('data-slot="sidebar-menu-sub-button"');
106 expect(html).toContain("cursor-pointer");
107 });
108});