Changesets · Branches · Tags · Compare
| Changeset | f636b4841cdd1439315e2c1b550a0d3bc0c72a010bf238c62bff346719ab2310 |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-09-25 15:46 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-09-25 15:46 -07:00 |
| Parents | 3ff29c567dd0, ddc2c7a0c5a7 |
2 files changed
added extensions/cli/src/ui/components/ChecklistDisplay.test.tsx +63 −0
| @@ -0,0 +1,63 @@ | ||
| 1 | +import { render } from "ink-testing-library"; | |
| 2 | +import React from "react"; | |
| 3 | + | |
| 4 | +import { ChecklistDisplay } from "./ChecklistDisplay.js"; | |
| 5 | + | |
| 6 | +describe("ChecklistDisplay", () => { | |
| 7 | + it("should highlight the first incomplete item", () => { | |
| 8 | + const content = `Task list status: | |
| 9 | +- [x] Completed task | |
| 10 | +- [ ] First incomplete task | |
| 11 | +- [ ] Second incomplete task`; | |
| 12 | + | |
| 13 | + const { lastFrame } = render(<ChecklistDisplay content={content} />); | |
| 14 | + const output = lastFrame(); | |
| 15 | + | |
| 16 | + // The output should contain the checkbox symbols and text | |
| 17 | + expect(output).toContain("✓"); | |
| 18 | + expect(output).toContain("○"); | |
| 19 | + expect(output).toContain("Completed task"); | |
| 20 | + expect(output).toContain("First incomplete task"); | |
| 21 | + expect(output).toContain("Second incomplete task"); | |
| 22 | + }); | |
| 23 | + | |
| 24 | + it("should handle empty checklist", () => { | |
| 25 | + const content = "Task list status:"; | |
| 26 | + | |
| 27 | + const { lastFrame } = render(<ChecklistDisplay content={content} />); | |
| 28 | + const output = lastFrame(); | |
| 29 | + | |
| 30 | + expect(output).toBeDefined(); | |
| 31 | + }); | |
| 32 | + | |
| 33 | + it("should handle all completed tasks", () => { | |
| 34 | + const content = `Task list status: | |
| 35 | +- [x] Completed task 1 | |
| 36 | +- [x] Completed task 2`; | |
| 37 | + | |
| 38 | + const { lastFrame } = render(<ChecklistDisplay content={content} />); | |
| 39 | + const output = lastFrame(); | |
| 40 | + | |
| 41 | + expect(output).toContain("✓"); | |
| 42 | + expect(output).toContain("Completed task 1"); | |
| 43 | + expect(output).toContain("Completed task 2"); | |
| 44 | + }); | |
| 45 | + | |
| 46 | + it("should handle mixed content with headers", () => { | |
| 47 | + const content = `Task list status: | |
| 48 | +## Important Tasks | |
| 49 | +- [x] Done task | |
| 50 | +- [ ] Todo task | |
| 51 | + | |
| 52 | +## Other Tasks | |
| 53 | +- [ ] Another todo`; | |
| 54 | + | |
| 55 | + const { lastFrame } = render(<ChecklistDisplay content={content} />); | |
| 56 | + const output = lastFrame(); | |
| 57 | + | |
| 58 | + expect(output).toContain("Important Tasks"); | |
| 59 | + expect(output).toContain("Other Tasks"); | |
| 60 | + expect(output).toContain("✓"); | |
| 61 | + expect(output).toContain("○"); | |
| 62 | + }); | |
| 63 | +}); |
modified extensions/cli/src/ui/components/ChecklistDisplay.tsx +16 −1
| @@ -13,6 +13,17 @@ | ||
| 13 | 13 | }) => { |
| 14 | 14 | const lines = content.split("\n"); |
| 15 | 15 | |
| 16 | + // Find the index of the first incomplete checkbox item | |
| 17 | + let firstIncompleteIndex = -1; | |
| 18 | + for (let i = 0; i < lines.length; i++) { | |
| 19 | + const line = lines[i]; | |
| 20 | + const checkboxMatch = line.match(/^(\s*)-\s*\[([ x])\]\s*(.*)$/); | |
| 21 | + if (checkboxMatch && checkboxMatch[2] === " ") { | |
| 22 | + firstIncompleteIndex = i; | |
| 23 | + break; | |
| 24 | + } | |
| 25 | + } | |
| 26 | + | |
| 16 | 27 | return ( |
| 17 | 28 | <Box flexDirection="column" paddingLeft={2}> |
| 18 | 29 | {lines.map((line, index) => { |
| @@ -25,6 +36,7 @@ | ||
| 25 | 36 | if (checkboxMatch) { |
| 26 | 37 | const [, indent, status, taskText] = checkboxMatch; |
| 27 | 38 | const isCompleted = status === "x"; |
| 39 | + const isFirstIncomplete = index === firstIncompleteIndex; | |
| 28 | 40 | |
| 29 | 41 | return ( |
| 30 | 42 | <Box key={index}> |
| @@ -34,8 +46,11 @@ | ||
| 34 | 46 | </Text> |
| 35 | 47 | <Text> </Text> |
| 36 | 48 | <Text |
| 37 | - color={isCompleted ? "gray" : "white"} | |
| 49 | + color={ | |
| 50 | + isCompleted ? "gray" : isFirstIncomplete ? "cyan" : "white" | |
| 51 | + } | |
| 38 | 52 | strikethrough={isCompleted} |
| 53 | + bold={isFirstIncomplete} | |
| 39 | 54 | > |
| 40 | 55 | {taskText} |
| 41 | 56 | </Text> |