Skip to content

Commit 6cd02e9

Browse files
feat(web): filter PR comments by bots and resolved threads (pingdotgg#17645)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent e308522 commit 6cd02e9

2 files changed

Lines changed: 205 additions & 269 deletions

File tree

‎apps/web/src/components/pullRequest/PullRequestSummaryTab.test.tsx‎

Lines changed: 89 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ vi.mock("~/browser/useOpenLink", () => ({ useOpenLink: () => vi.fn() }));
99
vi.mock("./PullRequestMarkdown", () => ({
1010
PullRequestMarkdown: ({ text }: { text: string }) => <p>{text}</p>,
1111
}));
12+
vi.mock("../ui/menu", () => ({
13+
Menu: "div",
14+
MenuCheckboxItem: "div",
15+
MenuGroup: "div",
16+
MenuGroupLabel: "div",
17+
MenuPopup: "div",
18+
MenuTrigger: "div",
19+
}));
1220
vi.mock("../ui/tooltip", () => ({
1321
Tooltip: ({ children }: { children: ReactNode }) => children,
1422
TooltipTrigger: ({ children }: { children: ReactNode }) => children,
@@ -70,7 +78,20 @@ const detail: PullRequestDetailView = {
7078
};
7179

7280
let renderer: ReactTestRenderer;
73-
beforeEach(() => vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true));
81+
beforeEach(() => {
82+
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
83+
const store = new Map<string, string>();
84+
vi.stubGlobal(
85+
"window",
86+
Object.assign(new EventTarget(), {
87+
localStorage: {
88+
getItem: (key: string) => store.get(key) ?? null,
89+
setItem: (key: string, value: string) => store.set(key, value),
90+
removeItem: (key: string) => store.delete(key),
91+
},
92+
}),
93+
);
94+
});
7495
afterEach(() => {
7596
act(() => renderer?.unmount());
7697
vi.unstubAllGlobals();
@@ -145,70 +166,80 @@ it("keeps an unsaved description when collapsed and reopened", () => {
145166
expect(renderer.root.findByType("textarea").props.value).toBe("Unsaved description");
146167
});
147168

148-
it("opens bot reports in pages without hiding human comments", () => {
169+
function texts() {
170+
return renderer.root
171+
.findAllByType("p")
172+
.map((p) => p.children.join(""))
173+
.filter((text) => text !== detail.body);
174+
}
175+
176+
function filterItem(label: string) {
177+
return renderer.root.find(
178+
(node) => typeof node.props.onCheckedChange === "function" && node.children.includes(label),
179+
);
180+
}
181+
182+
it("hides bot and resolved comments until the filter shows them, and remembers the choice", () => {
183+
const comment = (index: number, login: string, body: string, isBot = false) => ({
184+
id: `comment-${index}`,
185+
kind: "issue-comment" as const,
186+
author: { login, name: null, avatarUrl: null, isBot },
187+
body,
188+
createdAt: `2026-09-01T00:00:${String(index).padStart(2, "0")}Z`,
189+
url: null,
190+
path: null,
191+
reviewState: null,
192+
});
193+
const resolved = {
194+
...comment(13, "reviewer", "Resolved remark"),
195+
kind: "review-comment" as const,
196+
};
149197
const value: PullRequestDetailView = {
150198
...detail,
151-
commentCount: 13,
152-
comments: Array.from({ length: 13 }, (_, index) => ({
153-
id: `comment-${index}`,
154-
kind: "issue-comment",
155-
author: {
156-
login: index === 12 ? "human" : "review-app",
157-
name: null,
158-
avatarUrl: null,
159-
isBot: index !== 12,
199+
commentCount: 14,
200+
comments: [
201+
...Array.from({ length: 12 }, (_, index) =>
202+
comment(index, "review-app", `Bot report ${index}`, true),
203+
),
204+
comment(12, "human", "Human comment"),
205+
resolved,
206+
],
207+
reviewThreads: [
208+
{
209+
id: "thread",
210+
path: "src/index.ts",
211+
line: 1,
212+
side: "right",
213+
isResolved: true,
214+
isOutdated: false,
215+
comments: [resolved],
160216
},
161-
body: index === 12 ? "Human comment" : `Bot report ${index}`,
162-
createdAt: `2026-09-01T00:00:${String(index).padStart(2, "0")}Z`,
163-
url: null,
164-
path: null,
165-
reviewState: null,
166-
})),
217+
],
167218
};
168219
act(() => {
169220
renderer = create(render(value));
170221
});
171-
expect(renderer.root.findAllByType("p").map((p) => p.children.join(""))).toContain(
172-
"Human comment",
173-
);
174-
expect(
175-
renderer.root.findAllByType("p").some((p) => p.children.join("").startsWith("Bot report")),
176-
).toBe(false);
177-
const group = renderer.root
178-
.findAllByType("button")
179-
.find((button) => button.props["aria-label"] === "12 bot comments")!;
180-
act(() => group.props.onClick({ nativeEvent: {}, preventDefault() {}, stopPropagation() {} }));
222+
expect(texts()).toEqual(["Human comment"]);
181223
expect(
182-
renderer.root.findAllByType("p").filter((p) => p.children.join("").startsWith("Bot report")),
183-
).toHaveLength(10);
184-
expect(renderer.root.findAllByType("p").map((p) => p.children.join(""))).not.toContain(
185-
"Bot report 0",
186-
);
187-
act(() =>
188-
renderer.root
189-
.findAllByType("button")
190-
.find((button) => button.children.includes(" older bot comment"))!
191-
.props.onClick(),
192-
);
193-
expect(
194-
renderer.root.findAllByType("p").filter((p) => p.children.join("").startsWith("Bot report")),
195-
).toHaveLength(12);
196-
act(() => group.props.onClick({ nativeEvent: {}, preventDefault() {}, stopPropagation() {} }));
197-
act(() => group.props.onClick({ nativeEvent: {}, preventDefault() {}, stopPropagation() {} }));
198-
expect(renderer.root.findAllByType("p").map((p) => p.children.join(""))).toContain(
199-
"Bot report 0",
200-
);
201-
act(() =>
202-
renderer.root
203-
.findAllByType("button")
204-
.find((button) => button.children.includes(" recent bot comments"))!
205-
.props.onClick(),
206-
);
207-
expect(
208-
renderer.root.findAllByType("p").filter((p) => p.children.join("").startsWith("Bot report")),
209-
).toHaveLength(10);
210-
act(() => renderer.update(render({ ...value, url: `${value.url}0`, number: 10 })));
224+
renderer.root.findByProps({ "aria-label": "Filter comments" }).children.join(""),
225+
).toContain("13 hidden");
226+
227+
act(() => filterItem("Bot comments").props.onCheckedChange(true));
228+
// Bots now share the human comment's pages: the ten most recent, the oldest left behind.
229+
expect(texts().filter((text) => text.startsWith("Bot report"))).toHaveLength(9);
230+
expect(texts()).toContain("Human comment");
231+
expect(texts()).not.toContain("Bot report 0");
232+
233+
act(() => filterItem("Resolved or dismissed").props.onCheckedChange(true));
211234
expect(
212-
renderer.root.findAllByType("p").some((p) => p.children.join("").startsWith("Bot report")),
213-
).toBe(false);
235+
renderer.root.findAllByType("button").some((button) => button.children.includes("Resolved")),
236+
).toBe(true);
237+
238+
// Another pull request, or the same one opened again, keeps the reader's choice.
239+
act(() => renderer.unmount());
240+
act(() => {
241+
renderer = create(render({ ...value, url: `${value.url}0`, number: 10 }));
242+
});
243+
expect(filterItem("Bot comments").props.checked).toBe(true);
244+
expect(texts()).toContain("Bot report 11");
214245
});

0 commit comments

Comments
 (0)