Files
radicle-desktop/tests/unit/commentResolutions.test.ts
Rūdolfs Ošiņš 56e495ba8d Add unit tests for patch review logic and draft storage
Code review is the app's core workflow and had almost no coverage. A
mutation run checked that each test fails when the logic it covers breaks.
2026-10-01 18:20:24 +02:00

72 lines
2.0 KiB
TypeScript

import { describe, expect, test } from "vitest";
import { resolutionsByComment } from "@app/lib/commentResolutions";
import { author, operation } from "./support/cobs";
const alice = author("alice");
const bob = author("bob");
function resolve(comment: string) {
return { type: "review.comment.resolve" as const, review: "r", comment };
}
function unresolve(comment: string) {
return { type: "review.comment.unresolve" as const, review: "r", comment };
}
describe("resolutionsByComment", () => {
test("records who resolved a comment and when", () => {
const resolutions = resolutionsByComment([
operation(alice, 10, [resolve("c1")]),
]);
expect(resolutions.get("c1")).toEqual({ author: alice, timestamp: 10 });
});
test("the latest resolve wins", () => {
const resolutions = resolutionsByComment([
operation(alice, 10, [resolve("c1")]),
operation(bob, 20, [resolve("c1")]),
]);
expect(resolutions.get("c1")).toEqual({ author: bob, timestamp: 20 });
});
test("replays operations in timestamp order, not array order", () => {
const resolutions = resolutionsByComment([
operation(bob, 20, [unresolve("c1")]),
operation(alice, 10, [resolve("c1")]),
]);
expect(resolutions.has("c1")).toBe(false);
});
test("unresolving drops the entry", () => {
const resolutions = resolutionsByComment([
operation(alice, 10, [resolve("c1"), resolve("c2")]),
operation(bob, 20, [unresolve("c1")]),
]);
expect([...resolutions.keys()]).toEqual(["c2"]);
});
test("ignores other actions", () => {
const resolutions = resolutionsByComment([
operation(alice, 10, [{ type: "label", labels: ["bug"] }]),
]);
expect(resolutions.size).toBe(0);
});
test("does not reorder the caller's array", () => {
const activity = [
operation(bob, 20, [resolve("c1")]),
operation(alice, 10, [resolve("c2")]),
];
resolutionsByComment(activity);
expect(activity.map(op => op.timestamp)).toEqual([20, 10]);
});
});