mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-10-17 04:37:03 +00:00
fix(web): show deleted Markdown files as diffs
This commit is contained in:
parent
3b1781022f
commit
e87e0df84d
2 changed files with 17 additions and 0 deletions
|
|
@ -258,6 +258,22 @@ describe("RunFiles rendering", () => {
|
|||
expect(multiFileDiffCalls).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("shows deleted Markdown files as a diff instead of an empty preview", () => {
|
||||
currentFilesPayload = makePayload(1);
|
||||
currentFilesPayload.data[0] = {
|
||||
change_kind: "deleted",
|
||||
old_file: { name: "docs/plan.md", contents: "# Plan\n\nReview this\n" },
|
||||
new_file: { name: "", contents: "" },
|
||||
};
|
||||
|
||||
const renderer = renderRunFiles();
|
||||
|
||||
expect(renderer.root.findAllByProps({ "data-markdown-preview": "true" })).toHaveLength(0);
|
||||
expect(multiFileDiffCalls).toHaveLength(1);
|
||||
expect(multiFileDiffCalls[0].oldFile.contents).toBe("# Plan\n\nReview this\n");
|
||||
expect(multiFileDiffCalls[0].newFile.contents).toBe("");
|
||||
});
|
||||
|
||||
test("passes the selected URL scope to useRunFiles", () => {
|
||||
currentFilesPayload = makePayload(1);
|
||||
|
||||
|
|
|
|||
|
|
@ -255,6 +255,7 @@ const RunFileRow = memo(function RunFileRow({
|
|||
const oldPath = file.old_file.name || display;
|
||||
const newPath = file.new_file.name || display;
|
||||
const canPreviewMarkdown =
|
||||
file.change_kind !== "deleted" &&
|
||||
/\.md$/i.test(newPath) && newContents != null && !placeholder;
|
||||
const [showMarkdownPreview, setShowMarkdownPreview] =
|
||||
useState(canPreviewMarkdown);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue