Repository navigation
Description
Context
Part of comprehensive test coverage initiative (#208). This phase covers the most critical and interdependent node operations that form the foundation of NodeSpace functionality.
Parent Issue: #208
Depends On: #209 (HTTP dev server infrastructure) - ✅ Assumed complete before starting this
Follows: None (this is Phase 1)
Before You Start - Important Clarifications
Prerequisites (Must Be Complete)
✅ #209 HTTP dev server is complete - Provides:
- HTTP dev server infrastructure running on port 3001
BackendAdapterinterface and implementations- Test database utilities (
createTestDatabase,cleanupTestDatabase,initializeTestDatabase) - Backend adapter auto-detection
Server Setup for Testing
-
Start HTTP dev server (in separate terminal):
bun run dev:server
- Server runs on
http://localhost:3001 - Must stay running during tests
- Provides real Rust backend access
- Server runs on
-
Run tests:
# All tests bun run test # Specific test file bunx vitest src/tests/integration/enter-key-operations.test.ts # Watch mode bunx vitest src/tests/integration/enter-key-operations.test.ts --watch
Test Database Strategy
- One database per test file (suite), not per test case
- Location:
/tmp/test-{suite-name}-{timestamp}.db - Lifecycle:
beforeAll(async () => { // Create once per file dbPath = await createTestDatabase('enter-key-operations'); backend = getBackendAdapter(); await backend.initializeDatabase(dbPath); }); beforeEach(async () => { // Clean between tests, reuse DB await cleanupTestData(dbPath); }); afterAll(async () => { // Delete after all tests in file await cleanupTestDatabase(dbPath); });
Test Utilities (From #209)
Check these exist before starting:
- ✅
src/lib/services/backend-adapter.ts- BackendAdapter interface - ✅
src/tests/utils/test-database.ts- Database utilities ⚠️ src/tests/utils/test-node-builder.ts- Create if missing
TestNodeBuilder example:
export class TestNodeBuilder {
constructor(private backend: BackendAdapter) {}
async createNode(options: {
content: string;
parentId?: string;
beforeSiblingId?: string;
}) {
return await this.backend.createNode({
id: generateId(),
nodeType: 'text',
content: options.content,
parentId: options.parentId,
beforeSiblingId: options.beforeSiblingId,
properties: {}
});
}
async createNodeTree(structure: {
content: string;
children?: NodeTreeStructure[];
collapsed?: boolean;
}) {
// Recursively create node hierarchy
// ...
}
}Visual Order Verification
- Find method in ReactiveNodeService:
getVisibleNodes()or equivalent - Use to verify node ordering in tests
- Test collapsed children separately:
// Collapsed children should NOT be in visible order const visible = await service.getVisibleNodes(rootId); expect(visible.map(n => n.id)).not.toContain(collapsedChildId);
Test Organization & PR Strategy
Recommended: Multiple smaller PRs
- PR 1: Test infrastructure + Section 1 (Enter Key - 10 tests)
- PR 2: Section 2 (Shift+Enter - 11 tests)
- PR 3: Section 3 (Backspace - 9 tests)
- PR 4: Sections 4-5 (Indent/Outdent + Sibling Chain - 21 tests)
Benefits:
- Easier reviews
- Incremental progress visible
- Can merge even if some tests fail
- Faster feedback cycles
TDD Approach - Failures Are OK
Expected: Some tests may fail initially - this is normal!
test('Basic enter creates new node', async () => {
// ... test code
// TODO: Currently failing - cursor position off by 1
// Issue logged, will fix in follow-up PR
expect(cursorPosition).toBe(expectedPosition);
});Document failures:
- Note which tests fail
- Describe expected vs actual behavior
- Create bug fix issues for failed tests
- Continue with other tests
Scope: 51 Test Cases
Section 1: Enter Key (10 cases)
- Basic enter operations (create node after, at beginning, in middle)
- Header preservation and inheritance
- Edge cases (empty nodes, children transfer, character leak prevention)
- Sibling chain updates
Section 2: Shift+Enter (11 cases)
- Basic newline insertion without creating new node
- Inline formatting preservation (bold, italic, code, strikethrough)
- Cursor positioning after split
- Arrow navigation in multiline nodes
Section 3: Backspace (9 cases)
- Basic merging (combine current with previous)
- Cursor positioning at junction point
- Child handling (promotion to parent)
- Sibling chain repairs
Section 4: Indent/Outdent (14 cases)
- Basic indent (make child of previous sibling)
- Basic outdent (move up one level)
- Outdent with sibling transfer (siblings below become children)
- Depth recalculation (recursive updates)
- Edge cases (first child, root node, deep hierarchy)
- Parent validation
Section 5: Sibling Chain Integrity (7 cases)
- Chain maintenance during creation
- Chain repairs during deletion
- Chain updates during movement (indent/outdent)
- Validation (order correctness, no circular refs, no orphans)
Why These Are Combined
These operations are tightly coupled:
- Backspace affects hierarchy - merging nodes can promote children
- Enter updates sibling chains - new nodes must maintain chain integrity
- Indent/outdent changes structure - affects all descendants
- Collapsed children have different logic paths
- Testing in isolation misses critical interaction bugs
Test Organization
packages/desktop-app/src/tests/
├─ integration/
│ ├─ enter-key-operations.test.ts (Section 1: 10 tests)
│ ├─ shift-enter-operations.test.ts (Section 2: 11 tests)
│ ├─ backspace-operations.test.ts (Section 3: 9 tests)
│ └─ indent-outdent-operations.test.ts (Section 4: 14 tests)
└─ services/
└─ sibling-chain-integrity.test.ts (Section 5: 7 tests - expand existing)
Testing Approach
Real Services + Real Database
- Use HTTP adapter to access real Rust backend (Create HTTP dev server for web-mode testing with real database access #209)
- Real database operations (no mocks)
- Separate test database per test suite (
/tmp/test-{timestamp}.db) - Cleanup after each test
Test Structure
Each test verifies:
- In-memory state -
_nodesand_uiStatecorrect - Visual order -
getVisibleNodes()returns correct order - Database persistence - Real database reflects changes
- Event emissions - Correct events fired exactly once
- No console errors - Clean execution
Scenario-Specific Seeding
Use test builders for complex scenarios:
const builder = new TestNodeBuilder(backend);
await builder.createNodeTree({
content: "Parent",
children: [
{ content: "Child1" },
{ content: "Child2", children: [
{ content: "Grandchild1" }
]}
],
collapsed: true
});Implementation Tasks
Infrastructure Setup
- Verify Create HTTP dev server for web-mode testing with real database access #209 test utilities exist and work
- Create
TestNodeBuilderhelper if not already created by Create HTTP dev server for web-mode testing with real database access #209 - Set up test fixtures for common node structures
- Verify backend adapter auto-detection works in test environment
Section 1: Enter Key Operations
- Test: Basic enter - create new node after current
- Test: Enter at beginning - insertAtBeginning logic
- Test: Enter in middle - split content at cursor
- Test: Enter at end - create empty placeholder
- Test: Enter with header syntax - preserve/inherit level
- Test: Enter at beginning of header - keep header on original
- Test: Enter in empty node - create sibling
- Test: Enter with children (expanded) - transfer children
- Test: Last character leak prevention
- Test: Enter updates next sibling beforeSiblingId
Section 2: Shift+Enter Operations
- Test: Basic Shift+Enter - insert \n without new node
- Test: Multiple Shift+Enter - handle multiple newlines
- Test: Shift+Enter rendering - visual line break appears
- Test: Shift+Enter in bold - preserve bold
- Test: Shift+Enter in italic - preserve italic
- Test: Shift+Enter in code - preserve
code - Test: Shift+Enter in strikethrough (double) - preserve
strike - Test: Shift+Enter in strikethrough (single) - preserve
strike - Test: Shift+Enter with mixed formatting
- Test: Cursor positioning after split
- Test: Arrow up/down in multiline node
Section 3: Backspace Operations
- Test: Basic backspace merge - combine with previous
- Test: Backspace cursor position - cursor at junction
- Test: Backspace with inline formatting - preserve formatting
- Test: Backspace with children - promote to parent
- Test: Children promotion preserves depth
- Test: Children disappearing prevention
- Test: Backspace sibling chain update - repair beforeSiblingId
- Test: Backspace in middle - delete character only
- Test: Cannot backspace first node (edge case)
Section 4: Indent/Outdent Operations
- Test: Basic indent - make child of previous sibling
- Test: Indent first child - cannot indent (no previous)
- Test: Indent with existing children - append to end
- Test: Indent updates sibling chain - remove from old
- Test: Indent depth calculation - depth increases by 1
- Test: Basic outdent - move up one level
- Test: Outdent root node - cannot outdent
- Test: Outdent positioning - insert after old parent
- Test: Outdent transfers siblings below as children
- Test: Transferred siblings maintain order
- Test: Outdent sibling chain integrity after transfer
- Test: Outdent updates descendant depths recursively
- Test: Indent updates descendant depths
- Test: Indent/outdent in deep hierarchy (depth 5+)
Section 5: Sibling Chain Integrity
- Test: Creating node updates next sibling
- Test: Creating first child - beforeSiblingId is null
- Test: Deleting node repairs chain
- Test: Deleting last sibling - no updates needed
- Test: Moving node removes from old chain
- Test: Multiple siblings maintain order (traverse chain)
- Test: Exactly one first child (one null beforeSiblingId)
Documentation
- Update test cases checklist with completion status
- Document test patterns and helpers
- Add troubleshooting guide for common test failures
Acceptance Criteria
- All 51 tests implemented
- Tests use real backend via HTTP adapter (Create HTTP dev server for web-mode testing with real database access #209)
- Tests use real database (separate test DB per suite)
- Each test verifies in-memory state, visual order, database persistence, and events
- Test database cleanup after each test
- No mocked services (real ReactiveNodeService, real backend)
- Test execution time <2 minutes for all 51 tests
- Zero console errors during test runs (unless explicitly testing error scenarios)
- All test cases checked off in
critical-node-operations-test-cases.md - Failed tests documented with issue numbers for bug fixes
Success Metrics
- Tests implemented: 51/51 (100%)
- Test suite runs in <120 seconds
- Tests catch real regressions (validate by temporarily breaking code)
- No flaky tests (run 10x, all pass or fail consistently)
- Clear test output with descriptive names
- Documentation complete for test patterns
Related Issues
- Implement comprehensive test coverage for critical node operations (99.9% complete - 1 test remaining) #208 - Parent epic
- Create HTTP dev server for web-mode testing with real database access #209 - HTTP dev server infrastructure (MUST BE COMPLETE before starting)
- Bug: Shift+Enter no longer splits inline formatting (e.g., **text**) #185 - Shift+Enter inline formatting (regression test reference)
- Fix outdent sibling chain integrity and parent validation #184 - Outdent sibling chain integrity (regression test reference)
Notes
TDD Approach:
- Write tests first, expect some failures
- Failures guide bug fixes in separate PRs/commits
- Goal: comprehensive coverage, not 100% passing immediately
- Document all failures with expected vs actual behavior
Test Reference Document:
packages/core/packages/desktop-app/docs/testing/critical-node-operations-test-cases.md
Backend Adapter Usage:
// Auto-detects environment (uses HTTP in tests)
const backend = getBackendAdapter();
// All operations go through adapter
await backend.createNode({ ... });
await backend.updateNode(id, { ... });
await backend.deleteNode(id);Database Verification Example:
// Verify in-memory state
expect(service.getNode(nodeId)).toBeDefined();
// Verify database persistence
const dbNode = await queryDatabase(dbPath,
`SELECT * FROM nodes WHERE id = '${nodeId}'`
);
expect(dbNode).toBeDefined();
expect(dbNode.content).toBe(expectedContent);
// Verify visual order
const visible = await service.getVisibleNodes(rootId);
expect(visible[0].id).toBe(nodeId);
Activity
feat: Add HTTP dev server for web-mode testing with real database acc…
feat: Add HTTP dev server for web-mode testing with real database acc…
Add Phase 1: Core + Hierarchy Operations Test Coverage (51 tests)
feat: Add Phase 2 query endpoints infrastructure (#211)
Phase 1: Core + Hierarchy Operations Test Coverage (Sections 1-5, 51 …
Phase 2: Infrastructure Test Coverage (Sections 6-8, 21 tests) (#215)
feat: Add HTTP dev server for web-mode testing with real database acc…
Phase 1: Core + Hierarchy Operations Test Coverage (Sections 1-5, 51 …
Phase 2: Infrastructure Test Coverage (Sections 6-8, 21 tests) (#215)
feat: Add HTTP dev server for web-mode testing with real database acc…
Phase 1: Core + Hierarchy Operations Test Coverage (Sections 1-5, 51 …
Phase 2: Infrastructure Test Coverage (Sections 6-8, 21 tests) (#215)
feat: Add HTTP dev server for web-mode testing with real database acc…
Phase 1: Core + Hierarchy Operations Test Coverage (Sections 1-5, 51 …
Phase 2: Infrastructure Test Coverage (Sections 6-8, 21 tests) (#215)