Skip to content
Merged
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
57 changes: 53 additions & 4 deletions apps/app/src/components/thread/ThreadActionsMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const mockActions = vi.hoisted(() => ({
archiveThreadAndChildren: vi.fn(),
requestRename: vi.fn(),
requestDelete: vi.fn(),
sendToPopout: null,
sendToPopout: null as ((thread: Thread) => void) | null,
togglePin: vi.fn(),
toggleRead: vi.fn(),
unarchiveThread: vi.fn(),
Expand Down Expand Up @@ -45,15 +45,23 @@ function makeThread(overrides: Partial<Thread> = {}): Thread {
};
}

async function renderOpenMenu(thread: Thread) {
async function renderOpenMenu(
thread: Thread,
{ isCompactViewport = true }: { isCompactViewport?: boolean } = {},
) {
const onOpenChange = vi.fn();
render(
<CompactViewportOverrideProvider isCompactViewport={true}>
<CompactViewportOverrideProvider isCompactViewport={isCompactViewport}>
<ThreadActionsMenu thread={thread} onOpenChange={onOpenChange} />
</CompactViewportOverrideProvider>,
);

fireEvent.click(screen.getByRole("button", { name: "Thread actions" }));
const trigger = screen.getByRole("button", { name: "Thread actions" });
if (isCompactViewport) {
fireEvent.click(trigger);
} else {
fireEvent.pointerDown(trigger, { button: 0 });
}
await screen.findByRole("menuitem", { name: /Mark / });
expect(onOpenChange).toHaveBeenLastCalledWith(true);
return onOpenChange;
Expand All @@ -64,10 +72,23 @@ function expectMenuItemIcon(label: string, iconName: string) {
expect(menuItem.querySelector(`[data-icon="${iconName}"]`)).not.toBeNull();
}

function getMenuRoleSequence(): string[] {
return Array.from(
screen
.getByRole("menu")
.querySelectorAll('[role="menuitem"], [role="separator"]'),
).map((element) =>
element.getAttribute("role") === "separator"
? "separator"
: (element.textContent ?? "").trim(),
);
}

describe("ThreadActionsMenu", () => {
afterEach(() => {
cleanup();
vi.clearAllMocks();
mockActions.sendToPopout = null;
});

it.each([
Expand Down Expand Up @@ -119,4 +140,32 @@ describe("ThreadActionsMenu", () => {
expectMenuItemIcon("Archive", "Archive");
expectMenuItemIcon("Delete", "Trash2");
});

it("omits dividers when rendering as a compact drawer", async () => {
await renderOpenMenu(makeThread(), { isCompactViewport: true });

expect(screen.queryAllByRole("separator")).toHaveLength(0);
});

it("renders one divider before lifecycle actions when the popout action is unavailable", async () => {
await renderOpenMenu(makeThread(), { isCompactViewport: false });

expect(screen.getAllByRole("separator")).toHaveLength(1);
expect(getMenuRoleSequence()).toEqual([
"Mark read",
"Pin",
"Rename",
"separator",
"Archive",
"Delete",
]);
});

it("renders both dividers when the popout action is available", async () => {
mockActions.sendToPopout = vi.fn();

await renderOpenMenu(makeThread(), { isCompactViewport: false });

expect(screen.getAllByRole("separator")).toHaveLength(2);
});
});
13 changes: 10 additions & 3 deletions apps/app/src/components/thread/ThreadActionsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { Icon, type IconName } from "@/components/ui/icon.js";
import { Button } from "@/components/ui/button.js";
import { COARSE_POINTER_ICON_SIZE_CLASS } from "@/components/ui/coarse-pointer-sizing.js";
import { useIsCompactViewport } from "@/components/ui/hooks/use-compact-viewport.js";
import { cn } from "@/lib/utils";
import { isThreadRead } from "@/lib/thread-read-state";
import { useThreadActions } from "./ThreadActionsProvider";
Expand Down Expand Up @@ -124,9 +125,13 @@ function ThreadActionsMenuItems({
unarchiveThread,
sendToPopout,
} = useThreadActions();
const isCompactViewport = useIsCompactViewport();
const isDrawer = surface === "dropdown" && isCompactViewport;
const showSeparators = !isDrawer;
const isRead = isThreadRead(thread);
const isArchived = thread.archivedAt != null;
const isPinned = thread.pinnedAt !== null;
const canSendToPopout = sendToPopout !== null;

return (
<>
Expand All @@ -149,8 +154,10 @@ function ThreadActionsMenuItems({
>
{isPinned ? "Unpin" : "Pin"}
</ThreadActionMenuItem>
<ThreadActionMenuSeparator surface={surface} />
{sendToPopout !== null ? (
{showSeparators && canSendToPopout ? (
<ThreadActionMenuSeparator surface={surface} />
) : null}
{canSendToPopout ? (
<ThreadActionMenuItem
surface={surface}
icon="ExternalLink"
Expand All @@ -172,7 +179,7 @@ function ThreadActionsMenuItems({
>
Rename
</ThreadActionMenuItem>
<ThreadActionMenuSeparator surface={surface} />
{showSeparators ? <ThreadActionMenuSeparator surface={surface} /> : null}
<ThreadActionMenuItem
surface={surface}
icon={isArchived ? "ArchiveRestore" : "Archive"}
Expand Down
Loading