mail / dev /test-split-json.html
enronarchive's picture
Super-squash branch 'main' using huggingface_hub
fb238c5
<!DOCTYPE html>
<html>
<head>
<title>Test Split JSON Loading</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
.test { margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px; }
.pass { background: #d4edda; border-color: #c3e6cb; }
.fail { background: #f8d7da; border-color: #f5c6cb; }
.loading { background: #fff3cd; border-color: #ffeaa7; }
h1 { color: #333; }
h3 { margin-top: 0; }
.details { font-family: monospace; font-size: 12px; margin: 10px 0; }
button { padding: 10px 20px; font-size: 16px; cursor: pointer; }
</style>
</head>
<body>
<h1>🧪 Split JSON Files Test Suite</h1>
<button onclick="runTests()">Run All Tests</button>
<div id="results"></div>
<script>
async function runTests() {
const resultsDiv = document.getElementById('results');
resultsDiv.innerHTML = '';
const tests = [
{ name: 'Test non-split user (south-s)', user: 'south-s', expectedParts: 1 },
{ name: 'Test split user - small (farmer-d)', user: 'farmer-d', expectedParts: 2 },
{ name: 'Test split user - medium (jones-t)', user: 'jones-t', expectedParts: 3 },
{ name: 'Test split user - large (kean-s)', user: 'kean-s', expectedParts: 15 }
];
for (const test of tests) {
await runTest(test);
}
}
async function runTest(test) {
const resultsDiv = document.getElementById('results');
const testDiv = document.createElement('div');
testDiv.className = 'test loading';
testDiv.innerHTML = `<h3>${test.name}</h3><p>Testing...</p>`;
resultsDiv.appendChild(testDiv);
try {
const startTime = Date.now();
// Load index.json
const response = await fetch(`mail/${test.user}/index.json`);
if (!response.ok) {
throw new Error(`Failed to load: ${response.status}`);
}
const data = await response.json();
const totalParts = data.total_parts || 1;
let allEmails = data.emails || [];
// Load additional parts if they exist
if (totalParts > 1) {
for (let i = 2; i <= totalParts; i++) {
const partResponse = await fetch(`/mail/${test.user}/index-part-${i}.json`);
if (partResponse.ok) {
const partData = await partResponse.json();
allEmails = allEmails.concat(partData.emails || []);
}
}
}
const loadTime = Date.now() - startTime;
// Verify results
const passed = totalParts === test.expectedParts;
testDiv.className = passed ? 'test pass' : 'test fail';
testDiv.innerHTML = `
<h3>${passed ? '✅' : '❌'} ${test.name}</h3>
<div class="details">
<strong>Expected parts:</strong> ${test.expectedParts}<br>
<strong>Actual parts:</strong> ${totalParts}<br>
<strong>Total emails loaded:</strong> ${allEmails.length}<br>
<strong>Load time:</strong> ${loadTime}ms<br>
<strong>Status:</strong> ${passed ? 'PASS' : 'FAIL - Part count mismatch'}
</div>
`;
} catch (error) {
testDiv.className = 'test fail';
testDiv.innerHTML = `
<h3>❌ ${test.name}</h3>
<div class="details">
<strong>Error:</strong> ${error.message}<br>
<strong>Status:</strong> FAIL - Exception thrown
</div>
`;
}
}
// Auto-run tests on page load
window.addEventListener('load', () => {
setTimeout(runTests, 500);
});
</script>
</body>
</html>