|
| 1 | +import type { Task } from "@posthog/shared/domain-types"; |
| 2 | +import { fireEvent, render, screen } from "@testing-library/react"; |
| 3 | +import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 4 | + |
| 5 | +vi.mock("@posthog/ui/features/git-interaction/usePrDetails", () => ({ |
| 6 | + usePrDetails: () => ({ |
| 7 | + meta: { state: "open", merged: false, draft: false }, |
| 8 | + }), |
| 9 | +})); |
| 10 | + |
| 11 | +import { useThreadNavigationStore } from "@posthog/ui/features/sessions/threadNavigationStore"; |
| 12 | +import { ActivityTimeline } from "./ActivityTimeline"; |
| 13 | + |
| 14 | +const task = { |
| 15 | + id: "task-1", |
| 16 | + created_at: "2026-07-17T09:00:00Z", |
| 17 | + updated_at: "2026-07-17T09:00:00Z", |
| 18 | + created_by: { uuid: "u1", first_name: "Shy", last_name: "Alter" }, |
| 19 | + latest_run: null, |
| 20 | +} as unknown as Task; |
| 21 | + |
| 22 | +// Every conversation row is attributed to the task's creator, which is exactly why |
| 23 | +// an author-derived accessible name would be identical on all of them. |
| 24 | +const conversationItems = [ |
| 25 | + { |
| 26 | + type: "user_message" as const, |
| 27 | + id: "turn-1-1-user", |
| 28 | + content: "first thing\nand more detail", |
| 29 | + timestamp: Date.parse("2026-07-17T09:05:00Z"), |
| 30 | + }, |
| 31 | + { |
| 32 | + type: "user_message" as const, |
| 33 | + id: "turn-2-2-user", |
| 34 | + content: "second thing", |
| 35 | + timestamp: Date.parse("2026-07-17T09:10:00Z"), |
| 36 | + }, |
| 37 | +]; |
| 38 | + |
| 39 | +function renderTimeline(canOpenInPlace?: boolean) { |
| 40 | + return render( |
| 41 | + <ActivityTimeline |
| 42 | + task={task} |
| 43 | + timeline={[]} |
| 44 | + // biome-ignore lint/suspicious/noExplicitAny: narrow fixture for the rows under test |
| 45 | + conversationItems={conversationItems as any} |
| 46 | + isTaskAuthor |
| 47 | + canForward={false} |
| 48 | + canOpenInPlace={canOpenInPlace} |
| 49 | + onSendToAgent={() => {}} |
| 50 | + onDelete={() => {}} |
| 51 | + />, |
| 52 | + ); |
| 53 | +} |
| 54 | + |
| 55 | +beforeEach(() => { |
| 56 | + useThreadNavigationStore.setState({ scrollRequests: {} }); |
| 57 | +}); |
| 58 | + |
| 59 | +describe("ActivityTimeline", () => { |
| 60 | + it("names each message row by its own content, not a shared template", () => { |
| 61 | + renderTimeline(true); |
| 62 | + |
| 63 | + expect(screen.getAllByRole("button")).toHaveLength(2); |
| 64 | + // `name` here is the computed accessible name, so this is what a screen reader |
| 65 | + // announces: each row carries the content a sighted user sees, which is what |
| 66 | + // makes the two distinguishable — the author is the same on every row. |
| 67 | + expect( |
| 68 | + screen.getByRole("button", { name: /Shy Alter.*first thing/ }), |
| 69 | + ).toBeInTheDocument(); |
| 70 | + expect( |
| 71 | + screen.getByRole("button", { name: /Shy Alter.*second thing/ }), |
| 72 | + ).toBeInTheDocument(); |
| 73 | + // The avatar is decorative, so its initials stay out of the name. |
| 74 | + expect(screen.queryByRole("button", { name: /SA/ })).toBeNull(); |
| 75 | + }); |
| 76 | + |
| 77 | + it("asks the transcript to scroll to the clicked message", () => { |
| 78 | + renderTimeline(true); |
| 79 | + |
| 80 | + fireEvent.click(screen.getAllByRole("button")[1]); |
| 81 | + |
| 82 | + expect(useThreadNavigationStore.getState().scrollRequests["task-1"]).toBe( |
| 83 | + "turn-2-2-user", |
| 84 | + ); |
| 85 | + }); |
| 86 | + |
| 87 | + it("leaves rows inert with no transcript alongside to drive", () => { |
| 88 | + renderTimeline(); |
| 89 | + |
| 90 | + expect(screen.queryAllByRole("button")).toHaveLength(0); |
| 91 | + expect(screen.getByText(/first thing/)).toBeInTheDocument(); |
| 92 | + }); |
| 93 | +}); |
0 commit comments