diff --git a/apps/web/src/components/sidebar/SidebarListMarkers.browser.test.tsx b/apps/web/src/components/sidebar/SidebarListMarkers.browser.test.tsx new file mode 100644 index 0000000000000..f73b7ea54de91 --- /dev/null +++ b/apps/web/src/components/sidebar/SidebarListMarkers.browser.test.tsx @@ -0,0 +1,103 @@ +import { DndContext, useDndContext, useDraggable } from "@dnd-kit/core"; +import { useState } from "react"; +import { expect, it, vi } from "vite-plus/test"; +import { userEvent } from "vite-plus/test/browser"; + +import { act, render } from "../../../test/render"; +import { sidebarMarkerId } from "../Sidebar.logic"; +import { SidebarSectionHeader } from "./SidebarListMarkers"; + +vi.mock("./SidebarThreadRow", () => ({ + SIDEBAR_SORTABLE_DRAG_DISABLED: { draggable: true }, +})); + +function Shelf({ count }: { count: number }) { + const { active } = useDndContext(); + const { setNodeRef, attributes, listeners } = useDraggable({ id: "thread" }); + return ( + <> + + + + ); +} + +function Harness() { + const [count, setCount] = useState(0); + return ( +
+ { + if (over?.id === sidebarMarkerId("settled-header")) setCount(1); + }} + > + + + +
+ ); +} + +it("reveals an empty Settled drop target only for a drag and keeps it after a drop", async () => { + await using screen = await render(, { + router: false /* shelf drag/drop does not navigate */, + }); + const settled = screen.getByTestId("sidebar-settled-shelf-toggle"); + await expect.element(settled).not.toBeInTheDocument(); + + const startDrag = async () => { + const thread = screen.getByRole("button", { name: "Thread" }).element(); + const { x, y, width, height } = thread.getBoundingClientRect(); + await act(() => { + thread.dispatchEvent( + new PointerEvent("pointerdown", { + bubbles: true, + isPrimary: true, + pointerId: 1, + button: 0, + buttons: 1, + clientX: x + width / 2, + clientY: y + height / 2, + }), + ); + }); + await expect.element(settled).toBeVisible(); + }; + + await startDrag(); + await act(() => + document.dispatchEvent( + new KeyboardEvent("keydown", { key: "Escape", code: "Escape", bubbles: true }), + ), + ); + await expect.element(settled).not.toBeInTheDocument(); + + await startDrag(); + const target = settled.element().getBoundingClientRect(); + await act(() => { + document.dispatchEvent( + new PointerEvent("pointermove", { + bubbles: true, + pointerId: 1, + buttons: 1, + clientX: target.x + target.width / 2, + clientY: target.y + target.height / 2, + }), + ); + }); + await act(() => document.dispatchEvent(new PointerEvent("pointerup", { pointerId: 1 }))); + await expect.element(screen.getByRole("button", { name: /^Settled\s*1$/ })).toBeVisible(); + + await userEvent.click(screen.getByRole("button", { name: "Unsettle" })); + await expect.element(settled).not.toBeInTheDocument(); +}); diff --git a/apps/web/src/components/sidebar/SidebarListMarkers.tsx b/apps/web/src/components/sidebar/SidebarListMarkers.tsx index da9444a5c1b24..cf82c8da4c4ee 100644 --- a/apps/web/src/components/sidebar/SidebarListMarkers.tsx +++ b/apps/web/src/components/sidebar/SidebarListMarkers.tsx @@ -126,22 +126,31 @@ export function SidebarSectionHeader(props: { : props.marker === "snoozed-header" ? "snoozed" : "settled"; + // Keep the zero-height marker mounted so an empty shelf remains a valid drop target. + const visible = props.count > 0 || props.dragging === true; return ( - {props.count}} - > - {props.label} - + {visible ? ( + + {props.count} + + } + showChevron={!props.dragging} + > + {props.label} + + ) : null} ); } diff --git a/apps/web/src/components/ui/collapsible-section-header.tsx b/apps/web/src/components/ui/collapsible-section-header.tsx index 94323b0ad9443..674d83bfaba2d 100644 --- a/apps/web/src/components/ui/collapsible-section-header.tsx +++ b/apps/web/src/components/ui/collapsible-section-header.tsx @@ -14,12 +14,14 @@ export function CollapsibleSectionHeader({ tone = "muted", variant = "default", accessory, + showChevron = true, ...buttonProps }: Omit, "className" | "style" | "aria-expanded"> & { expanded: boolean; tone?: keyof typeof tones; variant?: "default" | "panel"; accessory?: ReactNode; + showChevron?: boolean; }) { return ( );