1import type { PullRequestFilesViewedResult } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3import { viewedOverlay } from "./pullRequestFilesViewed";
4
5// The overlay compares reads by identity, so each call is a distinct read.
6const read = (): PullRequestFilesViewedResult => ({ files: [], truncated: false });
7
8describe("viewedOverlay", () => {
9 it("keeps a press while its write is in flight", () => {
10 const before = read();
11 expect(
12 viewedOverlay({ "a.ts": { viewed: true, version: 1, awaitingReadAfter: undefined } }, before),
13 ).toEqual({ "a.ts": true });
14 });
15
16 it("keeps a landed press until a read newer than the one current at the write", () => {
17 const before = read();
18 const presses = {
19 "a.ts": { viewed: true, version: 1, awaitingReadAfter: { read: before } },
20 };
21 expect(viewedOverlay(presses, before)).toEqual({ "a.ts": true });
22 expect(viewedOverlay(presses, read())).toEqual({});
23 });
24});