-
Notifications
You must be signed in to change notification settings - Fork 42
feat(mobile): show live PR status on inbox report cards and detail (port #2695, #2694) #2698
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import { createElement } from "react"; | ||
| import { act, create } from "react-test-renderer"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import type { PrStatus } from "../hooks/usePrStatus"; | ||
| import { PrStatusBadge } from "./PrStatusBadge"; | ||
|
|
||
| vi.mock("phosphor-react-native", () => ({ | ||
| GitMerge: (props: Record<string, unknown>) => | ||
| createElement("GitMerge", props), | ||
| GitPullRequest: (props: Record<string, unknown>) => | ||
| createElement("GitPullRequest", props), | ||
| })); | ||
|
|
||
| vi.mock("@/lib/theme", () => ({ | ||
| useThemeColors: () => ({ | ||
| gray: { 11: "#444444" }, | ||
| status: { success: "#00aa00", error: "#cc0000" }, | ||
| }), | ||
| toRgba: (hex: string, alpha: number) => `${hex}/${alpha}`, | ||
| })); | ||
|
|
||
| vi.mock("@/lib/openExternalUrl", () => ({ openExternalUrl: vi.fn() })); | ||
|
|
||
| vi.mock("../hooks/usePrStatus", () => ({ usePrStatus: vi.fn() })); | ||
|
|
||
| import { usePrStatus } from "../hooks/usePrStatus"; | ||
|
|
||
| const mockUsePrStatus = vi.mocked(usePrStatus); | ||
|
|
||
| function setStatus(data: PrStatus | null | undefined) { | ||
| mockUsePrStatus.mockReturnValue({ data } as ReturnType<typeof usePrStatus>); | ||
| } | ||
|
|
||
| function render(props: Parameters<typeof PrStatusBadge>[0]) { | ||
| let renderer: ReturnType<typeof create> | null = null; | ||
| act(() => { | ||
| renderer = create(createElement(PrStatusBadge, props)); | ||
| }); | ||
| if (!renderer) throw new Error("Renderer not created"); | ||
| return renderer as ReturnType<typeof create>; | ||
| } | ||
|
|
||
| function label(renderer: ReturnType<typeof create>): string | undefined { | ||
| const node = renderer.root.findAll( | ||
| (n) => typeof n.props?.accessibilityLabel === "string", | ||
| )[0]; | ||
| return node?.props.accessibilityLabel as string | undefined; | ||
| } | ||
|
|
||
| function iconCount(renderer: ReturnType<typeof create>, type: string): number { | ||
| return renderer.root.findAll((n) => n.type === type).length; | ||
| } | ||
|
|
||
| const base: PrStatus = { | ||
| state: "open", | ||
| merged: false, | ||
| draft: false, | ||
| additions: 0, | ||
| deletions: 0, | ||
| }; | ||
|
|
||
| describe("PrStatusBadge", () => { | ||
| it("renders an open PR badge", () => { | ||
| setStatus({ ...base, state: "open" }); | ||
| const r = render({ prUrl: "https://github.com/a/b/pull/1" }); | ||
| expect(label(r)).toBe("Open PR"); | ||
| expect(iconCount(r, "GitPullRequest")).toBe(1); | ||
| }); | ||
|
|
||
| it("renders a merged PR badge with the merge icon", () => { | ||
| setStatus({ ...base, state: "closed", merged: true }); | ||
| const r = render({ prUrl: "https://github.com/a/b/pull/1" }); | ||
| expect(label(r)).toBe("Open merged PR"); | ||
| expect(iconCount(r, "GitMerge")).toBe(1); | ||
| expect(iconCount(r, "GitPullRequest")).toBe(0); | ||
| }); | ||
|
|
||
| it("renders a closed PR badge", () => { | ||
| setStatus({ ...base, state: "closed" }); | ||
| const r = render({ prUrl: "https://github.com/a/b/pull/1" }); | ||
| expect(label(r)).toBe("Open closed PR"); | ||
| }); | ||
|
|
||
| it("renders a draft PR badge", () => { | ||
| setStatus({ ...base, state: "open", draft: true }); | ||
| const r = render({ prUrl: "https://github.com/a/b/pull/1" }); | ||
| expect(label(r)).toBe("Open draft PR"); | ||
| }); | ||
|
|
||
| it.each([ | ||
| { data: undefined, label: "loading" }, | ||
| { data: null, label: "unresolved (private/404/non-GitHub)" }, | ||
| ])( | ||
| "renders nothing when hideWhenUnresolved is set and status is $label", | ||
| ({ data }) => { | ||
| setStatus(data); | ||
| const r = render({ | ||
| prUrl: "https://github.com/a/b/pull/1", | ||
| hideWhenUnresolved: true, | ||
| }); | ||
| expect(r.toJSON()).toBeNull(); | ||
| }, | ||
| ); | ||
|
|
||
| it("still renders a neutral badge for an unresolved PR by default", () => { | ||
| setStatus(null); | ||
| const r = render({ prUrl: "https://github.com/a/b/pull/1" }); | ||
| expect(r.toJSON()).not.toBeNull(); | ||
| expect(label(r)).toBe("Open PR"); | ||
| }); | ||
| }); | ||
|
Comment on lines
+55
to
+111
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR adds a Prompt To Fix With AIThis is a comment left during a code review.
Path: apps/mobile/src/features/tasks/components/PrStatusBadge.test.tsx
Line: 55-111
Comment:
**New `size` prop is untested**
The PR adds a `size` prop with distinct `box` class and `iconSize` values for `"sm"` vs `"md"`, but no test asserts on either. The `iconSize` logic (`16` vs `20`) is passed as a prop to the icon, so it is observable in the rendered tree. Without a test, a future refactor could silently regress the compact badge on list rows.
How can I resolve this? If you propose a fix, please make it concise. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The four individual state cases (open, merged, closed, draft) repeat the same structure — call
setStatus, render with an identicalprUrl, assert onlabel(). Per the team's convention we always prefer parameterised tests; these are a natural fit forit.each. The merged case has one extra icon assertion that can be captured as an optional field in the test-case object (e.g.expectedIcon?: stringdefaulting to"GitPullRequest"), keeping the whole suite in one table.Context Used: Do not attempt to comment on incorrect alphabetica... (source)
Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!