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