Skip to content

Commit b4143a6

Browse files
committed
Enhance test UI with master checkbox functionality
- Updated the test UI to include a master checkbox that controls the selection of individual test checkboxes. - Implemented logic to update the master checkbox state based on the selection of individual checkboxes and group checkboxes. - Adjusted the margin for h2 checkboxes for improved layout.
1 parent afa6333 commit b4143a6

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

src/puter-js/test/run.html

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108

109109
/* Style for h2 checkboxes */
110110
#tests h2 input[type="checkbox"] {
111-
margin-right: 10px;
111+
margin-right: 18px;
112112
transform: scale(1.2);
113113
}
114114

@@ -375,14 +375,35 @@
375375
runTests();
376376
});
377377

378-
$('#unselect-all').click(() => {
379-
$('.test-checkbox').prop('checked', false);
380-
$('#fsTests-group, #kvTests-group, #aiTests-group').prop('checked', false).trigger('change');
378+
// Master checkbox functionality
379+
$('#master-checkbox').change(function() {
380+
const isChecked = $(this).prop('checked');
381+
$('.test-checkbox').prop('checked', isChecked);
382+
$('#fsTests-group, #kvTests-group, #aiTests-group').prop('checked', isChecked);
383+
});
384+
385+
// Function to update master checkbox state
386+
function updateMasterCheckboxState() {
387+
const totalCheckboxes = $('.test-checkbox').length;
388+
const checkedCheckboxes = $('.test-checkbox:checked').length;
389+
390+
if (checkedCheckboxes === 0) {
391+
$('#master-checkbox').prop('checked', false).prop('indeterminate', false);
392+
} else if (checkedCheckboxes === totalCheckboxes) {
393+
$('#master-checkbox').prop('checked', true).prop('indeterminate', false);
394+
} else {
395+
$('#master-checkbox').prop('checked', false).prop('indeterminate', true);
396+
}
397+
}
398+
399+
// Update master checkbox state when individual checkboxes change
400+
$(document).on('change', '.test-checkbox', function() {
401+
updateMasterCheckboxState();
381402
});
382403

383-
$('#select-all').click(() => {
384-
$('.test-checkbox').prop('checked', true);
385-
$('#fsTests-group, #kvTests-group, #aiTests-group').prop('checked', true).trigger('change');
404+
// Update master checkbox state when group checkboxes change
405+
$('#fsTests-group, #kvTests-group, #aiTests-group').change(function() {
406+
updateMasterCheckboxState();
386407
});
387408

388409
});
@@ -392,9 +413,10 @@
392413
<body>
393414

394415
<nav style="position: fixed; top: 0; width: 100%; background: #EEE; left: 0; padding-left: 10px;">
416+
<label style="margin-left: 8px; margin-right: 10px; cursor: pointer; display: inline-flex; align-items: center;">
417+
<input type="checkbox" id="master-checkbox" checked style="margin-right: 5px; transform: scale(1.2);">
418+
</label>
395419
<button id="run-tests">Run Tests</button>
396-
<span id="select-all">Select All</span>
397-
<span id="unselect-all">Unselect All</span>
398420
</nav>
399421
<div id="tests"></div>
400422
</body>

0 commit comments

Comments
 (0)