|
| 1 | +/* @vitest-environment jsdom */ |
| 2 | + |
| 3 | +import { render } from "lit"; |
| 4 | +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
| 5 | +import type { ControlUiSessionPullRequestSnapshot } from "../../../src/gateway/control-ui-contract.js"; |
| 6 | +import type { SidebarRecentSession } from "./app-sidebar-session-types.ts"; |
| 7 | +import { renderSessionHovercard } from "./session-hovercard.ts"; |
| 8 | + |
| 9 | +function row(overrides: Partial<SidebarRecentSession> = {}): SidebarRecentSession { |
| 10 | + return { |
| 11 | + key: "agent:main:work", |
| 12 | + label: "Ship the release", |
| 13 | + startedAt: Date.now() - 2 * 60 * 60_000, |
| 14 | + updatedAt: Date.now() - 5 * 60_000, |
| 15 | + owner: { |
| 16 | + actor: { type: "human", id: "alice", label: "Alice Baker" }, |
| 17 | + }, |
| 18 | + children: [], |
| 19 | + ...overrides, |
| 20 | + } as SidebarRecentSession; |
| 21 | +} |
| 22 | + |
| 23 | +function snapshot( |
| 24 | + overrides: Partial<ControlUiSessionPullRequestSnapshot> = {}, |
| 25 | +): ControlUiSessionPullRequestSnapshot { |
| 26 | + return { |
| 27 | + status: "ready", |
| 28 | + pullRequests: [], |
| 29 | + rateLimited: false, |
| 30 | + ...overrides, |
| 31 | + }; |
| 32 | +} |
| 33 | + |
| 34 | +describe("renderSessionHovercard", () => { |
| 35 | + beforeEach(() => { |
| 36 | + vi.useFakeTimers(); |
| 37 | + vi.setSystemTime(new Date("2026-08-17T12:00:00Z")); |
| 38 | + }); |
| 39 | + |
| 40 | + afterEach(() => { |
| 41 | + vi.useRealTimers(); |
| 42 | + }); |
| 43 | + |
| 44 | + it("renders synchronous row metadata without inventing a progress section", () => { |
| 45 | + const container = document.createElement("div"); |
| 46 | + render(renderSessionHovercard({ row: row() }), container); |
| 47 | + |
| 48 | + expect(container.querySelector(".session-hovercard__title")?.textContent).toBe( |
| 49 | + "Ship the release", |
| 50 | + ); |
| 51 | + expect(container.querySelector(".session-hovercard__avatar")?.textContent).toBe("AB"); |
| 52 | + const metadata = container.querySelector(".session-hovercard__meta")?.textContent ?? ""; |
| 53 | + expect(metadata).toContain("Alice Baker"); |
| 54 | + expect(metadata).toContain("created"); |
| 55 | + expect(metadata).toContain("updated"); |
| 56 | + expect(container.querySelector(".session-progress-card")).toBeNull(); |
| 57 | + expect(container.querySelector(".session-hovercard__divider")).toBeNull(); |
| 58 | + }); |
| 59 | + |
| 60 | + it("renders bounded linked PR chips with state, CI, and diff facts", () => { |
| 61 | + const container = document.createElement("div"); |
| 62 | + render( |
| 63 | + renderSessionHovercard({ |
| 64 | + pullRequests: snapshot({ |
| 65 | + pullRequests: [ |
| 66 | + { |
| 67 | + number: 101, |
| 68 | + owner: "openclaw", |
| 69 | + repo: "openclaw", |
| 70 | + branch: "feature", |
| 71 | + title: "First", |
| 72 | + url: "https://github.com/openclaw/openclaw/pull/101", |
| 73 | + state: "open", |
| 74 | + changedFiles: 2, |
| 75 | + additions: 7, |
| 76 | + deletions: 3, |
| 77 | + checks: { state: "passing", passed: 2, failed: 0, skipped: 0, running: 0 }, |
| 78 | + }, |
| 79 | + { |
| 80 | + number: 102, |
| 81 | + owner: "openclaw", |
| 82 | + repo: "openclaw", |
| 83 | + branch: "feature", |
| 84 | + title: "Second", |
| 85 | + url: "https://github.com/openclaw/openclaw/pull/102", |
| 86 | + state: "draft", |
| 87 | + }, |
| 88 | + { |
| 89 | + number: 103, |
| 90 | + owner: "openclaw", |
| 91 | + repo: "openclaw", |
| 92 | + branch: "feature", |
| 93 | + title: "Third", |
| 94 | + url: "https://github.com/openclaw/openclaw/pull/103", |
| 95 | + state: "merged", |
| 96 | + }, |
| 97 | + { |
| 98 | + number: 104, |
| 99 | + owner: "openclaw", |
| 100 | + repo: "openclaw", |
| 101 | + branch: "feature", |
| 102 | + title: "Fourth", |
| 103 | + url: "https://github.com/openclaw/openclaw/pull/104", |
| 104 | + state: "closed", |
| 105 | + }, |
| 106 | + ], |
| 107 | + }), |
| 108 | + }), |
| 109 | + container, |
| 110 | + ); |
| 111 | + |
| 112 | + const links = [...container.querySelectorAll<HTMLAnchorElement>(".session-hovercard__pr-chip")]; |
| 113 | + expect(links).toHaveLength(3); |
| 114 | + expect(links[0]?.href).toBe("https://github.com/openclaw/openclaw/pull/101"); |
| 115 | + expect(links[0]?.target).toBe("_blank"); |
| 116 | + expect(links[0]?.rel).toContain("noopener"); |
| 117 | + expect(links[0]?.querySelector(".session-hovercard__pr-number")?.textContent).toBe("#101"); |
| 118 | + expect(links[0]?.querySelector(".session-hovercard__pr-state")?.textContent).toBe("Open"); |
| 119 | + expect(links[0]?.querySelector("[data-checks='passing']")?.textContent).toBe("✓"); |
| 120 | + expect(links[0]?.querySelector(".session-hovercard__files")?.textContent).toBe("2 files"); |
| 121 | + expect(links[0]?.querySelector(".session-hovercard__additions")?.textContent).toBe("+7"); |
| 122 | + expect(links[0]?.querySelector(".session-hovercard__deletions")?.textContent).toBe("−3"); |
| 123 | + expect(container.querySelector(".session-hovercard__more")?.textContent).toBe("+1 more"); |
| 124 | + }); |
| 125 | + |
| 126 | + it("falls back to branch and diff chips with a create-PR link", () => { |
| 127 | + const container = document.createElement("div"); |
| 128 | + render( |
| 129 | + renderSessionHovercard({ |
| 130 | + row: row({ workSession: true, subtitle: "openclaw/openclaw · feature" }), |
| 131 | + pullRequests: snapshot({ |
| 132 | + branch: { |
| 133 | + owner: "openclaw", |
| 134 | + repo: "openclaw", |
| 135 | + branch: "feature", |
| 136 | + changedFiles: 3, |
| 137 | + additions: 12, |
| 138 | + deletions: 4, |
| 139 | + createUrl: "https://github.com/openclaw/openclaw/pull/new/feature", |
| 140 | + }, |
| 141 | + }), |
| 142 | + }), |
| 143 | + container, |
| 144 | + ); |
| 145 | + |
| 146 | + expect(container.querySelector(".session-hovercard__branch-chip")?.textContent).toBe( |
| 147 | + "openclaw/openclaw · feature", |
| 148 | + ); |
| 149 | + expect(container.querySelector(".session-hovercard__files")?.textContent).toBe("3 files"); |
| 150 | + expect(container.querySelector(".session-hovercard__additions")?.textContent).toBe("+12"); |
| 151 | + expect(container.querySelector(".session-hovercard__deletions")?.textContent).toBe("−4"); |
| 152 | + const createLink = container.querySelector<HTMLAnchorElement>(".session-hovercard__no-pr a"); |
| 153 | + expect(createLink?.textContent).toBe("No PR yet"); |
| 154 | + expect(createLink?.href).toBe("https://github.com/openclaw/openclaw/pull/new/feature"); |
| 155 | + }); |
| 156 | +}); |
0 commit comments