This document describes the comprehensive test suite for the LeedPDF application, covering all major functionalities.
The test suite is organized into several categories:
- PDF Utilities Tests (
src/lib/utils/pdfUtils.test.ts) - Drawing Store Tests (
src/lib/stores/drawingStore.test.ts) - Drawing Utils Tests (
src/lib/utils/drawingUtils.test.ts)
- Application Tests (
tests/e2e/app.spec.ts) - PDF Loading Tests
- Drawing Features Tests
- Export/Save Tests
- Accessibility Tests
Before running tests, ensure you have installed all dependencies:
pnpm installRun all unit tests:
pnpm testRun tests in watch mode:
pnpm test:watchRun tests with coverage:
pnpm test:coverageRun tests with UI:
pnpm test:uiBuild the application first:
pnpm buildRun E2E tests:
pnpm test:e2eRun E2E tests in headed mode:
pnpm test:e2e --headedRun E2E tests in debug mode:
pnpm test:e2e --debugThe test suite aims for the following coverage targets:
- Lines: 80%
- Functions: 80%
- Branches: 80%
- Statements: 80%
- ✅ PDF loading from files and URLs
- ✅ PDF rendering and page management
- ✅ CORS proxy fallbacks for URL loading
- ✅ Dropbox URL conversion
- ✅ Error handling for invalid PDFs
- ✅ Page dimensions calculation
- ✅ Resource cleanup and memory management
- ✅ State management for drawing tools
- ✅ Drawing path storage and retrieval
- ✅ Shape object management
- ✅ Undo/redo functionality
- ✅ LocalStorage persistence
- ✅ PDF-specific drawing storage
- ✅ Auto-save functionality
- ✅ Constants and configuration arrays
- ✅ Drawing engine initialization
- ✅ Drawing operations (start, continue, end)
- ✅ Multiple tool support (pencil, eraser, highlight)
- ✅ Path rendering and scaling
- ✅ Point operations and coordinate conversion
- ✅ Path intersection detection
- ✅ Path simplification algorithms
- ✅ Bounding box calculations
- ✅ Application loading and welcome screen
- ✅ Navigation and routing
- ✅ PDF file upload and loading
- ✅ Drawing tools and annotations
- ✅ Export and save functionality
- ✅ Keyboard navigation and accessibility
- ✅ Mobile responsiveness
- ✅ Error handling
- Uses jsdom environment for DOM testing
- Includes comprehensive mocking setup
- Coverage reporting with thresholds
- Test file pattern matching
- Multi-browser testing (Chrome, Firefox, Safari, Edge)
- Mobile device testing
- Screenshot and video capture on failure
- Automatic dev server startup
The test suite uses extensive mocking to isolate functionality:
- Tauri APIs:
invoke,message,readFile - PDF.js: PDF loading and rendering
- Canvas Context: 2D drawing operations
- File API: File upload and handling
- LocalStorage: Data persistence
- IntersectionObserver: Lazy loading
- Mock PDF document creation
- Mock file creation utilities
- LocalStorage mock implementation
pnpm test src/lib/utils/pdfUtils.test.tspnpm test src/lib/stores/drawingStore.test.tspnpm test src/lib/utils/drawingUtils.test.tspnpm test:e2e --grep "PDF Loading"
pnpm test:e2e --grep "Drawing Features"
pnpm test:e2e --grep "Accessibility"# Run with verbose output
pnpm test --reporter=verbose
# Run specific test with debugging
pnpm test --reporter=verbose --grep "specific test name"
# Open test UI for interactive debugging
pnpm test:ui# Run with browser UI visible
pnpm test:e2e --headed
# Run in debug mode with browser dev tools
pnpm test:e2e --debug
# Run specific test file
pnpm test:e2e tests/e2e/app.spec.tsThe test suite is designed to run in CI environments:
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
node-version: 18
cache: pnpm
- run: pnpm install
- run: pnpm test:coverage
- run: pnpm build
- run: pnpm test:e2e- Minimal PDF for basic loading tests
- Multi-page PDF for navigation tests
- PDF with metadata for title extraction tests
- Sample drawing paths with different tools
- Shape objects with various types
- Intersection test cases for eraser functionality
- Isolation: Each test is independent and can run alone
- Mocking: External dependencies are mocked consistently
- Cleanup: Tests clean up after themselves
- Assertions: Clear, meaningful assertions
- Coverage: Aim for high coverage with meaningful tests
- Performance: Tests run quickly and efficiently
- Maintenance: Tests are easy to update when code changes
Tests failing in CI but passing locally:
- Check for timing issues in async operations
- Ensure all dependencies are properly mocked
- Verify browser compatibility for E2E tests
Canvas-related test failures:
- Ensure proper canvas context mocking
- Check for DOM element availability
- Verify drawing operation sequences
PDF loading test failures:
- Check PDF.js mock implementation
- Verify file reading mock setup
- Ensure proper error handling tests
E2E test timeouts:
- Increase timeout values for slow operations
- Check for proper element waiting strategies
- Verify application build and server startup
When adding new features:
- Write unit tests for new utilities and functions
- Update existing tests if behavior changes
- Add E2E tests for new user-facing features
- Maintain coverage targets
- Update documentation for new test patterns
- Unit tests:
*.test.tsalongside source files - E2E tests:
*.spec.tsintests/e2e/directory - Test utilities:
src/test/directory
- Global mocks:
src/test/setup.ts - Specific mocks: Alongside test files
- Test helpers:
src/test/helpers/