diff --git a/apps/web/src/components/pullRequest/PullRequestCodeTab.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestCodeTab.browser.test.tsx index d18a551b892ad..923019913617a 100644 --- a/apps/web/src/components/pullRequest/PullRequestCodeTab.browser.test.tsx +++ b/apps/web/src/components/pullRequest/PullRequestCodeTab.browser.test.tsx @@ -74,12 +74,18 @@ const { diffAtom, testFileDiffAtom, pagedDiffAtom } = await vi.hoisted(async () }; }); +const { allowed, denied } = await vi.hoisted(async () => { + const { Atom } = await import("effect/reactivity"); + return { allowed: Atom.make(true), denied: Atom.make(false) }; +}); + const mocks = vi.hoisted(() => ({ paged: false, shortPages: false, withTestFile: false, refreshed: false, diffCommits: [] as Array, + canMarkViewed: true, viewedPaths: null as ReadonlySet | null, viewedListeners: new Set<() => void>(), })); @@ -130,6 +136,10 @@ vi.mock(import("~/state/pullRequests"), async (original) => { if (mocks.paged) return pagedDiffAtom(mocks.shortPages)(input.cursor ?? "first"); return mocks.withTestFile ? testFileDiffAtom : diffAtom; }) as never, + setFilesViewed: { + ...actual.pullRequestEnvironment.setFilesViewed, + permissionAtom: () => (mocks.canMarkViewed ? allowed : denied), + }, }, }; }); @@ -189,7 +199,7 @@ const detail: PullRequestDetailView = { }, }; -function setup({ paged }: { paged: boolean }) { +function setup({ paged, canMarkViewed = true }: { paged: boolean; canMarkViewed?: boolean }) { window.localStorage.removeItem("t3code.diffHideTestFiles"); __setClientSettingsForTests(DEFAULT_CLIENT_SETTINGS); mocks.paged = paged; @@ -197,6 +207,7 @@ function setup({ paged }: { paged: boolean }) { mocks.withTestFile = false; mocks.refreshed = false; mocks.diffCommits = []; + mocks.canMarkViewed = canMarkViewed; mocks.viewedPaths = null; mocks.viewedListeners.clear(); } @@ -206,10 +217,12 @@ const tab = ( revealRequest: { readonly path: string; readonly nonce: number } | null = null, revealUrl?: string, onRevealSettled?: (url: string) => void, + environmentConnected = true, ) => ( {}} environmentId={EnvironmentId.make("environment")} + environmentConnected={environmentConnected} reference={detail} detail={detail} selectedCommitOid={null} @@ -468,6 +481,7 @@ it("never requests the diff of a selected commit the pull request no longer has" {}} environmentId={EnvironmentId.make("environment")} + environmentConnected reference={detail} detail={{ ...detail, @@ -493,6 +507,30 @@ it("never requests the diff of a selected commit the pull request no longer has" expect(mocks.diffCommits).not.toContain("gone"); }); +it("disables the Viewed checkbox on a connection that cannot mark files viewed", async () => { + setup({ paged: false, canMarkViewed: false }); + mocks.viewedPaths = new Set(); + const container = document.createElement("div"); + container.className = "flex h-[700px] w-[900px]"; + await using screen = await render(tab(0), { container }); + + await expect.element(screen.getByRole("checkbox", { name: "Viewed" })).toBeDisabled(); +}); + +it("disables the Viewed checkbox while the environment is disconnected, then enables it on reconnect", async () => { + setup({ paged: false }); + mocks.viewedPaths = new Set(); + const container = document.createElement("div"); + container.className = "flex h-[700px] w-[900px]"; + await using screen = await render(tab(0, null, undefined, undefined, false), { container }); + + await expect.element(screen.getByRole("checkbox", { name: "Viewed" })).toBeDisabled(); + + await screen.rerender(tab(0, null, undefined, undefined, true)); + + await expect.element(screen.getByRole("checkbox", { name: "Viewed" })).toBeEnabled(); +}); + it("answers a commit's diff link only once that commit's diff is shown", async () => { setup({ paged: false }); const container = document.createElement("div"); @@ -508,6 +546,7 @@ it("answers a commit's diff link only once that commit's diff is shown", async ( {}} environmentId={EnvironmentId.make("environment")} + environmentConnected reference={detail} detail={withCommit} selectedCommitOid={selectedCommitOid} @@ -547,6 +586,7 @@ it("hides a resolved conversation behind avatars on its line until they are clic {}} environmentId={EnvironmentId.make("environment")} + environmentConnected reference={detail} detail={{ ...detail, @@ -636,6 +676,7 @@ it("keeps an unsent reply when the appearance switches between light and dark", {}} environmentId={EnvironmentId.make("environment")} + environmentConnected reference={detail} detail={{ ...detail, diff --git a/apps/web/src/components/pullRequest/PullRequestCodeTab.tsx b/apps/web/src/components/pullRequest/PullRequestCodeTab.tsx index c847e55738405..cb11f14bf7d9f 100644 --- a/apps/web/src/components/pullRequest/PullRequestCodeTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestCodeTab.tsx @@ -304,6 +304,7 @@ function reviewThreadsByPath(threads: ReadonlyArray) { interface FileViewedToggleState { readonly enabled: boolean; + readonly canMarkViewed: boolean; readonly isViewed: (path: string) => boolean; readonly isStale: (path: string) => boolean; readonly setFileViewed: (fileKey: string, viewed: boolean, extendRange: boolean) => void; @@ -331,7 +332,7 @@ function FileViewedToggle({ {stat}