-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_frontend_backend_integration.html
More file actions
255 lines (229 loc) · 11.4 KB
/
test_frontend_backend_integration.html
File metadata and controls
255 lines (229 loc) · 11.4 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Frontend-Backend Integration Test</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; background: #f5f5f5; }
.container { max-width: 800px; margin: 0 auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
.test-section { margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 6px; }
.success { background: #d4edda; border-color: #c3e6cb; color: #155724; }
.error { background: #f8d7da; border-color: #f5c6cb; color: #721c24; }
.pending { background: #e2e3e5; border-color: #d6d8db; color: #383d41; }
button { padding: 10px 20px; margin: 5px; border: none; border-radius: 4px; cursor: pointer; }
.btn-primary { background: #007bff; color: white; }
.btn-success { background: #28a745; color: white; }
.btn-danger { background: #dc3545; color: white; }
pre { background: #f8f9fa; padding: 10px; border-radius: 4px; overflow-x: auto; }
.status { font-weight: bold; }
</style>
</head>
<body>
<div class="container">
<h1>🧪 Frontend-Backend Integration Test</h1>
<p>This test verifies that your ChatGPT-inspired frontend can communicate with the MCP backend.</p>
<div id="test-ping" class="test-section pending">
<h3>1. Backend Ping Test</h3>
<p>Testing if the backend server is responding...</p>
<button id="btn-ping" class="btn-primary" onclick="testPing()">Test Ping</button>
<div id="ping-result"></div>
</div>
<div id="test-cors" class="test-section pending">
<h3>2. CORS Configuration Test</h3>
<p>Testing if frontend can make cross-origin requests to backend...</p>
<button id="btn-cors" class="btn-primary" onclick="testCORS()">Test CORS</button>
<div id="cors-result"></div>
</div>
<div id="test-endpoints" class="test-section pending">
<h3>3. API Endpoints Test</h3>
<p>Testing the main API endpoints used by the frontend...</p>
<button id="btn-endpoints" class="btn-primary" onclick="testEndpoints()">Test Endpoints</button>
<div id="endpoints-result"></div>
</div>
<div id="test-frontend" class="test-section pending">
<h3>4. Frontend Accessibility Test</h3>
<p>Verify the React frontend is accessible...</p>
<button id="btn-frontend" class="btn-primary" onclick="testFrontend()">Test Frontend</button>
<div id="frontend-result"></div>
</div>
<div id="summary" class="test-section pending">
<h3>📊 Test Summary</h3>
<div id="summary-content">
<p>Click the test buttons above to run the integration tests.</p>
</div>
</div>
</div>
<script>
const API_BASE = 'http://localhost:8000';
const FRONTEND_URL = 'http://localhost:5173';
let testResults = {
ping: false,
cors: false,
endpoints: false,
frontend: false
};
async function testPing() {
const section = document.getElementById('test-ping');
const result = document.getElementById('ping-result');
try {
const response = await fetch(`${API_BASE}/ping`);
if (response.ok) {
const data = await response.json();
section.className = 'test-section success';
result.innerHTML = `
<p class="status">✅ SUCCESS</p>
<pre>${JSON.stringify(data, null, 2)}</pre>
`;
testResults.ping = true;
} else {
throw new Error(`HTTP ${response.status}`);
}
} catch (error) {
section.className = 'test-section error';
result.innerHTML = `
<p class="status">❌ FAILED</p>
<p>Error: ${error.message}</p>
`;
}
updateSummary();
}
async function testCORS() {
const section = document.getElementById('test-cors');
const result = document.getElementById('cors-result');
try {
// This request will fail if CORS is not properly configured
const response = await fetch(`${API_BASE}/ping`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
}
});
if (response.ok) {
section.className = 'test-section success';
result.innerHTML = `
<p class="status">✅ SUCCESS</p>
<p>CORS is properly configured. Frontend can communicate with backend.</p>
`;
testResults.cors = true;
} else {
throw new Error(`HTTP ${response.status}`);
}
} catch (error) {
section.className = 'test-section error';
result.innerHTML = `
<p class="status">❌ FAILED</p>
<p>CORS Error: ${error.message}</p>
<p>This means the frontend cannot communicate with the backend due to CORS restrictions.</p>
`;
}
updateSummary();
}
async function testEndpoints() {
const section = document.getElementById('test-endpoints');
const result = document.getElementById('endpoints-result');
const endpoints = [
{ name: 'Chat', path: '/chat', method: 'POST', body: { message: 'test', conversation_id: 'test' } },
{ name: 'NL2SQL', path: '/nl2sql', method: 'POST', body: { prompt: 'test query' } }
];
let successCount = 0;
let results = [];
for (const endpoint of endpoints) {
try {
const response = await fetch(`${API_BASE}${endpoint.path}`, {
method: endpoint.method,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(endpoint.body)
});
const status = response.ok ? '✅' : '⚠️';
results.push(`${status} ${endpoint.name}: HTTP ${response.status}`);
if (response.status < 500) successCount++; // Accept even 4xx as "reachable"
} catch (error) {
results.push(`❌ ${endpoint.name}: ${error.message}`);
}
}
if (successCount === endpoints.length) {
section.className = 'test-section success';
testResults.endpoints = true;
} else if (successCount > 0) {
section.className = 'test-section success';
testResults.endpoints = true;
} else {
section.className = 'test-section error';
}
result.innerHTML = `
<p class="status">${successCount === endpoints.length ? '✅ SUCCESS' : successCount > 0 ? '⚠️ PARTIAL' : '❌ FAILED'}</p>
<p>Endpoints reachable: ${successCount}/${endpoints.length}</p>
<ul>${results.map(r => `<li>${r}</li>`).join('')}</ul>
`;
updateSummary();
}
async function testFrontend() {
const section = document.getElementById('test-frontend');
const result = document.getElementById('frontend-result');
try {
const response = await fetch(FRONTEND_URL);
if (response.ok) {
const html = await response.text();
const isReactApp = html.includes('react') || html.includes('vite') || html.includes('root');
if (isReactApp) {
section.className = 'test-section success';
result.innerHTML = `
<p class="status">✅ SUCCESS</p>
<p>React frontend is accessible at <a href="${FRONTEND_URL}" target="_blank">${FRONTEND_URL}</a></p>
<p>The ChatGPT-inspired UI should be loading properly.</p>
`;
testResults.frontend = true;
} else {
throw new Error('Not a React application');
}
} else {
throw new Error(`HTTP ${response.status}`);
}
} catch (error) {
section.className = 'test-section error';
result.innerHTML = `
<p class="status">❌ FAILED</p>
<p>Error: ${error.message}</p>
<p>The frontend development server may not be running.</p>
`;
}
updateSummary();
}
function updateSummary() {
const summary = document.getElementById('summary');
const content = document.getElementById('summary-content');
const totalTests = Object.keys(testResults).length;
const passedTests = Object.values(testResults).filter(Boolean).length;
const allPassed = passedTests === totalTests;
summary.className = `test-section ${allPassed ? 'success' : passedTests > 0 ? 'pending' : 'error'}`;
content.innerHTML = `
<p class="status">${allPassed ? '🎉 ALL TESTS PASSED!' : `📊 ${passedTests}/${totalTests} tests passed`}</p>
<ul>
<li>Backend Ping: ${testResults.ping ? '✅' : '❌'}</li>
<li>CORS Configuration: ${testResults.cors ? '✅' : '❌'}</li>
<li>API Endpoints: ${testResults.endpoints ? '✅' : '❌'}</li>
<li>Frontend Access: ${testResults.frontend ? '✅' : '❌'}</li>
</ul>
${allPassed ? `
<div style="margin-top: 20px; padding: 15px; background: #d1ecf1; border: 1px solid #bee5eb; border-radius: 6px;">
<h4>🚀 Your ChatGPT-inspired MCP Chatbot is ready!</h4>
<p><strong>Frontend:</strong> <a href="${FRONTEND_URL}" target="_blank">${FRONTEND_URL}</a></p>
<p><strong>Backend API:</strong> <a href="${API_BASE}/docs" target="_blank">${API_BASE}/docs</a></p>
<p>Open the frontend link to start chatting with your mutual fund assistant!</p>
</div>
` : ''}
`;
}
// Auto-run tests when page loads
window.addEventListener('load', () => {
setTimeout(() => {
testPing();
setTimeout(() => testCORS(), 500);
setTimeout(() => testEndpoints(), 1000);
setTimeout(() => testFrontend(), 1500);
}, 1000);
});
</script>
</body>
</html>