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

sidebar.test.tsx

86 lines2.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 a pointer cursor for menu buttons by default", () => {
54 const html = renderSidebarButton();
55​
56 expect(html).toContain('data-slot="sidebar-menu-button"');
57 expect(html).toContain("cursor-pointer");
58 });
59​
60 it("lets project drag handles override the default pointer cursor", () => {
61 const html = renderSidebarButton("cursor-grab");
62​
63 expect(html).toContain("cursor-grab");
64 expect(html).not.toContain("cursor-pointer");
65 });
66​
67 it("uses a pointer cursor for menu actions", () => {
68 const html = renderToStaticMarkup(
69 <SidebarMenuAction aria-label="Create thread">
70 <span>+</span>
71 </SidebarMenuAction>,
72 );
73​
74 expect(html).toContain('data-slot="sidebar-menu-action"');
75 expect(html).toContain("cursor-pointer");
76 });
77​
78 it("uses a pointer cursor for submenu buttons", () => {
79 const html = renderToStaticMarkup(
80 <SidebarMenuSubButton render={<button type="button" />}>Show more</SidebarMenuSubButton>,
81 );
82​
83 expect(html).toContain('data-slot="sidebar-menu-sub-button"');
84 expect(html).toContain("cursor-pointer");
85 });
86});