|
38 | 38 | .test-container{ |
39 | 39 | font-family: monospace; |
40 | 40 | } |
| 41 | + .test-checkbox-container{ |
| 42 | + display: flex; |
| 43 | + align-items: center; |
| 44 | + } |
41 | 45 | .test-container:hover{ |
42 | 46 | background-color: #f0f0f0; |
43 | 47 | } |
|
47 | 51 | .test-container input{ |
48 | 52 | float: left; |
49 | 53 | } |
| 54 | + .test-run-button { |
| 55 | + margin-left: 10px; |
| 56 | + background-color: #4c84af; |
| 57 | + border: none; |
| 58 | + color: white; |
| 59 | + padding: 5px 10px; |
| 60 | + text-align: center; |
| 61 | + text-decoration: none; |
| 62 | + display: inline-block; |
| 63 | + font-size: 12px; |
| 64 | + cursor: pointer; |
| 65 | + border-radius: 3px; |
| 66 | + opacity: 0; |
| 67 | + transition: opacity 0.2s ease; |
| 68 | + } |
| 69 | + .test-container:hover .test-run-button { |
| 70 | + opacity: 1; |
| 71 | + } |
| 72 | + .test-run-button:hover { |
| 73 | + background-color: #3a6a8a; |
| 74 | + } |
| 75 | + .test-run-button:disabled { |
| 76 | + background-color: #999; |
| 77 | + cursor: not-allowed; |
| 78 | + opacity: 1; |
| 79 | + } |
| 80 | + .test-run-button:disabled:hover { |
| 81 | + background-color: #999; |
| 82 | + } |
50 | 83 | </style> |
51 | 84 | <script> |
52 | 85 | document.addEventListener("DOMContentLoaded", () => { |
|
77 | 110 | $('#tests').append('<h2>File System Tests</h2>'); |
78 | 111 | for (let i = 0; i < fsTests.length; i++) { |
79 | 112 | $('#tests').append(`<div class="test-container" id="fsTests-container-${i}"> |
80 | | - <input type="checkbox" class="test-checkbox" id="fsTests${i}" checked> |
81 | | - <label for="fsTests${i}">${fsTests[i].name}</label><br> |
| 113 | + <div class="test-checkbox-container"> |
| 114 | + <input type="checkbox" class="test-checkbox" id="fsTests${i}" checked> |
| 115 | + <label for="fsTests${i}">${fsTests[i].name}</label><br> |
| 116 | + <button class="test-run-button" onclick="runSingleTest('fs', ${i})">Run Test</button> |
| 117 | + </div> |
82 | 118 | </div>`); |
83 | 119 | } |
84 | 120 |
|
85 | 121 | $('#tests').append('<h2>Key Value Tests</h2>'); |
86 | 122 | for (let i = 0; i < kvTests.length; i++) { |
87 | 123 | $('#tests').append(`<div class="test-container" id="kvTests-container-${i}"> |
88 | | - <input type="checkbox" class="test-checkbox" id="kvTests${i}" checked> |
89 | | - <label for="kvTests${i}">${kvTests[i].name}</label><br> |
| 124 | + <div class="test-checkbox-container"> |
| 125 | + <input type="checkbox" class="test-checkbox" id="kvTests${i}" checked> |
| 126 | + <label for="kvTests${i}">${kvTests[i].name}</label><br> |
| 127 | + <button class="test-run-button" onclick="runSingleTest('kv', ${i})">Run Test</button> |
| 128 | + </div> |
90 | 129 | </div>`); |
91 | 130 | } |
92 | 131 |
|
93 | 132 | $('#tests').append('<h2>AI Tests</h2>'); |
94 | 133 | for (let i = 0; i < aiTests.length; i++) { |
95 | 134 | $('#tests').append(`<div class="test-container" id="aiTests-container-${i}"> |
96 | | - <input type="checkbox" class="test-checkbox" id="aiTests${i}" checked> |
97 | | - <label for="aiTests${i}">${aiTests[i].name}</label><br> |
| 135 | + <div class="test-checkbox-container"> |
| 136 | + <input type="checkbox" class="test-checkbox" id="aiTests${i}" checked> |
| 137 | + <label for="aiTests${i}">${aiTests[i].name}</label><br> |
| 138 | + <button class="test-run-button" onclick="runSingleTest('ai', ${i})">Run Test</button> |
| 139 | + </div> |
98 | 140 | </div>`); |
99 | 141 | } |
100 | 142 |
|
|
104 | 146 | } |
105 | 147 | } |
106 | 148 |
|
| 149 | + async function runSingleTest(testType, index) { |
| 150 | + const testSuites = { |
| 151 | + 'fs': fsTests, |
| 152 | + 'kv': kvTests, |
| 153 | + 'ai': aiTests |
| 154 | + }; |
| 155 | + |
| 156 | + const tests = testSuites[testType]; |
| 157 | + const containerId = `${testType}Tests-container-${index}`; |
| 158 | + const buttonSelector = `#${containerId} .test-run-button`; |
| 159 | + |
| 160 | + // Disable the button and show it while running |
| 161 | + $(buttonSelector).prop('disabled', true).text('Running...'); |
| 162 | + |
| 163 | + // Clear previous results |
| 164 | + $(`#${containerId}`).css('background-color', ''); |
| 165 | + $(`#${containerId} pre`).remove(); |
| 166 | + |
| 167 | + try { |
| 168 | + await tests[index](); |
| 169 | + // make this test's container green |
| 170 | + $(`#${containerId}`).css('background-color', '#85e085'); |
| 171 | + } catch (e) { |
| 172 | + console.error(`${testType.toUpperCase()} Test failed:`, tests[index].name, e); |
| 173 | + // make this test's container red |
| 174 | + $(`#${containerId}`).css('background-color', '#ffbfbf'); |
| 175 | + // message - show full error information including JSON details |
| 176 | + let errorMessage = e.message || e.toString(); |
| 177 | + if (e.originalError) { |
| 178 | + errorMessage += '\n\nOriginal Error:\n' + JSON.stringify(e.originalError, null, 2); |
| 179 | + } |
| 180 | + $(`#${containerId}`).append(`<pre style="color:#c00000; white-space: pre-wrap; font-size: 12px; margin: 5px 0; padding: 10px; background-color: #f8f8f8; border-radius: 3px;">${errorMessage}</pre>`); |
| 181 | + } finally { |
| 182 | + // Re-enable the button |
| 183 | + $(buttonSelector).prop('disabled', false).text('Run Test'); |
| 184 | + } |
| 185 | + } |
| 186 | + |
| 187 | + window.runSingleTest = runSingleTest; |
| 188 | + |
107 | 189 | async function runTests() { |
108 | 190 | // go through fsTests and run each test |
109 | 191 | for (let i = 0; i < fsTests.length; i++) { |
|
0 commit comments