12ed7123ab
* fix: support markdown preview comments * fix: address markdown preview review feedback * fix: address markdown preview comment scope * fix: address markdown preview follow-up feedback * fix: preserve markdown preview run action in file tabs * fix: ignore svg clicks in markdown preview controls * fix: ignore svg markdown preview selection targets
62 lines
2.0 KiB
TypeScript
62 lines
2.0 KiB
TypeScript
import { act, renderHook } from "@testing-library/react";
|
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
import { useCommentsStore, type DiffComment } from "@/lib/state/slices/comments";
|
|
import { useDiffFileComments } from "./use-diff-comments";
|
|
|
|
const SESSION_ID = "session-1";
|
|
const FILE_PATH = "README.md";
|
|
|
|
function diffComment(overrides: Partial<DiffComment>): DiffComment {
|
|
return {
|
|
id: "comment-" + Math.random().toString(36).slice(2),
|
|
sessionId: SESSION_ID,
|
|
source: "diff",
|
|
text: "tighten this",
|
|
filePath: FILE_PATH,
|
|
startLine: 1,
|
|
endLine: 1,
|
|
side: "additions",
|
|
codeContent: "hello",
|
|
createdAt: new Date().toISOString(),
|
|
status: "pending",
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("useDiffFileComments", () => {
|
|
beforeEach(() => {
|
|
sessionStorage.clear();
|
|
useCommentsStore.setState({
|
|
byId: {},
|
|
bySession: {},
|
|
pendingForChat: [],
|
|
editingCommentId: null,
|
|
});
|
|
});
|
|
|
|
it("filters comments by repositoryId when one is provided", () => {
|
|
act(() => {
|
|
const store = useCommentsStore.getState();
|
|
store.addComment(diffComment({ id: "repo-a", repositoryId: "repo-a" }));
|
|
store.addComment(diffComment({ id: "repo-b", repositoryId: "repo-b" }));
|
|
store.addComment(diffComment({ id: "legacy" }));
|
|
});
|
|
|
|
const { result } = renderHook(() => useDiffFileComments(SESSION_ID, FILE_PATH, "repo-a"));
|
|
|
|
expect(result.current.map((comment) => comment.id)).toEqual(["repo-a", "legacy"]);
|
|
});
|
|
|
|
it("preserves legacy unscoped reads when repositoryId is omitted", () => {
|
|
act(() => {
|
|
const store = useCommentsStore.getState();
|
|
store.addComment(diffComment({ id: "repo-a", repositoryId: "repo-a" }));
|
|
store.addComment(diffComment({ id: "repo-b", repositoryId: "repo-b" }));
|
|
});
|
|
|
|
const { result } = renderHook(() => useDiffFileComments(SESSION_ID, FILE_PATH));
|
|
|
|
expect(result.current.map((comment) => comment.id)).toEqual(["repo-a", "repo-b"]);
|
|
});
|
|
});
|