Skip to content

Commit 4eed43d

Browse files
rdhyeeclaude
andcommitted
Add Playwright testing infrastructure for Cesium UI
Establish comprehensive testing foundation for future UI evolution: **Test Framework**: - Playwright for E2E browser testing - Configured for Chromium (extensible to Firefox/Safari) - HTML reporting with traces and screenshots - CI-ready with automatic retries **Test Coverage** (`tests/playwright/cesium-queries.spec.js`): - ✅ Page loading and geocode search box - ✅ Camera movement on geocode search - ✅ HTML table structure (5 columns: Thumbnail | Sample | Description | Site | Location) - ✅ Clickable sample PID links to OpenContext - ✅ "View site" links - ✅ Thumbnail images and "No image" placeholders - ✅ Result count displays - ✅ Empty state friendly messages - ✅ Scrollable tables with sticky headers - ✅ Zebra-striped rows - ✅ Visual consistency across all three tables **Test Data**: - PKAP location with samples: `geoloc_04d6e816218b1a8798fa90b3d1d43bf4c043a57f` - Larnaka site marker (empty state): `geoloc_7a05216d388682536f3e2abd8bd2ee3fb286e461` **Infrastructure Files**: - `playwright.config.js`: Test configuration with extended timeouts - `package.json`: NPM scripts (test, test:headed, test:ui, test:debug) - `tests/README.md`: Comprehensive testing guide - `tests/playwright/cesium-queries.spec.js`: Full test suite **NPM Scripts**: ```bash npm test # Run all tests npm run test:headed # Run with browser visible npm run test:ui # Interactive UI mode npm run test:debug # Debug mode with inspector npm run test:report # View HTML report ``` **Gitignore Updates**: - node_modules/ - test-results/ - playwright-report/ - package-lock.json **Future-Ready**: This infrastructure provides a solid foundation for: - Adding new UI feature tests - Visual regression testing - Accessibility testing - Performance monitoring - Cross-browser testing - Mobile responsive tests Tests validate the enhanced query UI (Path 1, Path 2, Eric's query) to ensure consistent, high-quality user experience as the UI evolves. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4a4b527 commit 4eed43d

File tree

5 files changed

+636
-0
lines changed

5 files changed

+636
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ docs
66
# Large data files
77
*.parquet
88

9+
# Node / Playwright
10+
node_modules/
11+
package-lock.json
12+
tests/playwright-report/
13+
test-results/
14+
playwright-report/
15+
playwright/.cache/
16+
917
.$*
1018

1119
# Byte-compiled / optimized / DLL files

package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "isamplesorg-website",
3+
"version": "1.0.0",
4+
"description": "iSamples website testing infrastructure",
5+
"private": true,
6+
"scripts": {
7+
"test": "playwright test",
8+
"test:headed": "playwright test --headed",
9+
"test:ui": "playwright test --ui",
10+
"test:debug": "playwright test --debug",
11+
"test:report": "playwright show-report tests/playwright-report",
12+
"test:install": "playwright install chromium"
13+
},
14+
"keywords": [
15+
"isamples",
16+
"testing",
17+
"playwright"
18+
],
19+
"author": "iSamples Team",
20+
"license": "MIT",
21+
"devDependencies": {
22+
"@playwright/test": "^1.40.0"
23+
}
24+
}

playwright.config.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// @ts-check
2+
const { defineConfig, devices } = require('@playwright/test');
3+
4+
/**
5+
* Playwright Configuration for iSamples Cesium Tutorial Tests
6+
*
7+
* @see https://playwright.dev/docs/test-configuration
8+
*/
9+
module.exports = defineConfig({
10+
testDir: './tests/playwright',
11+
12+
/* Run tests in files in parallel */
13+
fullyParallel: false,
14+
15+
/* Fail the build on CI if you accidentally left test.only in the source code. */
16+
forbidOnly: !!process.env.CI,
17+
18+
/* Retry on CI only */
19+
retries: process.env.CI ? 2 : 0,
20+
21+
/* Opt out of parallel tests on CI. */
22+
workers: process.env.CI ? 1 : undefined,
23+
24+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
25+
reporter: [
26+
['html', { outputFolder: 'tests/playwright-report' }],
27+
['list']
28+
],
29+
30+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
31+
use: {
32+
/* Base URL to use in actions like `await page.goto('/')`. */
33+
baseURL: process.env.TEST_URL || 'http://localhost:5860',
34+
35+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
36+
trace: 'on-first-retry',
37+
38+
/* Screenshot on failure */
39+
screenshot: 'only-on-failure',
40+
41+
/* Video on failure */
42+
video: 'retain-on-failure',
43+
44+
/* Extend timeout for slow remote parquet loading */
45+
actionTimeout: 15000,
46+
navigationTimeout: 60000,
47+
},
48+
49+
/* Configure projects for major browsers */
50+
projects: [
51+
{
52+
name: 'chromium',
53+
use: { ...devices['Desktop Chrome'] },
54+
},
55+
56+
// Uncomment to test on other browsers
57+
// {
58+
// name: 'firefox',
59+
// use: { ...devices['Desktop Firefox'] },
60+
// },
61+
//
62+
// {
63+
// name: 'webkit',
64+
// use: { ...devices['Desktop Safari'] },
65+
// },
66+
67+
/* Test against mobile viewports. */
68+
// {
69+
// name: 'Mobile Chrome',
70+
// use: { ...devices['Pixel 5'] },
71+
// },
72+
// {
73+
// name: 'Mobile Safari',
74+
// use: { ...devices['iPhone 12'] },
75+
// },
76+
],
77+
78+
/* Run your local dev server before starting the tests */
79+
// webServer: {
80+
// command: 'quarto preview tutorials/parquet_cesium.qmd --no-browser',
81+
// url: 'http://localhost:5860',
82+
// timeout: 120 * 1000,
83+
// reuseExistingServer: !process.env.CI,
84+
// },
85+
});

tests/README.md

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
# iSamples Testing Infrastructure
2+
3+
Automated tests for the iSamples Cesium tutorial UI using Playwright.
4+
5+
## Setup
6+
7+
### Install Dependencies
8+
9+
```bash
10+
npm install
11+
npx playwright install chromium
12+
```
13+
14+
### Start Development Server
15+
16+
Before running tests, start the Quarto preview server:
17+
18+
```bash
19+
quarto preview tutorials/parquet_cesium.qmd --no-browser
20+
```
21+
22+
This will typically start on `http://localhost:5860` (port may vary).
23+
24+
## Running Tests
25+
26+
### Run All Tests
27+
28+
```bash
29+
npx playwright test
30+
```
31+
32+
### Run Specific Test File
33+
34+
```bash
35+
npx playwright test tests/playwright/cesium-queries.spec.js
36+
```
37+
38+
### Run in UI Mode (Interactive)
39+
40+
```bash
41+
npx playwright test --ui
42+
```
43+
44+
### Run with Browser Visible
45+
46+
```bash
47+
npx playwright test --headed
48+
```
49+
50+
### Run Specific Test
51+
52+
```bash
53+
npx playwright test -g "shows HTML table"
54+
```
55+
56+
## Test Structure
57+
58+
```
59+
tests/
60+
├── playwright/
61+
│ └── cesium-queries.spec.js # Cesium UI tests
62+
└── README.md # This file
63+
```
64+
65+
## What's Tested
66+
67+
### Cesium Query Results UI (`cesium-queries.spec.js`)
68+
69+
Tests the HTML table UI for all three query paths:
70+
71+
1. **Eric's Query** (Path 1 only, authoritative)
72+
2. **Path 1 Query** (direct event location)
73+
3. **Path 2 Query** (via site location)
74+
75+
#### Test Coverage
76+
77+
- ✅ Page loads and shows geocode search box
78+
- ✅ Geocode search triggers camera movement
79+
- ✅ HTML tables render with correct 5-column structure
80+
- ✅ Tables contain clickable sample PID links
81+
- ✅ Tables contain "View site" links
82+
- ✅ Tables show thumbnails or "No image" placeholders
83+
- ✅ Result counts display correctly
84+
- ✅ Empty states show friendly messages
85+
- ✅ Tables are scrollable with sticky headers
86+
- ✅ Zebra-striped rows for readability
87+
- ✅ Visual consistency across all three tables
88+
89+
#### Test Data
90+
91+
**Location with samples** (PKAP):
92+
- `geoloc_04d6e816218b1a8798fa90b3d1d43bf4c043a57f`
93+
- Returns ~5 samples via Path 1
94+
95+
**Location without samples** (Larnaka site marker):
96+
- `geoloc_7a05216d388682536f3e2abd8bd2ee3fb286e461`
97+
- Returns 0 samples (tests empty state)
98+
99+
## Test Reports
100+
101+
After running tests, view the HTML report:
102+
103+
```bash
104+
npx playwright show-report tests/playwright-report
105+
```
106+
107+
## Debugging
108+
109+
### Take Screenshots
110+
111+
Tests automatically capture screenshots on failure.
112+
113+
### View Traces
114+
115+
For failed tests with retries:
116+
117+
```bash
118+
npx playwright show-trace tests/playwright-report/trace.zip
119+
```
120+
121+
### Debug Mode
122+
123+
Run tests in debug mode with Playwright Inspector:
124+
125+
```bash
126+
npx playwright test --debug
127+
```
128+
129+
## Configuration
130+
131+
Test configuration is in `playwright.config.js`:
132+
133+
- **Test directory**: `./tests/playwright`
134+
- **Base URL**: `http://localhost:5860` (configurable via `TEST_URL` env var)
135+
- **Timeouts**: Extended for remote parquet loading
136+
- **Reporters**: HTML + list
137+
- **Screenshots**: On failure
138+
- **Video**: On failure
139+
140+
### Environment Variables
141+
142+
Set custom test URL:
143+
144+
```bash
145+
TEST_URL=http://localhost:3000 npx playwright test
146+
```
147+
148+
## Continuous Integration
149+
150+
Tests are designed to run on CI with:
151+
152+
```bash
153+
# Start Quarto preview in background
154+
quarto preview tutorials/parquet_cesium.qmd --no-browser &
155+
156+
# Wait for server to start
157+
sleep 10
158+
159+
# Run tests
160+
npx playwright test
161+
162+
# CI will automatically retry failed tests 2x
163+
```
164+
165+
## Adding New Tests
166+
167+
### Test File Template
168+
169+
```javascript
170+
const { test, expect } = require('@playwright/test');
171+
172+
test.describe('Feature Name', () => {
173+
174+
test.beforeEach(async ({ page }) => {
175+
await page.goto('/tutorials/parquet_cesium.html');
176+
// Add setup code
177+
});
178+
179+
test('should do something', async ({ page }) => {
180+
// Test code
181+
await expect(page.locator('selector')).toBeVisible();
182+
});
183+
});
184+
```
185+
186+
### Best Practices
187+
188+
1. **Use descriptive test names** - "Table shows result counts" not "test 1"
189+
2. **Wait for data loading** - Remote parquet queries can be slow
190+
3. **Test user workflows** - Not implementation details
191+
4. **Use `test.describe` blocks** - Group related tests
192+
5. **Keep tests independent** - Each test should work alone
193+
6. **Use page objects** - For complex selectors (future enhancement)
194+
195+
## Known Issues
196+
197+
### Remote Parquet Loading
198+
199+
The remote parquet file (~700MB) can take time to load. Tests include generous timeouts:
200+
201+
- Action timeout: 15 seconds
202+
- Navigation timeout: 60 seconds
203+
- Additional `waitForTimeout` calls where needed
204+
205+
### Observable Cell Evaluation
206+
207+
Observable cells may not evaluate immediately after page load. Tests wait for specific UI elements before interacting.
208+
209+
## Future Enhancements
210+
211+
- [ ] Add visual regression tests (screenshots comparison)
212+
- [ ] Test mobile responsive layouts
213+
- [ ] Test keyboard navigation
214+
- [ ] Test accessibility (ARIA labels, screen readers)
215+
- [ ] Add performance metrics (query execution time)
216+
- [ ] Page object pattern for cleaner test code
217+
- [ ] API mocking to speed up tests (mock parquet responses)
218+
- [ ] Cross-browser testing (Firefox, Safari)
219+
220+
## Maintenance
221+
222+
### Updating Test Data
223+
224+
If test geocode IDs change, update constants in `cesium-queries.spec.js`:
225+
226+
```javascript
227+
const TEST_GEOCODE_WITH_SAMPLES = 'geoloc_...';
228+
const TEST_GEOCODE_NO_SAMPLES = 'geoloc_...';
229+
```
230+
231+
### Updating Selectors
232+
233+
If UI structure changes, update locators in tests:
234+
235+
```javascript
236+
// Before
237+
page.locator('text=Old Label')
238+
239+
// After
240+
page.locator('text=New Label')
241+
```
242+
243+
## Resources
244+
245+
- [Playwright Documentation](https://playwright.dev/)
246+
- [Playwright Test API](https://playwright.dev/docs/api/class-test)
247+
- [Playwright Best Practices](https://playwright.dev/docs/best-practices)
248+
- [Quarto Documentation](https://quarto.org/)

0 commit comments

Comments
 (0)