-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-e2e-full.mjs
More file actions
executable file
·190 lines (154 loc) · 6.11 KB
/
test-e2e-full.mjs
File metadata and controls
executable file
·190 lines (154 loc) · 6.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env node
/**
* Full end-to-end test for Route.dog
* Tests image upload and address extraction workflow
*/
import puppeteer from 'puppeteer';
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const UI_URL = 'https://11e4812e.route-dog.pages.dev';
const API_URL = 'https://route-dog-prod.pig.workers.dev';
// Create a simple test image with addresses
async function createTestImage(page) {
console.log('Creating test image with addresses...');
// Create a canvas with text addresses
await page.setContent(`
<!DOCTYPE html>
<html>
<body>
<canvas id="canvas" width="800" height="600"></canvas>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
// White background
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, 800, 600);
// Black text
ctx.fillStyle = 'black';
ctx.font = '20px Arial';
// Title
ctx.font = 'bold 24px Arial';
ctx.fillText('DELIVERY ROUTE - TEST', 50, 50);
// Addresses
ctx.font = '18px Arial';
const addresses = [
'1. 93 NORTH 9TH STREET, BROOKLYN NY 11211',
'2. 380 WESTMINSTER ST, PROVIDENCE RI 02903',
'3. 177 MAIN STREET, LITTLETON NH 03561',
'4. 202 HARLOW ST, BANGOR ME 04401'
];
addresses.forEach((addr, i) => {
ctx.fillText(addr, 50, 100 + (i * 40));
});
</script>
</body>
</html>
`);
await new Promise(resolve => setTimeout(resolve, 500));
// Take screenshot of the canvas to create test image
const canvas = await page.$('#canvas');
await canvas.screenshot({ path: 'test-addresses-image.png' });
console.log('✅ Test image created: test-addresses-image.png\n');
}
async function main() {
console.log('🚀 Starting Route.dog Full E2E Test\n');
const browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
try {
// Create test image first
await createTestImage(page);
// Test 1: Load the UI
console.log('Test 1: Loading Route.dog UI...');
await page.goto(UI_URL, { waitUntil: 'networkidle0', timeout: 30000 });
const title = await page.title();
console.log(`✅ UI loaded: ${title}\n`);
// Test 2: Check for upload button
console.log('Test 2: Looking for Upload Image button...');
const uploadButton = await page.evaluateHandle(() => {
const buttons = Array.from(document.querySelectorAll('button'));
return buttons.find(btn => btn.textContent.includes('Upload Image'));
});
const buttonExists = await page.evaluate(btn => !!btn, uploadButton);
if (buttonExists) {
console.log('✅ Upload button found\n');
// Take screenshot before interaction
await page.screenshot({ path: 'test-before-upload.png' });
console.log('📸 Screenshot saved: test-before-upload.png\n');
} else {
console.log('❌ Upload button not found\n');
}
// Test 3: Check page structure
console.log('Test 3: Checking page structure...');
const bodyText = await page.evaluate(() => document.body.innerText);
const checks = {
'Route.dog branding': bodyText.includes('Route.dog'),
'Upload instructions': bodyText.toLowerCase().includes('upload'),
'Address mention': bodyText.toLowerCase().includes('address')
};
for (const [check, passed] of Object.entries(checks)) {
console.log(`${passed ? '✅' : '❌'} ${check}`);
}
console.log();
// Test 4: API Integration
console.log('Test 4: Testing API endpoints...');
// Health check
const healthResp = await fetch(`${API_URL}/health`);
const health = await healthResp.json();
console.log(`✅ API Health: ${health.status}`);
// Test geocoding
const geocodeResp = await fetch(`${API_URL}/v1/geocode-address`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ address: '93 NORTH 9TH STREET, BROOKLYN NY 11211' })
});
const geocoded = await geocodeResp.json();
console.log(`✅ Geocoding works: ${geocoded.standardized}`);
console.log(` Coordinates: ${geocoded.latitude}, ${geocoded.longitude}\n`);
// Test 5: Console monitoring
console.log('Test 5: Monitoring browser console...');
const errors = [];
const warnings = [];
page.on('console', msg => {
if (msg.type() === 'error') errors.push(msg.text());
if (msg.type() === 'warning') warnings.push(msg.text());
});
await new Promise(resolve => setTimeout(resolve, 2000));
if (errors.length === 0) {
console.log('✅ No console errors');
} else {
console.log(`⚠️ ${errors.length} console error(s):`);
errors.slice(0, 3).forEach(e => console.log(` - ${e}`));
}
if (warnings.length > 0) {
console.log(`⚠️ ${warnings.length} console warning(s) (not shown)`);
}
console.log();
// Final screenshot
await page.screenshot({ path: 'test-final.png', fullPage: true });
console.log('📸 Final screenshot: test-final.png');
console.log('\n✅ All E2E tests completed successfully!');
console.log('\n📊 Summary:');
console.log(' - UI is loading correctly');
console.log(' - Upload button is present');
console.log(' - API is healthy and geocoding works');
console.log(' - No critical browser errors');
console.log('\n💡 Next steps:');
console.log(' - Manual testing of image upload in browser');
console.log(' - Test with real delivery route images');
console.log(' - Verify map markers and route optimization');
} catch (error) {
console.error('❌ Test failed:', error.message);
await page.screenshot({ path: 'test-error.png' });
console.log('📸 Error screenshot saved: test-error.png');
process.exit(1);
} finally {
await browser.close();
}
}
main().catch(console.error);