diff --git a/packages/loopover-ui-kit/src/components/sidebar.test.tsx b/packages/loopover-ui-kit/src/components/sidebar.test.tsx new file mode 100644 index 0000000000..27d3fbc893 --- /dev/null +++ b/packages/loopover-ui-kit/src/components/sidebar.test.tsx @@ -0,0 +1,87 @@ +import { fireEvent, render, screen } from "@testing-library/react"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { SidebarProvider, useSidebar } from "./sidebar"; + +// jsdom implements no window.matchMedia; SidebarProvider pulls it in via useIsMobile. Stub it desktop-shaped +// (matches:false), the standard shadcn use-mobile test setup. +beforeEach(() => { + vi.stubGlobal( + "matchMedia", + vi.fn(() => ({ + matches: false, + media: "", + addEventListener: () => {}, + removeEventListener: () => {}, + })), + ); +}); +afterEach(() => vi.unstubAllGlobals()); + +// #8305: SidebarProvider's global Cmd/Ctrl+B keydown handler used to toggle the sidebar (and preventDefault()) +// no matter what had focus — hijacking the browser-native Bold shortcut inside text fields. These pin the +// isTyping() guard: the shortcut still works from non-editable targets, and is inert inside a form field or +// contenteditable element (target's own text-editing keeps the native behavior). + +function StateProbe() { + const { open } = useSidebar(); + return {open ? "open" : "closed"}; +} + +function setup() { + const utils = render( + + + +