|
37 | 37 | tab_until_focused, |
38 | 38 | ) |
39 | 39 |
|
40 | | -NUM_SLIDER_WIDGETS = 30 |
| 40 | +NUM_SLIDER_WIDGETS = 36 |
41 | 41 |
|
42 | 42 |
|
43 | 43 | def test_slider_rendering(themed_app: Page, assert_snapshot: ImageCompareFunction): |
@@ -258,8 +258,8 @@ def test_slider_works_with_fragments(app: Page): |
258 | 258 | def test_slider_with_float_formatting(app: Page, assert_snapshot: ImageCompareFunction): |
259 | 259 | slider = get_slider(app, "Slider 11 (formatted float)") |
260 | 260 | slider.hover() |
261 | | - # click in middle |
262 | 261 | app.mouse.down() |
| 262 | + app.mouse.up() |
263 | 263 |
|
264 | 264 | # Move slider once to right |
265 | 265 | app.keyboard.press("ArrowRight") |
@@ -487,3 +487,127 @@ def test_slider_query_param_empty_value_rejected(page: Page, app_base_url: str): |
487 | 487 | # Slider should use default (50), empty param should be cleared |
488 | 488 | expect_prefixed_markdown(page, "Bound int value:", "50") |
489 | 489 | expect(page).not_to_have_url(re.compile(r"[?&]bound_int=")) |
| 490 | + |
| 491 | + |
| 492 | +# --- Date/time/datetime slider ISO URL tests --- |
| 493 | + |
| 494 | + |
| 495 | +def test_slider_query_param_date_iso_seeding(page: Page, app_base_url: str): |
| 496 | + """Test that a date slider can be seeded with an ISO date string.""" |
| 497 | + page.goto(build_app_url(app_base_url, query={"bound_date": "2024-03-20"})) |
| 498 | + wait_for_app_loaded(page) |
| 499 | + |
| 500 | + expect_prefixed_markdown(page, "Bound date value:", "2024-03-20") |
| 501 | + expect(page).to_have_url(re.compile(r"bound_date=2024-03-20")) |
| 502 | + |
| 503 | + |
| 504 | +def test_slider_query_param_time_iso_seeding(page: Page, app_base_url: str): |
| 505 | + """Test that a time slider can be seeded with an ISO time string.""" |
| 506 | + page.goto(build_app_url(app_base_url, query={"bound_time": "09:30"})) |
| 507 | + wait_for_app_loaded(page) |
| 508 | + |
| 509 | + expect_prefixed_markdown(page, "Bound time value:", "09:30:00") |
| 510 | + expect(page).to_have_url(re.compile(r"bound_time=09%3A30")) |
| 511 | + |
| 512 | + |
| 513 | +def test_slider_query_param_datetime_iso_seeding(page: Page, app_base_url: str): |
| 514 | + """Test that a datetime slider can be seeded with an ISO datetime string.""" |
| 515 | + page.goto(build_app_url(app_base_url, query={"bound_datetime": "2024-03-20T09:30"})) |
| 516 | + wait_for_app_loaded(page) |
| 517 | + |
| 518 | + expect_prefixed_markdown(page, "Bound datetime value:", "2024-03-20 09:30:00") |
| 519 | + expect(page).to_have_url(re.compile(r"bound_datetime=2024-03-20T09%3A30")) |
| 520 | + |
| 521 | + |
| 522 | +def test_slider_query_param_date_range_iso_seeding(page: Page, app_base_url: str): |
| 523 | + """Test that a date range slider can be seeded with ISO date strings.""" |
| 524 | + page.goto( |
| 525 | + build_app_url( |
| 526 | + app_base_url, |
| 527 | + query={"bound_date_range": ["2021-06-01", "2023-12-15"]}, |
| 528 | + ) |
| 529 | + ) |
| 530 | + wait_for_app_loaded(page) |
| 531 | + |
| 532 | + expect_prefixed_markdown( |
| 533 | + page, |
| 534 | + "Bound date range value:", |
| 535 | + "(datetime.date(2021, 6, 1), datetime.date(2023, 12, 15))", |
| 536 | + ) |
| 537 | + expect(page).to_have_url( |
| 538 | + re.compile(r"bound_date_range=2021-06-01&bound_date_range=2023-12-15") |
| 539 | + ) |
| 540 | + |
| 541 | + |
| 542 | +def test_slider_query_param_date_default_not_in_url(app: Page): |
| 543 | + """Test that a date slider at its default value does not show in URL.""" |
| 544 | + expect(app).not_to_have_url(re.compile(r"[?&]bound_date=")) |
| 545 | + |
| 546 | + |
| 547 | +def test_slider_query_param_date_invalid_iso_resets(page: Page, app_base_url: str): |
| 548 | + """Test that an invalid ISO date resets the slider to default.""" |
| 549 | + page.goto(build_app_url(app_base_url, query={"bound_date": "not-a-date"})) |
| 550 | + wait_for_app_loaded(page) |
| 551 | + |
| 552 | + expect_prefixed_markdown(page, "Bound date value:", "2023-06-15") |
| 553 | + expect(page).not_to_have_url(re.compile(r"[?&]bound_date=")) |
| 554 | + |
| 555 | + |
| 556 | +def test_slider_query_param_date_updates_url_with_iso(app: Page): |
| 557 | + """Test that interacting with a date slider updates the URL with ISO format.""" |
| 558 | + slider = get_element_by_key(app, "bound_date") |
| 559 | + slider.get_by_role("slider").press("ArrowRight") |
| 560 | + wait_for_app_run(app) |
| 561 | + |
| 562 | + expect_prefixed_markdown(app, "Bound date value:", "2023-06-16") |
| 563 | + expect(app).to_have_url(re.compile(r"bound_date=2023-06-16")) |
| 564 | + |
| 565 | + |
| 566 | +def test_slider_query_param_time_updates_url_with_iso(app: Page): |
| 567 | + """Test that interacting with a time slider updates the URL with ISO format.""" |
| 568 | + slider = get_element_by_key(app, "bound_time") |
| 569 | + slider.get_by_role("slider").press("ArrowRight") |
| 570 | + wait_for_app_run(app) |
| 571 | + |
| 572 | + expect_prefixed_markdown(app, "Bound time value:", "12:15:00") |
| 573 | + expect(app).to_have_url(re.compile(r"bound_time=12%3A15")) |
| 574 | + |
| 575 | + |
| 576 | +def test_slider_query_param_datetime_updates_url_with_iso(app: Page): |
| 577 | + """Test that interacting with a datetime slider updates the URL with ISO format. |
| 578 | +
|
| 579 | + The default (2023-06-15 14:30) is between step boundaries (step=1day from |
| 580 | + midnight). BaseWeb quantizes to the nearest boundary on interaction, so |
| 581 | + ArrowRight produces 2023-06-17 00:00 rather than 2023-06-16 14:30. |
| 582 | + """ |
| 583 | + slider = get_element_by_key(app, "bound_datetime") |
| 584 | + slider.get_by_role("slider").press("ArrowRight") |
| 585 | + wait_for_app_run(app) |
| 586 | + |
| 587 | + expect_prefixed_markdown(app, "Bound datetime value:", "2023-06-17 00:00:00") |
| 588 | + expect(app).to_have_url(re.compile(r"bound_datetime=2023-06-17T00%3A00")) |
| 589 | + |
| 590 | + |
| 591 | +# --- Second-resolution slider tests --- |
| 592 | + |
| 593 | + |
| 594 | +def test_slider_query_param_time_seconds_iso_seeding(page: Page, app_base_url: str): |
| 595 | + """Test that a time slider with seconds-step can be seeded with HH:MM:SS.""" |
| 596 | + page.goto(build_app_url(app_base_url, query={"bound_time_secs": "09:30:30"})) |
| 597 | + wait_for_app_loaded(page) |
| 598 | + |
| 599 | + expect_prefixed_markdown(page, "Bound time secs value:", "09:30:30") |
| 600 | + expect(page).to_have_url(re.compile(r"bound_time_secs=09%3A30%3A30")) |
| 601 | + |
| 602 | + |
| 603 | +def test_slider_query_param_datetime_seconds_iso_seeding(page: Page, app_base_url: str): |
| 604 | + """Test that a datetime slider with seconds-step can be seeded with seconds.""" |
| 605 | + page.goto( |
| 606 | + build_app_url( |
| 607 | + app_base_url, query={"bound_datetime_secs": "2024-03-20T09:30:30"} |
| 608 | + ) |
| 609 | + ) |
| 610 | + wait_for_app_loaded(page) |
| 611 | + |
| 612 | + expect_prefixed_markdown(page, "Bound datetime secs value:", "2024-03-20 09:30:30") |
| 613 | + expect(page).to_have_url(re.compile(r"bound_datetime_secs=2024-03-20T09%3A30%3A30")) |
0 commit comments