-
Notifications
You must be signed in to change notification settings - Fork 53
feat(sessions): Scrollable & collapsible queued-messages dock #2904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+220
−27
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
packages/ui/src/features/sessions/components/QueuedMessagesDock.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| import { Theme } from "@radix-ui/themes"; | ||
| import { fireEvent, render, screen } from "@testing-library/react"; | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| const queuedState = vi.hoisted(() => ({ | ||
| messages: [] as Array<{ id: string; content: string; queuedAt: number }>, | ||
| })); | ||
|
|
||
| vi.mock("@posthog/core/sessions/sessionService", () => ({ | ||
| SESSION_SERVICE: Symbol.for("test.session-service"), | ||
| })); | ||
|
|
||
| vi.mock("@posthog/di/react", () => ({ | ||
| useService: () => ({ | ||
| steerQueuedMessage: vi.fn().mockResolvedValue(undefined), | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock("@posthog/ui/features/sessions/useSession", () => ({ | ||
| useQueuedMessagesForTask: () => queuedState.messages, | ||
| })); | ||
|
|
||
| vi.mock("@posthog/ui/features/sessions/hooks/useMessagingMode", () => ({ | ||
| useSupportsNativeSteer: () => false, | ||
| })); | ||
|
|
||
| vi.mock( | ||
| "@posthog/ui/features/sessions/hooks/useReturnQueuedMessageToEditor", | ||
| () => ({ | ||
| useReturnQueuedMessageToEditor: () => vi.fn(), | ||
| }), | ||
| ); | ||
|
|
||
| vi.mock("@posthog/ui/features/sessions/sessionStore", () => ({ | ||
| sessionStoreSetters: { removeQueuedMessage: vi.fn() }, | ||
| useSessionIsCloud: () => false, | ||
| useSessionSelector: <T,>( | ||
| _taskId: string, | ||
| select: (session: undefined) => T, | ||
| ) => select(undefined), | ||
| })); | ||
|
|
||
| vi.mock("@posthog/ui/primitives/toast", () => ({ | ||
| toast: { error: vi.fn() }, | ||
| })); | ||
|
|
||
| // Stub the per-message card so the test exercises the dock's collapse/scroll | ||
| // shell, not the markdown/steer internals it already owns. | ||
| vi.mock( | ||
| "@posthog/ui/features/sessions/components/session-update/QueuedMessageView", | ||
| async () => { | ||
| const React = await import("react"); | ||
| return { | ||
| QueuedMessageView: ({ message }: { message: { content: string } }) => | ||
| React.createElement( | ||
| "div", | ||
| { "data-testid": "queued-card" }, | ||
| message.content, | ||
| ), | ||
| }; | ||
| }, | ||
| ); | ||
|
|
||
| import { QueuedMessagesDock } from "./QueuedMessagesDock"; | ||
|
|
||
| const TWO_MESSAGES = [ | ||
| { id: "q1", content: "first queued message", queuedAt: 1 }, | ||
| { id: "q2", content: "second queued message", queuedAt: 2 }, | ||
| ]; | ||
|
|
||
| // Each test uses a distinct taskId so the (real, per-task) collapse state in | ||
| // sessionViewStore never bleeds between cases. | ||
| function renderDock(taskId: string) { | ||
| return render( | ||
| <Theme> | ||
| <QueuedMessagesDock taskId={taskId} /> | ||
| </Theme>, | ||
| ); | ||
| } | ||
|
|
||
| describe("QueuedMessagesDock", () => { | ||
| beforeEach(() => { | ||
| queuedState.messages = []; | ||
| }); | ||
|
|
||
| it("renders nothing when the queue is empty", () => { | ||
| queuedState.messages = []; | ||
| const { container } = render(<QueuedMessagesDock taskId="task-empty" />); | ||
| expect(container).toBeEmptyDOMElement(); | ||
| }); | ||
|
|
||
| it("is expanded by default and shows every queued message with a count", () => { | ||
| queuedState.messages = TWO_MESSAGES; | ||
| renderDock("task-expanded"); | ||
|
|
||
| expect(screen.getByText("first queued message")).toBeInTheDocument(); | ||
| expect(screen.getByText("second queued message")).toBeInTheDocument(); | ||
| expect(screen.getByText("2 queued")).toBeInTheDocument(); | ||
| expect( | ||
| screen.getByRole("button", { name: "Collapse queued messages" }), | ||
| ).toHaveAttribute("aria-expanded", "true"); | ||
| }); | ||
|
|
||
| it("caps the list height and scrolls so it can't push the composer down", () => { | ||
| queuedState.messages = TWO_MESSAGES; | ||
| const { container } = renderDock("task-scroll"); | ||
|
|
||
| const scroller = container.querySelector(".overflow-y-auto"); | ||
| expect(scroller).not.toBeNull(); | ||
| expect(scroller?.classList.contains("max-h-[30vh]")).toBe(true); | ||
| }); | ||
|
|
||
| it("collapses and expands the list when the header is toggled", () => { | ||
| queuedState.messages = TWO_MESSAGES; | ||
| renderDock("task-toggle"); | ||
|
|
||
| expect(screen.getAllByTestId("queued-card")).toHaveLength(2); | ||
|
|
||
| fireEvent.click( | ||
| screen.getByRole("button", { name: "Collapse queued messages" }), | ||
| ); | ||
|
|
||
| // Collapsed: cards are hidden, but the header with the live count stays. | ||
| expect(screen.queryAllByTestId("queued-card")).toHaveLength(0); | ||
| expect(screen.getByText("2 queued")).toBeInTheDocument(); | ||
| const trigger = screen.getByRole("button", { | ||
| name: "Expand queued messages", | ||
| }); | ||
| expect(trigger).toHaveAttribute("aria-expanded", "false"); | ||
|
|
||
| fireEvent.click(trigger); | ||
| expect(screen.getAllByTestId("queued-card")).toHaveLength(2); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.