diff --git a/src/ui/taskCardProperties.ts b/src/ui/taskCardProperties.ts index 9a1c5bedc..cc2ee9f7a 100644 --- a/src/ui/taskCardProperties.ts +++ b/src/ui/taskCardProperties.ts @@ -222,8 +222,11 @@ function calculateChecklistProgress(cache: unknown): ChecklistProgress | null { const isNested = typeof item.parent === "number" && item.parent >= 0; if (isNested) continue; + const marker = item.task.toLowerCase(); + if (marker === "-") continue; // cancelled — excluded from progress count + total += 1; - if (item.task.toLowerCase() === "x") { + if (marker === "x") { completed += 1; } } diff --git a/tests/unit/issues/issue-1576-display-progress-bar.test.ts b/tests/unit/issues/issue-1576-display-progress-bar.test.ts index abc3124fd..0d189b00b 100644 --- a/tests/unit/issues/issue-1576-display-progress-bar.test.ts +++ b/tests/unit/issues/issue-1576-display-progress-bar.test.ts @@ -199,7 +199,7 @@ describe("Issue #1576 - Display Progress Bar on task cards", () => { expect((card.querySelector(".task-card__progress-fill") as HTMLElement).style.width).toBe("100%"); }); - it("treats non-x task markers as incomplete", () => { + it("treats non-x, non-dash task markers as incomplete", () => { const task = TaskFactory.createTask({ path: "tasks/custom-marker-task.md", title: "Custom marker", @@ -209,7 +209,7 @@ describe("Issue #1576 - Display Progress Bar on task cards", () => { app.metadataCache.setCache(task.path, { frontmatter: { title: task.title }, listItems: [ - listItem("-", -1, 10), // not completed + listItem("/", -1, 10), // not completed listItem("x", -1, 11), // completed ], }); @@ -218,4 +218,45 @@ describe("Issue #1576 - Display Progress Bar on task cards", () => { expect(card.querySelector(".task-card__progress-label")?.textContent).toBe("1/2"); expect((card.querySelector(".task-card__progress-fill") as HTMLElement).style.width).toBe("50%"); }); + + it("excludes cancelled (- [-]) items from both numerator and denominator", () => { + const task = TaskFactory.createTask({ + path: "tasks/cancelled-marker-task.md", + title: "Cancelled marker", + }); + + MockObsidian.createTestFile(task.path, "# Cancelled marker"); + app.metadataCache.setCache(task.path, { + frontmatter: { title: task.title }, + listItems: [ + listItem("-", -1, 10), // cancelled — excluded entirely + listItem("x", -1, 11), // completed + ], + }); + + const card = createTaskCard(task, plugin, ["checklistProgress"]); + expect(card.querySelector(".task-card__progress-label")?.textContent).toBe("1/1"); + expect((card.querySelector(".task-card__progress-fill") as HTMLElement).style.width).toBe("100%"); + }); + + it("does not render checklist progress when only cancelled checkboxes exist", () => { + const task = TaskFactory.createTask({ + path: "tasks/all-cancelled-task.md", + title: "All cancelled", + }); + + MockObsidian.createTestFile(task.path, "# All cancelled"); + app.metadataCache.setCache(task.path, { + frontmatter: { title: task.title }, + listItems: [ + listItem("-", -1, 10), + listItem("-", -1, 11), + ], + }); + + const card = createTaskCard(task, plugin, ["checklistProgress"]); + expect(card.querySelector(".task-card__progress")).toBeNull(); + const metadata = card.querySelector(".task-card__metadata") as HTMLElement; + expect(metadata.style.display).toBe("none"); + }); });