Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/app/src/components/demo-gallery/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export function DemoGallery({ open, onClose, onTryDemo }: DemoGalleryProps) {

{/* Drawer: full-screen bottom sheet on mobile, right side panel on sm+ */}
<div
inert={!open}
aria-hidden={!open}
className={`demo-gallery-drawer fixed z-50 flex flex-col transition-transform duration-300 ease-in-out ${open ? "demo-gallery-drawer--open" : ""}`}
style={{ background: "var(--surface-primary, #fff)" }}
>
Expand Down
34 changes: 34 additions & 0 deletions apps/app/src/components/drawers.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { afterEach, expect, it, vi } from "vitest";
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import "@testing-library/jest-dom/vitest";
import { DemoGallery } from "./demo-gallery";
import { TemplateLibrary } from "./template-library";
vi.mock("@copilotkit/react-core/v2", () => ({
useAgent: () => ({ agent: { state: { templates: [] }, setState: vi.fn() } }),
}));
afterEach(cleanup);
it.each(["gallery", "templates"])("excludes the closed %s drawer from accessible interaction", (kind) => {
const makeDrawer = (open: boolean) => kind === "gallery"
? <DemoGallery open={open} onClose={vi.fn()} onTryDemo={vi.fn()} />
: <TemplateLibrary open={open} onClose={vi.fn()} />;
const view = render(makeDrawer(false));
expect(view.container.querySelector("button")).not.toBeNull();
expect(screen.queryAllByRole("button")).toHaveLength(0);
const closedButton = view.container.querySelector("button")!;
expect(closedButton.closest("[inert]")).not.toBeNull();
view.rerender(makeDrawer(true));
expect(screen.getAllByRole("button").length).toBeGreaterThan(1);
expect(screen.getAllByRole("button")[0].closest("[inert]")).toBeNull();
view.rerender(makeDrawer(false));
expect(screen.queryAllByRole("button")).toHaveLength(0);
});
it("preserves the selected gallery category across closing and reopening", () => {
const onTryDemo = vi.fn();
const onClose = vi.fn();
const view = render(<DemoGallery open onClose={onClose} onTryDemo={onTryDemo} />);
fireEvent.click(screen.getByRole("button", { name: "Compare" }));
const filteredCount = screen.getAllByRole("button").length;
view.rerender(<DemoGallery open={false} onClose={onClose} onTryDemo={onTryDemo} />);
view.rerender(<DemoGallery open onClose={onClose} onTryDemo={onTryDemo} />);
expect(screen.getAllByRole("button")).toHaveLength(filteredCount);
});
2 changes: 2 additions & 0 deletions apps/app/src/components/template-library/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export function TemplateLibrary({ open, onClose }: TemplateLibraryProps) {

{/* Drawer panel */}
<div
inert={!open}
aria-hidden={!open}
className="fixed top-0 right-0 h-full z-50 flex flex-col transition-transform duration-300 ease-in-out"
style={{
width: 380,
Expand Down