vicky469_aside/tests/sidebarDraftComment.test.ts
vicky469 e94254ee2d feat(publish): add local Pages publishing
Add experimental Cloudflare Pages publishing through local Wrangler, pane-header publish actions, public HTML preview support, artifact safety checks, and state cleanup for rename/delete/unpublish flows.
2026-07-09 15:51:02 +08:00

105 lines
3.4 KiB
TypeScript

import * as assert from "node:assert/strict";
import test from "node:test";
import type { DraftComment } from "../src/domain/drafts";
import {
buildDraftCommentPresentation,
isDraftSaveActionDisabled,
} from "../src/ui/views/sidebarDraftComment";
function createDraft(overrides: Partial<DraftComment> = {}): DraftComment {
return {
id: overrides.id ?? "draft-1",
filePath: overrides.filePath ?? "docs/architecture.md",
startLine: overrides.startLine ?? 9,
startChar: overrides.startChar ?? 2,
endLine: overrides.endLine ?? 9,
endChar: overrides.endChar ?? 11,
selectedText: overrides.selectedText ?? "draft",
selectedTextHash: overrides.selectedTextHash ?? "hash:draft",
comment: overrides.comment ?? "Draft body",
timestamp: overrides.timestamp ?? 100,
anchorKind: overrides.anchorKind ?? "selection",
orphaned: overrides.orphaned ?? false,
mode: overrides.mode ?? "new",
};
}
test("buildDraftCommentPresentation includes draft state classes and add/save label", () => {
const createPresentation = buildDraftCommentPresentation(createDraft({
anchorKind: "page",
mode: "new",
}), "draft-1");
const editPresentation = buildDraftCommentPresentation(createDraft({
id: "draft-2",
orphaned: true,
mode: "edit",
}), null);
assert.deepEqual(createPresentation.classes, [
"aside-comment-item",
"aside-comment-draft",
"is-new",
"page-note",
"active",
]);
assert.equal(createPresentation.saveLabel, "Add");
assert.deepEqual(editPresentation.classes, [
"aside-comment-item",
"aside-comment-draft",
"is-edit",
"orphaned",
]);
assert.equal(editPresentation.saveLabel, "Save");
});
test("buildDraftCommentPresentation keeps append drafts distinct from new drafts", () => {
const appendPresentation = buildDraftCommentPresentation(createDraft({
mode: "append",
}), null);
assert.deepEqual(appendPresentation.classes, [
"aside-comment-item",
"aside-comment-draft",
"is-append",
]);
assert.equal(appendPresentation.saveLabel, "Add");
assert.equal(appendPresentation.placeholder, "Add another entry to this thread.");
});
test("buildDraftCommentPresentation mentions todo and agent directives in new draft placeholder", () => {
const presentation = buildDraftCommentPresentation(createDraft({
mode: "new",
}), null);
assert.equal(
presentation.placeholder,
"Write a side note. Use B or H for styling, or type @todo, @codex, or @claude.",
);
});
test("isDraftSaveActionDisabled allows empty new anchored notes but blocks other empty drafts", () => {
assert.equal(isDraftSaveActionDisabled(createDraft({
anchorKind: "selection",
mode: "new",
}), " "), false);
assert.equal(isDraftSaveActionDisabled(createDraft({
anchorKind: undefined,
mode: "new",
}), " "), false);
assert.equal(isDraftSaveActionDisabled(createDraft({
anchorKind: "page",
mode: "new",
}), " "), true);
assert.equal(isDraftSaveActionDisabled(createDraft({
anchorKind: "selection",
mode: "append",
}), " "), true);
});
test("isDraftSaveActionDisabled blocks over-limit saves", () => {
assert.equal(isDraftSaveActionDisabled(createDraft(), `${"word ".repeat(301)}`), true);
});