|
| 1 | +import { SourceControlProviderKind } from "@t3tools/contracts"; |
| 2 | +import { expect, it, vi } from "vite-plus/test"; |
| 3 | +import { userEvent } from "vite-plus/test/browser"; |
| 4 | + |
| 5 | +vi.mock(import("~/state/query"), async (original) => ({ |
| 6 | + ...(await original()), |
| 7 | + useEnvironmentQuery: (() => ({})) as never, |
| 8 | +})); |
| 9 | + |
| 10 | +import { act, render } from "../../../test/render"; |
| 11 | +import type { EnvironmentPullRequestEntry } from "./pullRequestList.logic"; |
| 12 | +import { PullRequestRow } from "./PullRequestRow"; |
| 13 | + |
| 14 | +const entry = { |
| 15 | + environmentId: "env-1", |
| 16 | + provider: SourceControlProviderKind.make("github"), |
| 17 | + host: "github.com", |
| 18 | + projectId: "project-1", |
| 19 | + projectTitle: "t3code", |
| 20 | + repository: "pingdotgg/t3code", |
| 21 | + title: "Add the pull requests page", |
| 22 | + url: "https://github.com/pingdotgg/t3code/pull/7", |
| 23 | + author: { login: "octocat", name: null, avatarUrl: null }, |
| 24 | + headBranch: "feat/branch-7", |
| 25 | + baseBranch: "main", |
| 26 | + state: "open", |
| 27 | + isDraft: false, |
| 28 | + mergeability: "mergeable", |
| 29 | + additions: 0, |
| 30 | + deletions: 0, |
| 31 | + createdAt: "2026-07-01T00:00:00Z", |
| 32 | + updatedAt: "2026-07-02T00:00:00Z", |
| 33 | + viewerReviewRequested: false, |
| 34 | + number: 7, |
| 35 | + labels: [], |
| 36 | +} as unknown as EnvironmentPullRequestEntry; |
| 37 | + |
| 38 | +it("keeps a row's intent while either the pointer or focus is still on it", async () => { |
| 39 | + const onIntent = vi.fn(); |
| 40 | + await using screen = await render( |
| 41 | + <PullRequestRow |
| 42 | + entry={entry} |
| 43 | + selected={false} |
| 44 | + showProjectTitle |
| 45 | + showProvider={false} |
| 46 | + onSelect={() => undefined} |
| 47 | + onIntent={onIntent} |
| 48 | + hostActions={new Set()} |
| 49 | + onActed={() => undefined} |
| 50 | + />, |
| 51 | + ); |
| 52 | + const row = screen.getByRole("button", { name: /Add the pull requests page/ }); |
| 53 | + |
| 54 | + await act(() => (row.element() as HTMLElement).focus()); |
| 55 | + await userEvent.hover(row); |
| 56 | + await userEvent.unhover(row); |
| 57 | + expect(onIntent).toHaveBeenLastCalledWith(entry); |
| 58 | + |
| 59 | + await userEvent.hover(row); |
| 60 | + await act(() => (row.element() as HTMLElement).blur()); |
| 61 | + expect(onIntent).toHaveBeenLastCalledWith(entry); |
| 62 | + |
| 63 | + await userEvent.unhover(row); |
| 64 | + expect(onIntent).toHaveBeenLastCalledWith(null); |
| 65 | +}); |
0 commit comments