Novel Editor Autocomplete Tests
This directory contains comprehensive Playwright tests for the Novel Editor autocomplete functionality in Terraphim AI.
Overview
The autocomplete test suite validates the complete Novel Editor autocomplete workflow, including:
- TipTap integration with custom Terraphim extension
- MCP server backend communication
- Keyboard navigation and accessibility
- Performance benchmarks
- Visual regression testing
- Error handling and fallback scenarios
Test Structure
tests/
βββ e2e/ # End-to-end Playwright tests
β βββ novel-autocomplete.spec.ts # Main test specification
β βββ helpers/
β βββ autocomplete-helpers.ts # Test helper functions
βββ unit/ # Unit tests for individual components
β βββ operator-parsing.test.mjs # Search operator parsing tests
β βββ README.md # Unit tests documentation
βββ fixtures/
β βββ autocomplete-fixtures.ts # Test data and mock responses
βββ global-setup-autocomplete.ts # Pre-test setup and MCP server startup
βββ global-teardown-autocomplete.ts # Post-test cleanup and artifact collection
βββ playwright-autocomplete.config.ts # Autocomplete-specific Playwright config
βββ README.md # This filePrerequisites
System Requirements
- Node.js (v18 or higher)
- Rust toolchain with Cargo
- Git
- curl (for health checks)
Project Setup
- Install frontend dependencies:
- Build MCP server:
- Install Playwright browsers:
Running Tests
Unit Tests
# From the desktop directory
# Run operator parsing tests
End-to-End Tests
# From the desktop directory
# Run all autocomplete tests
# Run with UI mode for debugging
# Run specific test project (Chrome only)
Test Projects Available
- autocomplete-chrome - Primary testing in Chrome
- autocomplete-firefox - Cross-browser testing in Firefox
- autocomplete-safari - WebKit testing (macOS only)
- autocomplete-mobile-chrome - Mobile touch interaction testing
- autocomplete-performance - Performance benchmarking tests
- autocomplete-visual - Visual regression testing
Environment Variables
Control test behavior with these environment variables:
# Server configuration
# MCP server port (default: 8001)
# Skip MCP server startup
# Test scope
# Enable Safari tests in CI
# Enable mobile tests
# Enable debug logging
# CI/CD settings
# Enable CI-specific timeouts and settingsAdvanced Usage
# Run only performance tests
# Run only visual regression tests
# Run with custom retry count
# Run with specific timeout
Test Architecture
Global Setup Process
The global-setup-autocomplete.ts handles:
- Environment validation (Node.js, Cargo, Git, curl)
- Test directory creation
- MCP server startup and health verification
- Functional test of autocomplete endpoint
Global Teardown Process
The global-teardown-autocomplete.ts handles:
- MCP server shutdown with graceful termination
- Test artifact collection and archiving
- Test report generation with pass/fail statistics
- Temporary file cleanup (CI environments only)
Test Helpers
The helper functions provide:
- Editor Interaction:
waitForEditor,typeInEditor,clearEditor - Autocomplete Testing:
triggerAutocomplete,waitForSuggestions,selectSuggestion - Keyboard Navigation:
navigateWithArrows,selectWithEnter,cancelWithEscape - Server Communication:
testMCPConnection,validateSuggestionStructure - Performance Measurement:
measureResponseTime,checkDebounceEffectiveness
Test Fixtures
Comprehensive test data including:
- Expected suggestions for common queries
- Mock responses for offline testing
- Error scenarios and fallback behavior
- Performance benchmarks and thresholds
- Visual test scenarios for regression testing
- Keyboard navigation test sequences
Test Scenarios Covered
Core Functionality
- Basic autocomplete trigger and display
- Suggestion filtering and ranking
- Text insertion and editor integration
- Debouncing and performance optimization
User Interactions
- Keyboard Navigation: Arrow keys, Tab, Enter, Escape
- Mouse Interaction: Click selection, hover effects
- Touch Interface: Mobile gesture support (when enabled)
Backend Integration
- MCP Server: Live connection testing and response validation
- Error Handling: Network failures, timeout scenarios
- Fallback Behavior: Graceful degradation when servers unavailable
Performance Testing
- Response time measurements (< 500ms target)
- Debounce effectiveness validation
- Memory usage monitoring
- UI responsiveness under load
Visual Regression
- Dropdown appearance consistency
- Theme compatibility testing
- Mobile responsive layout validation
- High contrast mode support
Accessibility
- Screen reader compatibility
- Keyboard-only navigation
- Focus management and indicators
- ARIA attributes and roles
Configuration Details
Test Timeouts
- Global timeout: 10 minutes (local), 15 minutes (CI)
- Test timeout: 60 seconds (local), 2 minutes (CI)
- Action timeout: 30 seconds (local), 60 seconds (CI)
- Expect timeout: 15 seconds (local), 30 seconds (CI)
Browser Settings
- Chrome: Optimized for MCP server CORS, background throttling disabled
- Firefox: Notifications and permissions disabled for clean testing
- Safari: Standard WebKit configuration, skipped in CI unless requested
- Mobile: Touch-enabled testing with Pixel 5 viewport
Reporter Configuration
- Local: HTML reports with failure screenshots, list reporter with steps
- CI: GitHub reporter, HTML, JSON, and JUnit XML output formats
Debugging Test Failures
Common Issues and Solutions
- MCP Server Connection Failed
# Check if MCP server is running
# Check server logs
RUST_LOG=debug - Frontend Not Loading
# Start development server manually
# Check port availability
- Test Timeout Issues
# Run with extended timeout
# Enable debug logging
DEBUG=pw:api - Browser Installation Issues
# Reinstall Playwright browsers
# Install system dependencies
Debug Mode
Enable detailed logging and debugging:
# Enable Playwright debug logging
# Enable browser debugging
# Record test execution
Test Report Analysis
After test execution, reports are available in:
test-results/autocomplete-report/- HTML report with screenshotstest-results/autocomplete-results.json- Machine-readable test resultstest-results/autocomplete-junit.xml- CI/CD compatible resultstest-results/autocomplete-summary.json- Quick test summary
CI/CD Integration
GitHub Actions Example
name: Novel Editor Autocomplete Tests
on:
jobs:
autocomplete-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Install dependencies
run: |
cd desktop
yarn install
npx playwright install --with-deps
- name: Build MCP server
run: |
cd crates/terraphim_mcp_server
cargo build --release
- name: Run autocomplete tests
run: |
cd desktop
npx playwright test --config=tests/playwright-autocomplete.config.ts
env:
CI: true
MCP_SERVER_PORT: 8001
- uses: actions/upload-artifact@v3
if: failure()
with:
name: playwright-report
path: desktop/test-results/Jenkins Pipeline Example
pipeline {
agent any
environment {
CI = 'true'
MCP_SERVER_PORT = '8001'
}
stages {
{
steps {
sh 'cd desktop && yarn install'
sh 'npx playwright install --with-deps'
sh 'cd crates/terraphim_mcp_server && cargo build --release'
}
}
{
steps {
sh 'cd desktop && npx playwright test --config=tests/playwright-autocomplete.config.ts'
}
post {
always {
}
}
}
}
}Performance Benchmarks
Response Time Targets
- Excellent: < 100ms
- Good: < 300ms
- Acceptable: < 500ms
- Poor: > 1000ms
Debounce Settings
- Minimum delay: 200ms
- Optimal delay: 300ms
- Maximum delay: 600ms
Suggestion Counts
- Minimal: 3 suggestions
- Standard: 8 suggestions
- Maximum: 12 suggestions
Contributing
Adding New Tests
- Add test scenarios to
fixtures/autocomplete-fixtures.ts - Implement test logic in
e2e/novel-autocomplete.spec.ts - Update helper functions in
helpers/autocomplete-helpers.tsif needed - Document any new configuration requirements
Test Data Management
- Keep expected suggestions synchronized with actual MCP server responses
- Update mock responses when backend API changes
- Maintain visual regression baselines for UI changes
Performance Testing
- Add new benchmarks to
PERFORMANCE_BENCHMARKSin fixtures - Use
@performancetag for performance-specific tests - Monitor and update thresholds based on baseline measurements
Troubleshooting Guide
Port Conflicts
If default port 8001 is occupied:
Memory Issues
For large test suites on limited memory systems:
# Reduce parallel workers
# Skip memory-intensive projects
Network Issues
For environments with limited network access:
# Skip MCP server startup
# Use shorter timeouts
Support
For issues with the autocomplete test suite:
- Check the troubleshooting guide above
- Review test output in
test-results/directory - Enable debug logging with
DEBUG=true - Consult the main Terraphim AI documentation
- File issues in the project repository with test logs attached