|
| 1 | + |
1 | 2 | # frozen_string_literal: true
|
2 | 3 |
|
3 | 4 | require "system/test_case"
|
@@ -182,11 +183,12 @@ def test_remembers_selections_on_filter
|
182 | 183 | end
|
183 | 184 |
|
184 | 185 | # Phaser should already be selected
|
185 |
| - assert_selector "[aria-checked=true]", count: 1 |
| 186 | + assert_selector "[aria-checked=true]", text: "Phaser" |
186 | 187 |
|
187 | 188 | click_on "Photon torpedo"
|
188 | 189 |
|
189 |
| - assert_selector "[aria-checked=true]", count: 2 |
| 190 | + assert_selector "[aria-checked=true]", text: "Phaser" |
| 191 | + assert_selector "[aria-checked=true]", text: "Photon torpedo" |
190 | 192 |
|
191 | 193 | wait_for_items_to_load do
|
192 | 194 | filter_results(query: "ph")
|
@@ -382,6 +384,100 @@ def test_single_select_disabled_item_cannot_be_checked
|
382 | 384 | refute_selector "[aria-selected=true]"
|
383 | 385 | end
|
384 | 386 |
|
| 387 | + def test_single_select_does_not_allow_server_to_check_items_on_filter_if_selections_already_made |
| 388 | + # playground is single-select |
| 389 | + visit_preview(:playground) |
| 390 | + |
| 391 | + wait_for_items_to_load do |
| 392 | + click_on_invoker_button |
| 393 | + end |
| 394 | + |
| 395 | + # Phaser should already be selected |
| 396 | + assert_selector "[aria-selected=true]", text: "Phaser" |
| 397 | + |
| 398 | + click_on "Photon torpedo" |
| 399 | + click_on_invoker_button |
| 400 | + |
| 401 | + wait_for_items_to_load do |
| 402 | + filter_results(query: "ph") |
| 403 | + end |
| 404 | + |
| 405 | + # server will render this item checked, but since the user has already made selections, |
| 406 | + # the server-rendered selections should be ignored |
| 407 | + refute_selector "[aria-selected=true]", text: "Phaser" |
| 408 | + assert_selector "[aria-selected=true]", text: "Photon torpedo" |
| 409 | + end |
| 410 | + |
| 411 | + def test_single_select_remembers_only_one_checked_item_and_ignores_checked_items_from_server |
| 412 | + # playground is single-select |
| 413 | + visit_preview(:playground) |
| 414 | + |
| 415 | + wait_for_items_to_load do |
| 416 | + click_on_invoker_button |
| 417 | + end |
| 418 | + |
| 419 | + # Phaser should already be selected |
| 420 | + assert_selector "[aria-selected=true]", text: "Phaser" |
| 421 | + |
| 422 | + wait_for_items_to_load do |
| 423 | + filter_results(query: "light") |
| 424 | + end |
| 425 | + |
| 426 | + click_on "Lightsaber" |
| 427 | + |
| 428 | + click_on_invoker_button |
| 429 | + |
| 430 | + wait_for_items_to_load do |
| 431 | + filter_results(query: "") |
| 432 | + end |
| 433 | + |
| 434 | + refute_selector "[aria-selected=true]", text: "Phaser" |
| 435 | + assert_selector "[aria-selected=true]", text: "Lightsaber" |
| 436 | + end |
| 437 | + |
| 438 | + def test_single_select_handles_all_options_unselected_by_default |
| 439 | + # playground is single-select |
| 440 | + visit_preview(:playground, select_items: false) |
| 441 | + |
| 442 | + wait_for_items_to_load do |
| 443 | + click_on_invoker_button |
| 444 | + end |
| 445 | + |
| 446 | + # Phaser should note already be selected |
| 447 | + refute_selector "[aria-selected=true]", text: "Phaser" |
| 448 | + |
| 449 | + wait_for_items_to_load do |
| 450 | + filter_results(query: "light") |
| 451 | + end |
| 452 | + |
| 453 | + click_on "Lightsaber" |
| 454 | + |
| 455 | + click_on_invoker_button |
| 456 | + |
| 457 | + wait_for_items_to_load do |
| 458 | + filter_results(query: "") |
| 459 | + end |
| 460 | + |
| 461 | + refute_selector "[aria-selected=true]", text: "Phaser" |
| 462 | + assert_selector "[aria-selected=true]", text: "Lightsaber" |
| 463 | + |
| 464 | + |
| 465 | + wait_for_items_to_load do |
| 466 | + filter_results(query: "ph") |
| 467 | + end |
| 468 | + |
| 469 | + click_on "Phaser" |
| 470 | + |
| 471 | + click_on_invoker_button |
| 472 | + |
| 473 | + wait_for_items_to_load do |
| 474 | + filter_results(query: "") |
| 475 | + end |
| 476 | + |
| 477 | + assert_selector "[aria-selected=true]", text: "Phaser" |
| 478 | + refute_selector "[aria-selected=true]", text: "Lightsaber" |
| 479 | + end |
| 480 | + |
385 | 481 | ########## MULTISELECT TESTS ############
|
386 | 482 |
|
387 | 483 | def test_multi_select_items_checked
|
@@ -477,6 +573,31 @@ def test_multi_select_disabled_item_cannot_be_checked
|
477 | 573 | refute_selector "[aria-checked=true]"
|
478 | 574 | end
|
479 | 575 |
|
| 576 | + def test_multi_select_does_not_allow_server_to_check_items_on_filter_if_selections_already_made |
| 577 | + # remote_fetch is multi-select |
| 578 | + visit_preview(:remote_fetch) |
| 579 | + |
| 580 | + wait_for_items_to_load do |
| 581 | + click_on_invoker_button |
| 582 | + end |
| 583 | + |
| 584 | + # Phaser should already be selected |
| 585 | + assert_selector "[aria-checked=true]", text: "Phaser" |
| 586 | + |
| 587 | + # check torpedo, uncheck phaser |
| 588 | + click_on "Photon torpedo" |
| 589 | + click_on "Phaser" |
| 590 | + |
| 591 | + wait_for_items_to_load do |
| 592 | + filter_results(query: "ph") |
| 593 | + end |
| 594 | + |
| 595 | + # server will render phaser checked, but since the user has already made selections, |
| 596 | + # the server-rendered selections should be ignored |
| 597 | + refute_selector "[aria-checked=true]", text: "Phaser" |
| 598 | + assert_selector "[aria-checked=true]", text: "Photon torpedo" |
| 599 | + end |
| 600 | + |
480 | 601 | ########## JAVASCRIPT API TESTS ############
|
481 | 602 |
|
482 | 603 | def test_disable_item_via_js_api
|
|
0 commit comments