Skip to content
Merged
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
183 changes: 183 additions & 0 deletions docs/architecture/development/testing-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
# NodeSpace Testing Guide

**Practical testing for early-stage development with gradual complexity growth.**

## Quick Start

```bash
# Rust backend tests
cargo test

# Frontend tests
bun run test

# Frontend tests with coverage
bun run test:coverage

# All tests
cargo test && bun run test
```

## 4 Core Testing Types

### 1. Unit Testing
Test individual functions and methods in isolation.

**Rust Example:**
```rust
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_node_validation() {
let node = NodeData::new(NodeType::Text, "".to_string());
let result = node.validate();
assert!(result.is_err());
}
}
```

**TypeScript Example:**
```typescript
import { describe, it, expect } from 'vitest';
import { validateNodeContent } from './nodeUtils';

describe('Node Validation', () => {
it('rejects empty content', () => {
expect(validateNodeContent('')).toBe(false);
});
});
```

### 2. Component Testing
Test UI components with realistic user interactions.

```typescript
import { render, screen, fireEvent } from '@testing-library/svelte';
import TextNode from '$lib/components/TextNode.svelte';

describe('TextNode', () => {
it('renders and edits content', async () => {
render(TextNode, { props: { content: 'Hello' } });

const element = screen.getByText('Hello');
await fireEvent.click(element);

expect(screen.getByRole('textbox')).toBeInTheDocument();
});
});
```

### 3. Integration Testing
Test component workflows and API integration.

```typescript
import { createMockAPI } from './fixtures/mockAPI';

describe('Node Management', () => {
it('saves node via API', async () => {
const mockAPI = createMockAPI();
const result = await mockAPI.saveNode({ content: 'Test' });

expect(result.id).toBeTruthy();
expect(mockAPI.getLastSaved().content).toBe('Test');
});
});
```

### 4. Basic E2E Testing
Test critical user workflows when UI exists.

```typescript
import { test, expect } from '@playwright/test';

test('creates and saves a note', async ({ page }) => {
await page.goto('/');
await page.click('[data-testid="new-note"]');
await page.fill('textarea', 'My note content');
await page.click('[data-testid="save"]');

await expect(page.locator('text=My note content')).toBeVisible();
});
```

## Simple Mock Strategy

### Mock Data Store
```typescript
export class SimpleMockStore {
private nodes = new Map<string, NodeData>();

async save(node: NodeData): Promise<string> {
const id = node.id || `node-${Date.now()}`;
this.nodes.set(id, { ...node, id });
return id;
}

async load(id: string): Promise<NodeData | null> {
return this.nodes.get(id) || null;
}
}
```

### Test Utilities
```typescript
export function createTestNode(content = 'Test'): NodeData {
return {
id: `test-${Date.now()}`,
type: 'text',
content,
createdAt: new Date()
};
}

export function renderWithStore(component: any, props = {}) {
const mockStore = new SimpleMockStore();
return render(component, {
props: { ...props, dataStore: mockStore },
context: new Map([['dataStore', mockStore]])
});
}
```

## Coverage Requirements

- **Rust Backend**: >80% line coverage
- **Frontend Components**: >75% statement coverage
- **Critical Workflows**: 100% tested

## Testing Commands

```bash
# Run tests with coverage
cargo test --coverage # Rust (requires cargo-llvm-cov)
bun run test:coverage # Frontend

# Run specific tests
cargo test node_validation # Rust specific test
bun run test TextNode # Frontend specific test
```

## Quality Gates

Before creating PR, verify:
- [ ] All tests pass
- [ ] Coverage thresholds met
- [ ] No linting errors (`bun run quality:fix`)
- [ ] Component works in isolation

## Growth Strategy

**Start Simple** (Current):
- Basic unit/component tests
- Simple mocks
- Essential workflows

**Add Complexity** (As Needed):
- Performance testing
- Security validation
- Cross-platform E2E
- Advanced mocking

This approach provides immediate practical value while allowing natural growth as the project matures.
71 changes: 69 additions & 2 deletions nodespace-app/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,74 @@
# Tauri + SvelteKit + TypeScript
# NodeSpace Desktop Application

This template should help get you started developing with Tauri, SvelteKit and TypeScript in Vite.
AI-native knowledge management system built with Tauri, SvelteKit, and TypeScript.

## Quick Start

### Development Setup

```bash
# Install dependencies
bun install

# Start development server
bun run tauri:dev
```

### Testing

NodeSpace uses a simplified testing foundation with 4 core testing types:

```bash
# Run all tests
bun run test

# Run tests with coverage
bun run test:coverage

# Run Rust backend tests
cd src-tauri && cargo test

# Run tests in watch mode
bun run test:watch
```

**Testing Standards:**
- **Frontend**: 80% coverage (lines/functions/statements), 75% branches
- **Backend**: 80% coverage target
- **Integration**: 100% critical workflows tested

### Test Examples

- **Unit Tests**: `src/tests/example/BasicFunctions.test.ts`
- **Component Tests**: `src/tests/component/TextNode.test.ts`
- **Integration Tests**: `src/tests/integration/node-workflow.test.ts`

See `docs/architecture/development/testing-guide.md` for detailed testing patterns and examples.

## Development Commands

```bash
# Quality checks
bun run quality:fix # Fix linting, formatting, and type errors

# Testing
bun run test # Run all frontend tests
bun run test:coverage # Run with coverage report
cargo test # Run Rust tests (from src-tauri/)

# Tauri desktop app
bun run tauri:dev # Development mode
bun run tauri:build # Production build
```

## Recommended IDE Setup

[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer).

## Architecture

- **Frontend**: SvelteKit + TypeScript + TailwindCSS
- **Backend**: Rust with async/await patterns
- **Desktop**: Tauri 2.0 for native integration
- **Testing**: Vitest + Testing Library + Playwright (E2E)
- **Package Manager**: Bun (required)
Loading