-
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.
tests(sidebar): Add tests for sidebar (#1715)
- Loading branch information
1 parent
ead102a
commit fa9f8d4
Showing
4 changed files
with
300 additions
and
3 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
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
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,68 @@ | ||
from shiny.express import input, render, ui | ||
|
||
ui.page_opts(fillable=True) | ||
|
||
with ui.card(): | ||
with ui.layout_sidebar(): | ||
with ui.sidebar( | ||
id="sidebar_left", | ||
open="desktop", | ||
title="Left sidebar", | ||
bg="dodgerBlue", | ||
class_="text-white", | ||
gap="20px", | ||
padding="10px", | ||
width="200px", | ||
): | ||
"Left sidebar content" | ||
|
||
@render.code | ||
def state_left(): | ||
return f"input.sidebar_left(): {input.sidebar_left()}" | ||
|
||
|
||
with ui.card(): | ||
with ui.layout_sidebar(): | ||
with ui.sidebar( | ||
id="sidebar_right", | ||
position="right", | ||
open={"desktop": "closed", "mobile": "open"}, | ||
padding=["10px", "20px"], | ||
bg="SlateBlue", | ||
): | ||
"Right sidebar content" | ||
|
||
@render.code | ||
def state_right(): | ||
return f"input.sidebar_right(): {input.sidebar_right()}" | ||
|
||
|
||
with ui.card(): | ||
with ui.layout_sidebar(): | ||
with ui.sidebar( | ||
id="sidebar_closed", | ||
open="closed", | ||
bg="LightCoral", | ||
padding=["10px", "20px", "30px"], | ||
): | ||
"Closed sidebar content" | ||
|
||
@render.code | ||
def state_closed(): | ||
return f"input.sidebar_closed(): {input.sidebar_closed()}" | ||
|
||
|
||
with ui.card(): | ||
with ui.layout_sidebar(): | ||
with ui.sidebar( | ||
id="sidebar_always", | ||
open="always", | ||
bg="PeachPuff", | ||
padding=["10px", "20px", "30px", "40px"], | ||
max_height_mobile="175px", | ||
): | ||
"Always sidebar content" | ||
|
||
@render.code | ||
def state_always(): | ||
return f"input.sidebar_always(): {input.sidebar_always()}" |
50 changes: 50 additions & 0 deletions
50
tests/playwright/shiny/inputs/sidebar_kitchensink/test_sidebar_kitchensink.py
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,50 @@ | ||
from playwright.sync_api import Page | ||
|
||
from shiny.playwright import controller | ||
from shiny.run import ShinyAppProc | ||
|
||
|
||
def test_sidebar_kitchensink(page: Page, local_app: ShinyAppProc) -> None: | ||
page.goto(local_app.url) | ||
|
||
left_sidebar = controller.Sidebar(page, "sidebar_left") | ||
output_txt_left = controller.OutputTextVerbatim(page, "state_left") | ||
left_sidebar.set(True) | ||
left_sidebar.expect_padding("10px") | ||
left_sidebar.expect_padding(["10px"]) | ||
left_sidebar.expect_title("Left sidebar") | ||
left_sidebar.expect_gap("20px") | ||
left_sidebar.expect_class("text-white", has_class=True) | ||
left_sidebar.expect_bg_color("dodgerBlue") | ||
left_sidebar.expect_desktop_state("open") | ||
left_sidebar.expect_mobile_state("closed") | ||
left_sidebar.expect_width("200px") | ||
output_txt_left.expect_value("input.sidebar_left(): True") | ||
left_sidebar.expect_open(True) | ||
left_sidebar.set(False) | ||
output_txt_left.expect_value("input.sidebar_left(): False") | ||
left_sidebar.expect_handle(True) | ||
left_sidebar.expect_open(False) | ||
left_sidebar.loc_handle.click() | ||
left_sidebar.expect_open(True) | ||
output_txt_left.expect_value("input.sidebar_left(): True") | ||
|
||
right_sidebar = controller.Sidebar(page, "sidebar_right") | ||
right_sidebar.expect_padding(["10px", "20px"]) | ||
right_sidebar.expect_bg_color("SlateBlue") | ||
right_sidebar.expect_mobile_state("open") | ||
right_sidebar.expect_desktop_state("closed") | ||
|
||
closed_sidebar = controller.Sidebar(page, "sidebar_closed") | ||
closed_sidebar.expect_padding(["10px", "20px", "30px"]) | ||
closed_sidebar.expect_bg_color("LightCoral") | ||
closed_sidebar.expect_mobile_state("closed") | ||
closed_sidebar.expect_desktop_state("closed") | ||
|
||
always_sidebar = controller.Sidebar(page, "sidebar_always") | ||
always_sidebar.expect_padding(["10px", "20px", "30px", "40px"]) | ||
always_sidebar.expect_bg_color("PeachPuff") | ||
always_sidebar.expect_open(True) | ||
always_sidebar.expect_desktop_state("always") | ||
always_sidebar.expect_mobile_state("always") | ||
always_sidebar.expect_mobile_max_height("175px") |