-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add E2E tests for accordion and autoresize (#601)
Co-authored-by: Barret Schloerke <[email protected]>
- Loading branch information
1 parent
2d5acbe
commit a50c637
Showing
4 changed files
with
250 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from conftest import ShinyAppProc | ||
from controls import Accordion, InputActionButton, OutputTextVerbatim | ||
from playwright.sync_api import Page | ||
|
||
|
||
def test_accordion(page: Page, local_app: ShinyAppProc) -> None: | ||
page.goto(local_app.url) | ||
|
||
acc = Accordion(page, "acc") | ||
acc_panel_A = acc.accordion_panel("Section A") | ||
output_txt_verbatim = OutputTextVerbatim(page, "acc_txt") | ||
alternate_button = InputActionButton(page, "alternate") | ||
open_all_button = InputActionButton(page, "open_all") | ||
close_all_button = InputActionButton(page, "close_all") | ||
toggle_b_button = InputActionButton(page, "toggle_b") | ||
toggle_updates_button = InputActionButton(page, "toggle_updates") | ||
toggle_efg_button = InputActionButton(page, "toggle_efg") | ||
acc.expect_width(None) | ||
acc.expect_height(None) | ||
|
||
# initial state - by default only A is open | ||
acc.expect_panels(["Section A", "Section B", "Section C", "Section D"]) | ||
output_txt_verbatim.expect_value("input.acc(): ('Section A',)") | ||
acc.expect_open(["Section A"]) | ||
acc_panel_A.expect_label("Section A") | ||
acc_panel_A.expect_body("Some narrative for section A") | ||
acc_panel_A.expect_open(True) | ||
|
||
alternate_button.click() | ||
acc.expect_open(["Section B", "Section D"]) | ||
output_txt_verbatim.expect_value("input.acc(): ('Section B', 'Section D')") | ||
|
||
alternate_button.click() | ||
acc.expect_open(["Section A", "Section C"]) | ||
output_txt_verbatim.expect_value("input.acc(): ('Section A', 'Section C')") | ||
|
||
open_all_button.click() | ||
acc.expect_open(["Section A", "Section B", "Section C", "Section D"]) | ||
output_txt_verbatim.expect_value( | ||
"input.acc(): ('Section A', 'Section B', 'Section C', 'Section D')" | ||
) | ||
|
||
close_all_button.click() | ||
acc.expect_open([]) | ||
output_txt_verbatim.expect_value("input.acc(): None") | ||
|
||
toggle_b_button.click() | ||
acc.expect_open(["Section B"]) | ||
output_txt_verbatim.expect_value("input.acc(): ('Section B',)") | ||
|
||
acc_panel_updated_A = acc.accordion_panel("updated_section_a") | ||
toggle_updates_button.click() | ||
acc_panel_updated_A.expect_label("Updated title") | ||
acc_panel_updated_A.expect_body("Updated body") | ||
acc_panel_updated_A.expect_icon("Look! An icon! -->") | ||
|
||
acc.expect_panels(["updated_section_a", "Section B", "Section C", "Section D"]) | ||
output_txt_verbatim.expect_value("input.acc(): ('updated_section_a', 'Section B')") | ||
|
||
toggle_efg_button.click() | ||
acc.expect_panels( | ||
[ | ||
"updated_section_a", | ||
"Section B", | ||
"Section C", | ||
"Section D", | ||
"Section E", | ||
"Section F", | ||
"Section G", | ||
] | ||
) | ||
acc.expect_open( | ||
["updated_section_a", "Section B", "Section E", "Section F", "Section G"] | ||
) | ||
# will be uncommented once https://github.com/rstudio/bslib/issues/565 is fixed | ||
# output_txt_verbatim.expect_value( | ||
# "input.acc(): ('updated_section_a', 'Section B', 'Section E', 'Section F', 'Section G')" | ||
# ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from conftest import ShinyAppProc, x_create_doc_example_fixture | ||
from controls import InputTextArea, OutputTextVerbatim | ||
from playwright.sync_api import Locator, Page | ||
|
||
app = x_create_doc_example_fixture("input_text_area") | ||
|
||
resize_number = 6 | ||
|
||
|
||
def get_box_height(locator: Locator) -> float: | ||
bounding_box = locator.bounding_box() | ||
if bounding_box is not None: | ||
return bounding_box["height"] | ||
else: | ||
return 0 | ||
|
||
|
||
def test_autoresize(page: Page, app: ShinyAppProc) -> None: | ||
page.goto(app.url) | ||
|
||
input_area = InputTextArea(page, "caption") | ||
output_txt_verbatim = OutputTextVerbatim(page, "value") | ||
input_area.expect_height(None) | ||
input_area.expect_width(None) | ||
input_area.set("test value") | ||
# use bounding box approach since height is dynamic | ||
initial_height = get_box_height(input_area.loc) | ||
output_txt_verbatim.expect_value("test value") | ||
for _ in range(resize_number): | ||
input_area.loc.press("Enter") | ||
input_area.loc.type("end value") | ||
return_txt = "\n" * resize_number | ||
output_txt_verbatim.expect_value(f"test value{return_txt}end value") | ||
assert get_box_height(input_area.loc) > initial_height |