The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { |
| 4 | isFileViewed, |
| 5 | isStaleViewedState, |
| 6 | revertFileViewedOverlay, |
| 7 | settleFileViewedOverlay, |
| 8 | toFileViewedStates, |
| 9 | type FileViewedOverlay, |
| 10 | } from "./pullRequestFilesViewed.logic"; |
| 11 | |
| 12 | const NO_OVERLAY: FileViewedOverlay = new Map(); |
| 13 | const NOTHING_PENDING: ReadonlySet<string> = new Set(); |
| 14 | const NOTHING_ANSWERED: ReadonlySet<string> = new Set(); |
| 15 | |
| 16 | const states = toFileViewedStates({ |
| 17 | files: [ |
| 18 | { path: "a.ts", state: "viewed" }, |
| 19 | { path: "b.ts", state: "unviewed" }, |
| 20 | { path: "c.ts", state: "dismissed" }, |
| 21 | ], |
| 22 | truncated: false, |
| 23 | }); |
| 24 | |
| 25 | describe("isFileViewed", () => { |
| 26 | it("reads a file pushed to since it was cleared as unread", () => { |
| 27 | expect(isFileViewed("c.ts", states, NO_OVERLAY)).toBe(false); |
| 28 | expect(isStaleViewedState(states?.get("c.ts"))).toBe(true); |
| 29 | expect(isStaleViewedState(states?.get("a.ts"))).toBe(false); |
| 30 | }); |
| 31 | |
| 32 | it("shows the press ahead of the host's answer", () => { |
| 33 | expect(isFileViewed("b.ts", states, new Map([["b.ts", true]]))).toBe(true); |
| 34 | expect(isFileViewed("a.ts", states, new Map([["a.ts", false]]))).toBe(false); |
| 35 | }); |
| 36 | }); |
| 37 | |
| 38 | describe("settleFileViewedOverlay", () => { |
| 39 | it("drops a press the host has caught up on", () => { |
| 40 | const settled = settleFileViewedOverlay( |
| 41 | new Map([["a.ts", true]]), |
| 42 | states, |
| 43 | NOTHING_PENDING, |
| 44 | NOTHING_ANSWERED, |
| 45 | ); |
| 46 | expect(settled.size).toBe(0); |
| 47 | }); |
| 48 | |
| 49 | it("keeps a press the host cannot have heard yet", () => { |
| 50 | const overlay = new Map([["a.ts", false]]); |
| 51 | const settled = settleFileViewedOverlay(overlay, states, new Set(["a.ts"]), NOTHING_ANSWERED); |
| 52 | expect(settled.get("a.ts")).toBe(false); |
| 53 | }); |
| 54 | |
| 55 | it("settles a file pushed to since it was cleared against un-ticking it", () => { |
| 56 | const settled = settleFileViewedOverlay( |
| 57 | new Map([["c.ts", false]]), |
| 58 | states, |
| 59 | NOTHING_PENDING, |
| 60 | NOTHING_ANSWERED, |
| 61 | ); |
| 62 | expect(settled.size).toBe(0); |
| 63 | }); |
| 64 | |
| 65 | it("drops a tick once a read has answered for it, against what the reader pressed", () => { |
| 66 | const settled = settleFileViewedOverlay( |
| 67 | new Map([["c.ts", true]]), |
| 68 | states, |
| 69 | NOTHING_PENDING, |
| 70 | new Set(["c.ts"]), |
| 71 | ); |
| 72 | expect(settled.size).toBe(0); |
| 73 | expect(isFileViewed("c.ts", states, settled)).toBe(false); |
| 74 | expect(isStaleViewedState(states?.get("c.ts"))).toBe(true); |
| 75 | }); |
| 76 | |
| 77 | it("holds a press made since the read that would otherwise answer for it", () => { |
| 78 | const overlay = new Map([["c.ts", true]]); |
| 79 | const settled = settleFileViewedOverlay(overlay, states, new Set(["c.ts"]), new Set(["c.ts"])); |
| 80 | expect(settled.get("c.ts")).toBe(true); |
| 81 | }); |
| 82 | }); |
| 83 | |
| 84 | describe("revertFileViewedOverlay", () => { |
| 85 | const batch = [ |
| 86 | { path: "a.ts", viewed: true }, |
| 87 | { path: "b.ts", viewed: false }, |
| 88 | ]; |
| 89 | const both = new Set(["a.ts", "b.ts"]); |
| 90 | |
| 91 | it("puts the checkbox back to the host's answer for everything the request answers for", () => { |
| 92 | const overlay = new Map([ |
| 93 | ["a.ts", true], |
| 94 | ["b.ts", false], |
| 95 | ]); |
| 96 | expect(revertFileViewedOverlay(overlay, batch, both).size).toBe(0); |
| 97 | }); |
| 98 | |
| 99 | it("leaves a press the reader made after the request went out", () => { |
| 100 | const overlay = new Map([ |
| 101 | ["a.ts", false], |
| 102 | ["b.ts", false], |
| 103 | ]); |
| 104 | const reverted = revertFileViewedOverlay(overlay, batch, new Set(["b.ts"])); |
| 105 | expect([...reverted]).toEqual([["a.ts", false]]); |
| 106 | }); |
| 107 | |
| 108 | it("leaves a path a later request took over, even pressed the same way", () => { |
| 109 | const overlay = new Map([["a.ts", true]]); |
| 110 | expect(revertFileViewedOverlay(overlay, batch, new Set(["b.ts"]))).toBe(overlay); |
| 111 | }); |
| 112 | }); |