Skip to content

Commit 8d506ea

Browse files
committed
refactor: convert KDMA sliders to dropdown selects
- Replace range input sliders with select dropdowns for KDMA values - Update event handler from handleRunKDMASliderInput to handleRunKDMAValueChange - Remove slider-specific CSS and add dropdown styling - Update all tests to use select_option() instead of fill() for dropdowns - Remove redundant test_kdma_warning_system test - Preserve test intent while adapting for dropdown behavior
1 parent fdf1178 commit 8d506ea

5 files changed

Lines changed: 218 additions & 265 deletions

File tree

align_browser/static/app.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -490,25 +490,18 @@ document.addEventListener("DOMContentLoaded", () => {
490490
});
491491
};
492492

493-
window.handleRunKDMASliderInput = async function(runId, kdmaType, sliderElement) {
493+
window.handleRunKDMAValueChange = async function(runId, kdmaType, value) {
494494
const run = appState.pinnedRuns.get(runId);
495495
if (!run) return;
496496

497-
const normalizedValue = KDMAUtils.normalizeValue(sliderElement.value);
497+
const normalizedValue = KDMAUtils.normalizeValue(value);
498498

499-
// Update the display value immediately for responsiveness
500-
const valueDisplay = document.getElementById(`kdma-value-${runId}-${kdmaType}`);
501-
if (valueDisplay) {
502-
valueDisplay.textContent = KDMAUtils.formatValue(normalizedValue);
503-
}
504-
505-
// Update the KDMA values with debouncing
499+
// Update the KDMA values
506500
await updateKDMAsForRun(runId, (kdmas) => ({
507501
...kdmas,
508502
[kdmaType]: normalizedValue
509503
}), {
510-
updateURL: true,
511-
debounceMs: KDMA_SLIDER_DEBOUNCE_MS // Debounce to avoid too many requests while sliding
504+
updateURL: true
512505
});
513506
};
514507

align_browser/static/style.css

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -550,53 +550,15 @@ footer {
550550
box-shadow: 0 0 0 1px rgba(220, 53, 69, 0.25);
551551
}
552552

553-
/* KDMA slider styling for table cells */
554-
.table-kdma-value-slider {
555-
-webkit-appearance: none;
556-
appearance: none;
557-
min-width: 50px;
558-
width: 80px;
559-
flex: 0 1 80px;
560-
height: 4px;
561-
background: #ddd;
562-
outline: none;
563-
opacity: 0.9;
564-
transition: opacity 0.2s;
565-
border-radius: 4px;
566-
}
567-
568-
.table-kdma-value-slider:hover {
569-
opacity: 1;
570-
}
571-
572-
.table-kdma-value-slider::-webkit-slider-thumb {
573-
-webkit-appearance: none;
574-
appearance: none;
575-
width: 16px;
576-
height: 16px;
577-
background: var(--accent-color);
578-
cursor: pointer;
579-
border-radius: 50%;
580-
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
581-
}
582-
583-
.table-kdma-value-slider::-moz-range-thumb {
584-
width: 16px;
585-
height: 16px;
586-
background: var(--accent-color);
587-
cursor: pointer;
588-
border-radius: 50%;
589-
border: none;
590-
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
591-
}
592-
593-
.table-kdma-value-display {
594-
min-width: 24px;
595-
text-align: center;
596-
color: #495057;
597-
font-weight: 600;
598-
font-size: 11px;
599-
flex-shrink: 0;
553+
/* KDMA value dropdown styling for table cells */
554+
.table-kdma-value-select {
555+
min-width: 80px;
556+
padding: 2px 4px;
557+
border: 1px solid #ddd;
558+
border-radius: 3px;
559+
background-color: white;
560+
font-size: 12px;
561+
flex: 0 1 auto;
600562
}
601563

602564
/* Notification system styles */

align_browser/static/table-formatter.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -820,13 +820,13 @@ export function createSingleKDMAControlForRun(runId, kdmaType, value, pinnedRuns
820820
).join('')}
821821
</select>
822822
823-
<input type="range"
824-
class="table-kdma-value-slider"
825-
id="kdma-slider-${runId}-${kdmaType}"
826-
min="${minVal}" max="${maxVal}" step="${step}"
827-
value="${value}"
828-
oninput="handleRunKDMASliderInput('${runId}', '${kdmaType}', this)">
829-
<span class="table-kdma-value-display" id="kdma-value-${runId}-${kdmaType}">${formatKDMAValue(value)}</span>
823+
<select class="table-kdma-value-select"
824+
id="kdma-value-${runId}-${kdmaType}"
825+
onchange="handleRunKDMAValueChange('${runId}', '${kdmaType}', this.value)">
826+
${validValues.map(val =>
827+
`<option value="${val}" ${Math.abs(val - value) < FLOATING_POINT_TOLERANCE ? 'selected' : ''}>${formatKDMAValue(val)}</option>`
828+
).join('')}
829+
</select>
830830
831831
<button class="table-kdma-remove-btn"
832832
onclick="removeKDMAFromRun('${runId}', '${kdmaType}')"

align_browser/test_frontend.py

Lines changed: 59 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -221,22 +221,23 @@ def test_kdma_type_filtering_prevents_duplicates(page, real_data_test_server):
221221
# Wait for any updates instead of fixed timeout
222222
page.wait_for_load_state("networkidle")
223223

224-
# Check KDMA sliders in table
225-
kdma_sliders = page.locator(".table-kdma-value-slider")
226-
slider_count = kdma_sliders.count()
224+
# Check KDMA value dropdowns in table
225+
kdma_dropdowns = page.locator(".table-kdma-value-select")
226+
dropdown_count = kdma_dropdowns.count()
227227

228-
# KDMA sliders may or may not be available depending on selected ADM type
229-
print(f"Found {slider_count} KDMA sliders for ADM: {selected_option}")
228+
# KDMA dropdowns may or may not be available depending on selected ADM type
229+
print(f"Found {dropdown_count} KDMA dropdowns for ADM: {selected_option}")
230230

231-
# Test that KDMA sliders are functional
232-
if slider_count > 0:
233-
first_slider = kdma_sliders.first
234-
expect(first_slider).to_be_visible()
231+
# Test that KDMA dropdowns are functional
232+
if dropdown_count > 0:
233+
first_dropdown = kdma_dropdowns.first
234+
expect(first_dropdown).to_be_visible()
235235

236-
# Test slider functionality
237-
first_slider.fill("0.5")
238-
page.wait_for_timeout(500)
239-
assert first_slider.input_value() == "0.5", "KDMA slider should be functional"
236+
# Test dropdown interaction - select first available option that's different from current
237+
options = first_dropdown.locator("option").all_text_contents()
238+
if len(options) > 1:
239+
first_dropdown.select_option(index=1)
240+
page.wait_for_timeout(500)
240241

241242

242243
def test_kdma_max_limit_enforcement(page, real_data_test_server):
@@ -266,30 +267,29 @@ def test_kdma_max_limit_enforcement(page, real_data_test_server):
266267
# Wait for any updates instead of fixed timeout
267268
page.wait_for_load_state("networkidle")
268269

269-
# Test that KDMA sliders are present and functional
270-
kdma_sliders = page.locator(".table-kdma-value-slider")
271-
slider_count = kdma_sliders.count()
272-
273-
# Test passes regardless of KDMA slider availability - depends on selected ADM
274-
print(f"Found {slider_count} KDMA sliders for ADM: {selected_option}")
275-
276-
# Test slider functionality
277-
if slider_count > 0:
278-
first_slider = kdma_sliders.first
279-
expect(first_slider).to_be_visible()
280-
first_slider.fill("0.3")
281-
# Wait for value to update
282-
page.wait_for_function(
283-
"document.querySelector('.table-kdma-value-slider').value === '0.3'"
284-
)
285-
assert first_slider.input_value() == "0.3", "KDMA slider should be functional"
270+
# Test that KDMA dropdowns are present and functional
271+
kdma_dropdowns = page.locator(".table-kdma-value-select")
272+
dropdown_count = kdma_dropdowns.count()
273+
274+
# Test passes regardless of KDMA dropdown availability - depends on selected ADM
275+
print(f"Found {dropdown_count} KDMA dropdowns for ADM: {selected_option}")
276+
277+
# Test dropdown functionality
278+
if dropdown_count > 0:
279+
first_dropdown = kdma_dropdowns.first
280+
expect(first_dropdown).to_be_visible()
281+
# Get available options and select a different one if possible
282+
options = first_dropdown.locator("option").all_text_contents()
283+
if len(options) > 1:
284+
first_dropdown.select_option(index=1)
285+
page.wait_for_timeout(500)
286286

287287
# Verify table continues to work after changes
288288
expect(page.locator(".comparison-table")).to_be_visible()
289289

290290

291291
def test_kdma_removal_updates_constraints(page, real_data_test_server):
292-
"""Test that KDMA sliders are functional in table-based UI."""
292+
"""Test that KDMA dropdowns are functional in table-based UI."""
293293
page.goto(real_data_test_server)
294294

295295
# Wait for page to load
@@ -311,70 +311,30 @@ def test_kdma_removal_updates_constraints(page, real_data_test_server):
311311
adm_select.select_option(adm_options[0])
312312
page.wait_for_timeout(1000)
313313

314-
# Check for KDMA sliders in the table
315-
kdma_sliders = page.locator(".table-kdma-value-slider")
316-
initial_slider_count = kdma_sliders.count()
314+
# Check for KDMA dropdowns in the table
315+
kdma_dropdowns = page.locator(".table-kdma-value-select")
316+
initial_dropdown_count = kdma_dropdowns.count()
317317

318-
if initial_slider_count > 0:
319-
# Test that sliders are functional
320-
first_slider = kdma_sliders.first
321-
expect(first_slider).to_be_visible()
318+
if initial_dropdown_count > 0:
319+
# Test that dropdowns are functional
320+
first_dropdown = kdma_dropdowns.first
321+
expect(first_dropdown).to_be_visible()
322322

323-
# Test changing slider value
324-
first_slider.fill("0.5")
325-
# Wait for value to update
326-
page.wait_for_function(
327-
"document.querySelector('.table-kdma-value-slider').value === '0.5'"
328-
)
323+
# Select different option if available
324+
options = first_dropdown.locator("option").all_text_contents()
325+
if len(options) > 1:
326+
first_dropdown.select_option(index=1)
327+
page.wait_for_timeout(500)
329328

330-
# Verify slider value updated
331-
assert first_slider.input_value() == "0.5", "KDMA slider should update value"
329+
# Verify dropdown value updated
330+
assert first_dropdown.locator("option:checked").count() == 1, (
331+
"KDMA dropdown should have selected value"
332+
)
332333

333334
# Verify table still functions
334335
expect(page.locator(".comparison-table")).to_be_visible()
335336

336337

337-
def test_kdma_warning_system(page, real_data_test_server):
338-
"""Test that KDMA warning system shows for invalid values."""
339-
page.goto(real_data_test_server)
340-
341-
# Wait for page to load
342-
page.wait_for_selector(".comparison-table", timeout=10000)
343-
page.wait_for_function(
344-
"document.querySelectorAll('.table-adm-select').length > 0", timeout=10000
345-
)
346-
347-
# Select ADM and add KDMA
348-
# Use available ADM option from test data
349-
adm_select = page.locator(".table-adm-select").first
350-
available_options = adm_select.locator("option").all()
351-
adm_options = [
352-
opt.get_attribute("value")
353-
for opt in available_options
354-
if opt.get_attribute("value")
355-
]
356-
if adm_options:
357-
adm_select.select_option(adm_options[0])
358-
page.wait_for_timeout(1000)
359-
360-
# Check for KDMA sliders in the table
361-
kdma_sliders = page.locator(".table-kdma-value-slider")
362-
363-
if kdma_sliders.count() > 0:
364-
# Get first KDMA slider
365-
slider = kdma_sliders.first
366-
367-
# Test slider functionality
368-
slider.fill("0.5")
369-
# Wait for value to update
370-
371-
# Verify slider works
372-
assert slider.input_value() == "0.5", "KDMA slider should accept valid values"
373-
else:
374-
# Skip test if no KDMA sliders available
375-
pass
376-
377-
378338
def test_kdma_adm_change_resets_properly(page, real_data_test_server):
379339
"""Test that changing ADM type properly updates available controls."""
380340
page.goto(real_data_test_server)
@@ -475,19 +435,21 @@ def test_scenario_based_kdma_filtering(page, real_data_test_server):
475435
adm_select.select_option(selected_option)
476436
page.wait_for_load_state("networkidle")
477437

478-
# Check what KDMA sliders are available in table
479-
kdma_sliders = page.locator(".table-kdma-value-slider")
480-
slider_count = kdma_sliders.count()
438+
# Check what KDMA dropdowns are available in table
439+
kdma_dropdowns = page.locator(".table-kdma-value-select")
440+
dropdown_count = kdma_dropdowns.count()
481441

482-
if slider_count > 0:
483-
# For table-based UI, we test slider functionality instead of dropdown selection
484-
first_slider = kdma_sliders.first
485-
first_slider.fill("0.5")
486-
# Wait for updates to complete
487-
page.wait_for_load_state("networkidle")
442+
if dropdown_count > 0:
443+
# For table-based UI, we test dropdown functionality
444+
first_dropdown = kdma_dropdowns.first
445+
options = first_dropdown.locator("option").all_text_contents()
446+
if len(options) > 1:
447+
first_dropdown.select_option(index=1)
448+
# Wait for updates to complete
449+
page.wait_for_load_state("networkidle")
488450

489451
scenario_kdma_mapping[scenario_type] = ["kdma_available"]
490-
print(f" KDMA sliders available: {slider_count}")
452+
print(f" KDMA dropdowns available: {dropdown_count}")
491453

492454
# Check results in table format
493455
expect(page.locator(".comparison-table")).to_be_visible()

0 commit comments

Comments
 (0)