Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ui/taskCardProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
45 changes: 43 additions & 2 deletions tests/unit/issues/issue-1576-display-progress-bar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
],
});
Expand All @@ -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");
});
});