Skip to content

Commit 8678a52

Browse files
Copilotpatrickrb
andauthored
Add comprehensive Playwright test suite with CI/CD integration and database connection handling (#104)
* Initial plan * Set up Playwright testing infrastructure with core tests Co-authored-by: patrickrb <[email protected]> * Improved Playwright tests with comprehensive page coverage and documentation Co-authored-by: patrickrb <[email protected]> * Complete Playwright test suite with comprehensive coverage and CI/CD integration Co-authored-by: patrickrb <[email protected]> * Fix Playwright test configuration and API error handling for missing database Co-authored-by: patrickrb <[email protected]> * Complete Playwright test fixes - all 38 tests now passing Co-authored-by: patrickrb <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: patrickrb <[email protected]> Co-authored-by: Patrick Burns <[email protected]>
1 parent 1dc2498 commit 8678a52

36 files changed

+1507
-1
lines changed

.github/branch-protection.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Branch Protection Setup
2+
3+
To require passing tests before merging pull requests, configure branch protection rules:
4+
5+
## GitHub Repository Settings
6+
7+
1. Go to **Settings****Branches**
8+
2. Click **Add rule** or edit existing rule for `main` branch
9+
3. Configure the following settings:
10+
11+
### Required Settings
12+
-**Require a pull request before merging**
13+
-**Require status checks to pass before merging**
14+
-**Require branches to be up to date before merging**
15+
16+
### Required Status Checks
17+
Add these status checks:
18+
- `test` (from CI workflow)
19+
- `tests-required` (from CI workflow)
20+
21+
### Recommended Settings
22+
-**Restrict pushes that create files larger than 100 MB**
23+
-**Require conversation resolution before merging**
24+
-**Do not allow bypassing the above settings**
25+
26+
## Alternative: Using GitHub CLI
27+
28+
```bash
29+
# Enable branch protection with required tests
30+
gh api repos/:owner/:repo/branches/main/protection \
31+
--method PUT \
32+
--field required_status_checks='{"strict":true,"checks":[{"context":"test"},{"context":"tests-required"}]}' \
33+
--field enforce_admins=true \
34+
--field required_pull_request_reviews='{"required_approving_review_count":1}' \
35+
--field restrictions=null
36+
```
37+
38+
## Verification
39+
40+
Once configured:
41+
1. All pull requests will require passing tests
42+
2. Direct pushes to main branch will be blocked
43+
3. Tests must pass before merging is allowed
44+
4. The "tests-required" job ensures test completion
45+
46+
This ensures code quality and prevents breaking changes from being merged into the main branch.

.github/workflows/ci.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
test:
11+
timeout-minutes: 60
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: '20'
20+
cache: 'npm'
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
- name: Install Playwright Browsers
26+
run: npx playwright install --with-deps chromium
27+
28+
- name: Build application
29+
run: npm run build
30+
31+
- name: Run linting
32+
run: npm run lint
33+
34+
- name: Run Playwright tests
35+
run: npm run test
36+
env:
37+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
38+
39+
- uses: actions/upload-artifact@v4
40+
if: always()
41+
with:
42+
name: playwright-report
43+
path: playwright-report/
44+
retention-days: 30
45+
46+
# This job will be required for merging PRs
47+
tests-required:
48+
runs-on: ubuntu-latest
49+
needs: test
50+
if: always()
51+
steps:
52+
- name: Check test results
53+
run: |
54+
if [ "${{ needs.test.result }}" != "success" ]; then
55+
echo "Tests failed or were cancelled"
56+
exit 1
57+
fi
58+
echo "All tests passed!"

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,51 @@ The script requires these data files to be present:
150150

151151
Both files are included in the repository.
152152

153+
## Testing
154+
155+
Nextlog includes comprehensive end-to-end tests using Playwright to ensure application stability and feature reliability.
156+
157+
### Running Tests
158+
159+
```bash
160+
# Run all tests
161+
npm test
162+
163+
# Run tests for specific browser
164+
npm run test:chromium
165+
166+
# Run tests in headed mode (visible browser)
167+
npm run test:headed
168+
169+
# Run tests in UI mode for debugging
170+
npm run test:ui
171+
172+
# View test report
173+
npm run test:report
174+
```
175+
176+
### Test Coverage
177+
178+
The test suite covers:
179+
- **Authentication**: Login and registration flows
180+
- **Navigation**: Page routing and redirects
181+
- **Forms**: Input validation and submission
182+
- **Responsive Design**: Mobile and desktop layouts
183+
- **Error Handling**: Database connection failures
184+
- **Core Features**: Contact management, awards, ADIF import/export
185+
- **Build Quality**: JavaScript errors, CSS loading, performance
186+
- **Security**: Protected routes and authentication redirects
187+
188+
### Continuous Integration
189+
190+
Tests run automatically on:
191+
- Pull requests to main/develop branches
192+
- Pushes to main/develop branches
193+
194+
The CI workflow requires all tests to pass before merging. See `/.github/workflows/ci.yml` and `/.github/branch-protection.md` for setup details.
195+
196+
See `/tests/README.md` for detailed testing documentation.
197+
153198
## Usage
154199

155200
1. **Register**: Create a new account with your amateur radio callsign

package-lock.json

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
"dev": "next dev --turbopack",
77
"build": "next build",
88
"start": "next start",
9-
"lint": "next lint"
9+
"lint": "next lint",
10+
"test": "playwright test",
11+
"test:ui": "playwright test --ui",
12+
"test:debug": "playwright test --debug",
13+
"test:headed": "playwright test --headed",
14+
"test:chromium": "playwright test --project=chromium",
15+
"test:report": "playwright show-report",
16+
"test:install": "playwright install"
1017
},
1118
"dependencies": {
1219
"@azure/storage-blob": "^12.27.0",
@@ -40,6 +47,7 @@
4047
},
4148
"devDependencies": {
4249
"@eslint/eslintrc": "^3",
50+
"@playwright/test": "^1.54.2",
4351
"@tailwindcss/postcss": "^4",
4452
"@types/bcryptjs": "^2.4.6",
4553
"@types/jsonwebtoken": "^9.0.10",
@@ -49,6 +57,7 @@
4957
"@types/react-dom": "^19",
5058
"eslint": "^9",
5159
"eslint-config-next": "15.3.5",
60+
"playwright": "^1.54.2",
5261
"tailwindcss": "^4",
5362
"typescript": "5.8.3"
5463
}
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Page snapshot
2+
3+
```yaml
4+
- paragraph: Checking system status...
5+
```

playwright-report/index.html

Lines changed: 77 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)