|
| 1 | +# Database Designer Test Suite |
| 2 | + |
| 3 | +This directory contains comprehensive tests for the Database Designer application. |
| 4 | + |
| 5 | +## Test Structure |
| 6 | + |
| 7 | +``` |
| 8 | +tests/ |
| 9 | +├── unit/ # Unit tests (Jest) |
| 10 | +│ ├── app.test.js # Core application logic |
| 11 | +│ ├── diagram.test.js # Diagram rendering functions |
| 12 | +│ ├── ui.test.js # UI utility functions |
| 13 | +│ └── io.test.js # Data persistence functions |
| 14 | +├── integration/ # Integration tests (Playwright) |
| 15 | +│ ├── user-workflows.spec.js # End-to-end user workflows |
| 16 | +│ └── data-persistence.spec.js # Data persistence scenarios |
| 17 | +├── package.json # Test dependencies |
| 18 | +├── playwright.config.js # Playwright configuration |
| 19 | +├── setup.js # Jest setup file |
| 20 | +└── README.md # This file |
| 21 | +``` |
| 22 | + |
| 23 | +## Prerequisites |
| 24 | + |
| 25 | +- Node.js 16+ (Jest 28+ requires Node 16+) |
| 26 | +- Python 3.7+ (for the server) |
| 27 | + |
| 28 | +## Installation |
| 29 | + |
| 30 | +1. Navigate to the tests directory: |
| 31 | + ```bash |
| 32 | + cd tests |
| 33 | + ``` |
| 34 | + |
| 35 | +2. Install dependencies: |
| 36 | + ```bash |
| 37 | + npm install |
| 38 | + ``` |
| 39 | + |
| 40 | +3. Install Playwright browsers: |
| 41 | + ```bash |
| 42 | + npm run install:playwright |
| 43 | + ``` |
| 44 | + |
| 45 | +## Running Tests |
| 46 | + |
| 47 | +### Unit Tests |
| 48 | + |
| 49 | +Run all unit tests: |
| 50 | +```bash |
| 51 | +npm test |
| 52 | +``` |
| 53 | + |
| 54 | +Run unit tests in watch mode: |
| 55 | +```bash |
| 56 | +npm run test:watch |
| 57 | +``` |
| 58 | + |
| 59 | +Run unit tests with coverage: |
| 60 | +```bash |
| 61 | +npm run test:coverage |
| 62 | +``` |
| 63 | + |
| 64 | +### Integration Tests |
| 65 | + |
| 66 | +Run all integration tests: |
| 67 | +```bash |
| 68 | +npm run test:integration |
| 69 | +``` |
| 70 | + |
| 71 | +Run integration tests with UI: |
| 72 | +```bash |
| 73 | +npm run test:integration:ui |
| 74 | +``` |
| 75 | + |
| 76 | +### All Tests |
| 77 | + |
| 78 | +Run both unit and integration tests: |
| 79 | +```bash |
| 80 | +npm run test:all |
| 81 | +``` |
| 82 | + |
| 83 | +## Test Categories |
| 84 | + |
| 85 | +### Unit Tests |
| 86 | + |
| 87 | +- **app.test.js**: Tests core business logic including schema operations, table/column management, and foreign key operations |
| 88 | +- **diagram.test.js**: Tests SVG rendering, geometry calculations, and diagram interactions |
| 89 | +- **ui.test.js**: Tests UI utility functions for form population and data binding |
| 90 | +- **io.test.js**: Tests data persistence, localStorage operations, and server synchronization |
| 91 | + |
| 92 | +### Integration Tests |
| 93 | + |
| 94 | +- **user-workflows.spec.js**: End-to-end user scenarios including table creation, column management, foreign key relationships, and diagram interactions |
| 95 | +- **data-persistence.spec.js**: Data persistence scenarios including auto-save, server synchronization, and error recovery |
| 96 | + |
| 97 | +## Test Configuration |
| 98 | + |
| 99 | +### Jest Configuration |
| 100 | + |
| 101 | +Tests are configured in `package.json`: |
| 102 | +- Test environment: jsdom (for DOM testing) |
| 103 | +- Setup file: `setup.js` (mocks and global configurations) |
| 104 | +- Coverage collection from parent directory JavaScript files |
| 105 | +- Coverage reports in multiple formats (text, lcov, html) |
| 106 | + |
| 107 | +### Playwright Configuration |
| 108 | + |
| 109 | +Tests are configured in `playwright.config.js`: |
| 110 | +- Tests run against localhost:3000 |
| 111 | +- Automatic server startup with Python server |
| 112 | +- Multiple browser testing (Chrome, Firefox, Safari) |
| 113 | +- HTML reporter for test results |
| 114 | + |
| 115 | +## CI/CD Integration |
| 116 | + |
| 117 | +Tests are automatically run on: |
| 118 | +- Push to main/develop branches |
| 119 | +- Pull requests to main/develop branches |
| 120 | +- Multiple operating systems (Ubuntu, Windows, macOS) |
| 121 | +- Multiple Node.js versions (16, 18, 20) |
| 122 | + |
| 123 | +## Coverage Reports |
| 124 | + |
| 125 | +Unit test coverage is generated in the `coverage/` directory: |
| 126 | +- HTML report: `coverage/lcov-report/index.html` |
| 127 | +- LCOV report: `coverage/lcov.info` |
| 128 | +- Text summary in terminal |
| 129 | + |
| 130 | +## Debugging Tests |
| 131 | + |
| 132 | +### Unit Tests |
| 133 | + |
| 134 | +To debug unit tests, add `debugger` statements and run: |
| 135 | +```bash |
| 136 | +node --inspect-brk node_modules/.bin/jest --runInBand |
| 137 | +``` |
| 138 | + |
| 139 | +### Integration Tests |
| 140 | + |
| 141 | +To debug integration tests: |
| 142 | +1. Run tests in headed mode: |
| 143 | + ```bash |
| 144 | + npx playwright test --headed |
| 145 | + ``` |
| 146 | + |
| 147 | +2. Run tests in debug mode: |
| 148 | + ```bash |
| 149 | + npx playwright test --debug |
| 150 | + ``` |
| 151 | + |
| 152 | +3. Use the Playwright UI: |
| 153 | + ```bash |
| 154 | + npm run test:integration:ui |
| 155 | + ``` |
| 156 | + |
| 157 | +## Writing New Tests |
| 158 | + |
| 159 | +### Unit Tests |
| 160 | + |
| 161 | +1. Create test files in `unit/` directory |
| 162 | +2. Follow naming convention: `*.test.js` |
| 163 | +3. Use Jest testing framework |
| 164 | +4. Mock external dependencies appropriately |
| 165 | + |
| 166 | +### Integration Tests |
| 167 | + |
| 168 | +1. Create test files in `integration/` directory |
| 169 | +2. Follow naming convention: `*.spec.js` |
| 170 | +3. Use Playwright testing framework |
| 171 | +4. Test real user workflows and interactions |
| 172 | + |
| 173 | +## Test Data |
| 174 | + |
| 175 | +Test fixtures and mock data should be placed in a `fixtures/` directory if needed. Currently, tests use inline mock data for simplicity. |
| 176 | + |
| 177 | +## Troubleshooting |
| 178 | + |
| 179 | +### Common Issues |
| 180 | + |
| 181 | +1. **Playwright browsers not installed**: |
| 182 | + ```bash |
| 183 | + npm run install:playwright |
| 184 | + ``` |
| 185 | + |
| 186 | +2. **Server not starting**: |
| 187 | + - Ensure Python 3.7+ is installed |
| 188 | + - Check that `server.py` is in the parent directory |
| 189 | + - Verify port 3000 is available |
| 190 | + |
| 191 | +3. **Tests timing out**: |
| 192 | + - Increase timeout in test configuration |
| 193 | + - Check for infinite loops or blocking operations |
| 194 | + - Ensure proper async/await usage |
| 195 | + |
| 196 | +4. **Coverage not generated**: |
| 197 | + - Run `npm run test:coverage` |
| 198 | + - Check that source files are not excluded in Jest config |
| 199 | + |
| 200 | +## Contributing |
| 201 | + |
| 202 | +When adding new features: |
| 203 | +1. Write unit tests for new functions |
| 204 | +2. Write integration tests for new user workflows |
| 205 | +3. Ensure all tests pass before submitting PR |
| 206 | +4. Update this README if adding new test categories or configurations |
0 commit comments