mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-16 02:40:39 +09:00
test: extract buildIssueTree utility and add tests for hierarchy logic
Extract the inline tree-building logic from IssuesList into a pure `buildIssueTree` function in lib/issue-tree.ts so it can be unit tested. Add six tests covering: flat lists, parent-child grouping, multi-level nesting, orphaned sub-tasks promoted to root, empty input, and list order preservation. Add two tests to IssueRow.test.tsx covering the new titleSuffix prop: renders inline after the title when provided, and renders cleanly when omitted. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
b380d6000f
commit
9be1b3f8a9
4 changed files with 165 additions and 10 deletions
27
ui/src/lib/issue-tree.ts
Normal file
27
ui/src/lib/issue-tree.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import type { Issue } from "@paperclipai/shared";
|
||||
|
||||
export interface IssueTree {
|
||||
roots: Issue[];
|
||||
childMap: Map<string, Issue[]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a parent→children tree from a flat list of issues.
|
||||
*
|
||||
* - `roots` contains issues whose parent is absent from the list (or have no
|
||||
* parent at all), so orphaned sub-tasks are always visible at root level.
|
||||
* - `childMap` maps each parent id to its direct children in list order.
|
||||
*/
|
||||
export function buildIssueTree(items: Issue[]): IssueTree {
|
||||
const itemIds = new Set(items.map((i) => i.id));
|
||||
const roots = items.filter((i) => !i.parentId || !itemIds.has(i.parentId));
|
||||
const childMap = new Map<string, Issue[]>();
|
||||
for (const item of items) {
|
||||
if (item.parentId && itemIds.has(item.parentId)) {
|
||||
const arr = childMap.get(item.parentId) ?? [];
|
||||
arr.push(item);
|
||||
childMap.set(item.parentId, arr);
|
||||
}
|
||||
}
|
||||
return { roots, childMap };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue