Skip to content

Support nested if-branches and add comprehensive unit tests - #2

Merged
kongyo2 merged 2 commits into
mainfrom
claude/kawaii-deco-note-upstream-tjpml9
Jul 22, 2026
Merged

Support nested if-branches and add comprehensive unit tests#2
kongyo2 merged 2 commits into
mainfrom
claude/kawaii-deco-note-upstream-tjpml9

Conversation

@kongyo2

@kongyo2 kongyo2 commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Summary

This PR adds support for nested if-branches in flowchart steps, allowing if-cards to be placed inside other if-branches. It also introduces comprehensive unit tests for the model layer with 100% code coverage.

Key Changes

Nested If-Branches Support

  • Unified step type system: Removed BranchStep type; branches now contain full Step objects (either NormalStep or IfStep), enabling arbitrary nesting
  • Tree traversal helpers: Added updateStepInTree(), removeStepFromTree(), findStepInTree(), and appendToBranch() functions to handle recursive operations on nested step structures
  • Recursive normalization: Updated normalizeStep() to recursively normalize steps within branches, supporting both old format (type-less branch steps) and new nested if-cards
  • UI updates: Modified IfCard component to render nested if-cards within branches with proper depth-based styling; added "+🔀if" button to add nested if-branches alongside regular steps

State Management

  • Updated useNotebooks store to use tree traversal helpers for all step mutations (setStepText, toggleStep, deleteStep, setBranchLabel)
  • Added addBranchIfStep() action to create nested if-branches
  • Removed branch-specific mutation actions (setBranchStepText, toggleBranchStep, deleteBranchStep) in favor of unified tree operations

Testing Infrastructure

  • Added vitest.config.ts with 100% coverage thresholds for src/lib/model.ts and src/lib/format.ts
  • Created src/lib/model.test.ts with 638 lines of comprehensive tests covering:
    • Factory functions (newStep, newIfStep, newPage, newNotebook)
    • Tree operations (update, remove, find, append)
    • State normalization with nested structures and deduplication
    • Edge cases (invalid IDs, missing references, malformed data)
  • Created src/lib/format.test.ts with tests for utility functions
  • Added test and test:watch npm scripts; integrated Vitest into CI pipeline

Version & Documentation

  • Bumped version to 0.2.0
  • Updated README to clarify if-branch capabilities
  • Added coverage directory to .gitignore

Implementation Details

  • Tree operations use immutable patterns (spreading objects/arrays) to maintain referential integrity
  • seedUid() now recursively scans both yes and no branches to find the maximum ID number
  • Normalization deduplicates IDs across all nested structures (steps, stickers, shapes, photos, arrows)
  • Nested if-cards render with visual depth indicators (different styles for depth 0, 1, 2+)
  • Move buttons (▲▼) only appear on top-level steps; nested steps can only be deleted

https://claude.ai/code/session_01SRfSVMnqmMKh8JSMEsKpM9

…0.2.0

Upstream pppzet/KawaiiDecoNote's "ネストの機能更新" makes if-branches
nestable: a branch can now hold nested if-cards recursively, not just
plain steps. Port that into the React Native app.

- types: IfStep.branches now holds Step[] (recursive) instead of a
  separate BranchStep[]; the BranchStep type is removed.
- model: normalizeStep / seedUid / dedupeIds recurse through nested
  branches; add pure tree helpers updateStepInTree / removeStepFromTree
  / findStepInTree / appendToBranch. Old branch steps ({id,text,done})
  migrate to type:"step" automatically on load.
- store: step text/toggle/delete operate on the whole tree by id;
  addBranchStep plus new addBranchIfStep append into a branch; the old
  branch-specific actions are dropped.
- IfCard: recursive IfCardNode renders nested branches with depth-based
  colours, vertical branch stacking, and +工程 / +🔀if add buttons.

Testing:
- add vitest + @vitest/coverage-v8, vitest.config.ts, and test scripts.
- model.test.ts / format.test.ts: 59 tests at 100% coverage of the pure
  logic (statements/branches/functions/lines), enforced via thresholds.
- wire `npm run test:coverage` into CI.

Version bumped to 0.2.0 (app.json versionCode 2).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SRfSVMnqmMKh8JSMEsKpM9
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kongyo2, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: QUIET

Plan: Pro Plus

Run ID: 8a27f208-e5ac-49ca-bf69-6e3f696d646b

📥 Commits

Reviewing files that changed from the base of the PR and between b5d14a5 and aaaefb5.

📒 Files selected for processing (4)
  • src/components/flowchart/IfCard.tsx
  • src/lib/model.ts
  • src/lib/types.ts
  • src/state/notebooks.ts
📝 Walkthrough

Walkthrough

The PR adds recursive if branching across the step model, notebook state, and flowchart UI. It also adds Vitest coverage and CI execution, updates coverage ignores and configuration, documents nested branching, and bumps application versions.

Changes

Recursive branching and validation

Layer / File(s) Summary
Recursive step model and normalization
src/lib/types.ts, src/lib/model.ts
IfStep branches now contain recursive Step[] nodes. Tree update, removal, search, append, ID scanning, normalization, and deduplication operate recursively.
Notebook mutations and nested card rendering
src/state/notebooks.ts, src/components/flowchart/IfCard.tsx
Notebook actions use recursive tree helpers, while flowchart cards render nested if nodes with depth-aware styling and branch insertion controls.
Model and formatting test coverage
src/lib/model.test.ts, src/lib/format.test.ts
Vitest tests cover recursive tree operations, normalization, ID handling, factories, display fallbacks, and formatting utilities.
Vitest configuration and CI execution
package.json, vitest.config.ts, .gitignore, .github/workflows/ci.yml
Vitest scripts, V8 coverage thresholds, ignored coverage output, and CI coverage execution are added.
Application metadata and feature documentation
app.json, README.md
Application versions are bumped and nested if branching is documented.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant IfCardNode
  participant NotebooksState
  participant ModelTreeHelpers
  IfCardNode->>NotebooksState: edit or add nested branch step
  NotebooksState->>ModelTreeHelpers: update or append by step id
  ModelTreeHelpers-->>NotebooksState: updated recursive step tree
  NotebooksState-->>IfCardNode: render updated nested card
Loading
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: nested if-branch support and new unit tests.
Description check ✅ Passed The description is directly related to the changeset and accurately describes the nested branching and testing updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: QUIET

Plan: Pro Plus

Run ID: 195e502e-c892-43c2-8854-212a5a8717fa

📥 Commits

Reviewing files that changed from the base of the PR and between fd71140 and b5d14a5.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (12)
  • .github/workflows/ci.yml
  • .gitignore
  • README.md
  • app.json
  • package.json
  • src/components/flowchart/IfCard.tsx
  • src/lib/format.test.ts
  • src/lib/model.test.ts
  • src/lib/model.ts
  • src/lib/types.ts
  • src/state/notebooks.ts
  • vitest.config.ts

Comment thread src/components/flowchart/IfCard.tsx Outdated
Address PR #2 review: BranchKey ("yes" | "no") was redefined in three
files (model.ts, notebooks.ts, IfCard.tsx). Export it once from
src/lib/types.ts and import it everywhere so the branch-key contract
can't drift out of sync.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SRfSVMnqmMKh8JSMEsKpM9
@kongyo2
kongyo2 merged commit fefc1a8 into main Jul 22, 2026
5 checks passed
@kongyo2
kongyo2 deleted the claude/kawaii-deco-note-upstream-tjpml9 branch July 22, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants