File size: 4,512 Bytes
fb238c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!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>