Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e77de89
Add page_navset and Navset_hidden tests and controllers
karangattu Sep 5, 2024
7314f12
Add tests for checking gap params
karangattu Sep 5, 2024
b6f3acb
address failing tests
karangattu Sep 6, 2024
30b846a
Merge branch 'main' into add-page_nav_bar-kitchensink
karangattu Sep 6, 2024
21f43f5
use expect_to_have_class
karangattu Sep 6, 2024
3fcc0e5
Add tests to check for page window title
karangattu Sep 11, 2024
714f7e1
address linting failures
karangattu Sep 11, 2024
b9d3baa
Add additional test to check for window title
karangattu Sep 11, 2024
80dcfe7
fix card tests
karangattu Sep 11, 2024
23a5938
Merge branch 'main' into add-page_nav_bar-kitchensink
schloerke Sep 11, 2024
8f56222
Change param name to `expect_inverse(value=)`; Add missing docs
schloerke Sep 11, 2024
35d8357
Add TODO
schloerke Sep 11, 2024
fcb433d
Merge branch 'add-page_nav_bar-kitchensink' of https://github.com/pos…
schloerke Sep 11, 2024
6efde5d
Remove default value of `expect_inverse(value=)`. This means it now r…
schloerke Sep 11, 2024
464f0c2
Added changelog
karangattu Sep 12, 2024
fe6d3a2
move change log around
schloerke Sep 12, 2024
dd9e1d5
Added NavsetPillList `.expect_widths()` method
karangattu Sep 12, 2024
109f9f1
Update test_page_navbar_fillable_app.py
karangattu Sep 12, 2024
5629ee9
Update _navs.py
karangattu Sep 12, 2024
69135d8
Update _navs.py
karangattu Sep 12, 2024
1514f86
Merge branch 'main' into add-page_nav_bar-kitchensink
karangattu Sep 12, 2024
1ec046f
Remove unused imports
karangattu Sep 12, 2024
f8dbcd4
linting issues
karangattu Sep 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions shiny/playwright/controller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
NavsetPillList,
NavsetTab,
NavsetUnderline,
PageNavbar,
)
from ._output import (
OutputCode,
Expand Down Expand Up @@ -121,4 +122,5 @@
"NavsetUnderline",
"DownloadButton",
"DownloadLink",
"PageNavbar",
]
27 changes: 25 additions & 2 deletions shiny/playwright/controller/_navs.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,12 @@ def __init__(self, page: Page, id: str) -> None:
)


class NavsetBar(
class _ExpectNavsetCommonM(
_ExpectNavsetSidebarM,
_ExpectNavsetTitleM,
_NavsetBase,
):
"""Controller for :func:`shiny.ui.navset_bar`."""
"""Mixin class for common expectations of nav bars."""

def __init__(self, page: Page, id: str) -> None:
"""
Expand Down Expand Up @@ -695,3 +695,26 @@ def expect_layout(
playwright_expect(self.loc_container.locator("..")).to_have_class(
re.compile("container"), timeout=timeout
)


class NavsetBar(
_ExpectNavsetCommonM,
):
"""Controller for :func:`shiny.ui.navset_bar`."""


class PageNavbar(_ExpectNavsetCommonM):
"""Controller for :func:`shiny.ui.page_navbar`."""

def expect_fillable(self, *, timeout: Timeout = None) -> None:
"""
Expects the main content area to be considered a fillable (i.e., flexbox) container

Parameters
----------
timeout
The maximum time to wait for the expectation to pass. Defaults to `None`.
"""
playwright_expect(self.get_loc_active_content()).to_have_class(
re.compile("html-fill-container"), timeout=timeout
)
5 changes: 0 additions & 5 deletions tests/playwright/shiny/components/nav/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
from shiny.types import NavSetArg
from shiny.ui import Sidebar

# TODO-karan; Make test that uses sidebar / no sidebar (where possible)
# TODO-karan; Make test that has/does not have a header & footer (where possible)
# TODO-karan; Test for title value (where possible)
# TODO-karan; Make test that has placement = "above" / "below" (where possible); Test in combination of with/without sidebar


def nav_controls(prefix: str) -> List[NavSetArg]:
return [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from shiny import reactive
from shiny.express import input, ui

ui.input_radio_buttons("controller1", "Controller1", ["1", "2", "3"], selected="2")

with ui.navset_hidden(
id="hidden_tabs1",
header=ui.tags.div("Navset_hidden_header", id="navset_hidden_header1"),
footer=ui.tags.div("Navset_hidden_footer", id="navset_hidden_footer1"),
selected="panel2",
):
with ui.nav_panel(None, value="panel1"):
"Panel 1 content"
with ui.nav_panel(None, value="panel2"):
"Panel 2 content"
with ui.nav_panel(None, value="panel3"):
"Panel 3 content"

ui.markdown("-----")
ui.input_radio_buttons("controller2", "Controller2", ["4", "5", "6"])

with ui.navset_hidden(id="hidden_tabs2"):
with ui.nav_panel(None, value="panel4"):
"Panel 4 content"
with ui.nav_panel(None, value="panel5"):
"Panel 5 content"
with ui.nav_panel(None, value="panel6"):
"Panel 6 content"


@reactive.effect
@reactive.event(input.controller1)
def _():
ui.update_navs("hidden_tabs1", selected="panel" + str(input.controller1()))


@reactive.effect
@reactive.event(input.controller2)
def _():
ui.update_navs("hidden_tabs2", selected="panel" + str(input.controller2()))
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from playwright.sync_api import Page

from shiny.playwright import controller
from shiny.run import ShinyAppProc


def test_navset_hidden_kitchensink(page: Page, local_app: ShinyAppProc) -> None:
page.goto(local_app.url)

navset_hidden_1 = controller.NavsetHidden(page, "hidden_tabs1")
radio1 = controller.InputRadioButtons(page, "controller1")
navset_hidden_1.expect_value("panel2")
navset_hidden_1._expect_content_text("Panel 2 content")
# assert the DOM structure for hidden_navset with header and footer is preserved
assert (
page.locator(
"#hidden_tabs1 + #navset_hidden_header1 + .tab-content + #navset_hidden_footer1"
).count()
== 1
)
# assert header and footer contents
assert page.locator("#navset_hidden_header1").inner_text() == "Navset_hidden_header"
assert page.locator("#navset_hidden_footer1").inner_text() == "Navset_hidden_footer"
radio1.set("1")
navset_hidden_1.expect_value("panel1")
navset_hidden_1._expect_content_text("Panel 1 content")

navset_hidden_2 = controller.NavsetHidden(page, "hidden_tabs2")
navset_hidden_2.expect_value("panel4")
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from shiny.express import ui

ui.page_opts(id="default_page_navbar", title="Default Page Navbar")

with ui.nav_panel("Data"):
"This page could be used to pick a dataset."

with ui.nav_panel("View"):
"This page could be used to view the dataset."
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from playwright.sync_api import Page

from shiny.playwright import controller
from shiny.run import ShinyAppProc


def test_default_page_navbar(page: Page, local_app: ShinyAppProc) -> None:
page.goto(local_app.url)

default_page_navbar = controller.PageNavbar(page, "default_page_navbar")
default_page_navbar.expect_title("Default Page Navbar")
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from shiny.express import ui

ui.page_opts(id="page_navbar_fillable", fillable=True)

with ui.nav_panel("Data"):
"This page could be used to pick a dataset."

with ui.nav_panel("View"):
"This page could be used to view the dataset."
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from playwright.sync_api import Page

from shiny.playwright import controller
from shiny.run import ShinyAppProc


def test_page_navbar_fillable(page: Page, local_app: ShinyAppProc) -> None:
page.goto(local_app.url)

page_navbar_fillable = controller.PageNavbar(page, "page_navbar_fillable")
page_navbar_fillable._expect_content_text(
"This page could be used to pick a dataset."
)
page_navbar_fillable.expect_fillable()
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from shiny.express import ui

ui.page_opts(
id="page_fixed_bottom_inverse_bg",
position="fixed-bottom",
bg="dodgerBlue",
inverse=True,
gap="50px",
)

with ui.nav_panel("Data"):
"This page could be used to pick a dataset."

with ui.nav_panel("View"):
"This page could be used to view the dataset."
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from playwright.sync_api import Page

from shiny.playwright import controller
from shiny.run import ShinyAppProc


def test_page_navbar_fixed_bottom_inverse_bg(
page: Page, local_app: ShinyAppProc
) -> None:
page.goto(local_app.url)

page_navbar_fixed_bottom_inverse_bg = controller.PageNavbar(
page, "page_fixed_bottom_inverse_bg"
)
page_navbar_fixed_bottom_inverse_bg.expect_position("fixed-bottom")
page_navbar_fixed_bottom_inverse_bg.expect_inverse()
page_navbar_fixed_bottom_inverse_bg.expect_bg("dodgerBlue")
# page_navbar_fixed_bottom_inverse_bg.expect_gap("50px") # not working as expected since not showing on app
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from shiny.express import ui

ui.page_opts(
id="page_navbar_header_footer_fixed_top",
header=ui.tags.div("Header", id="page_navbar_header"),
footer=ui.tags.div("Footer", id="page_navbar_footer"),
position="fixed-top",
)

with ui.nav_panel("Data"):
"This page could be used to pick a dataset."

with ui.nav_panel("View"):
"This page could be used to view the dataset."
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from playwright.sync_api import Page

from shiny.playwright import controller
from shiny.run import ShinyAppProc


def test_page_navbar_header_footer_fixed_top(
page: Page, local_app: ShinyAppProc
) -> None:
page.goto(local_app.url)

page_navbar_header_footer_fixed_top = controller.PageNavbar(
page, "page_navbar_header_footer_fixed_top"
)
page_navbar_header_footer_fixed_top.expect_position("fixed-top")
# assert the DOM structure for page_navbar with header and footer is preserved
assert (
page.locator("#page_navbar_header + .tab-content + #page_navbar_footer").count()
== 1
)
# assert header and footer contents
assert page.locator("#page_navbar_header").inner_text() == "Header"
assert page.locator("#page_navbar_footer").inner_text() == "Footer"
# assert page_navbar_header_footer_fixed_top.expect_layout("fixed") # not working as expected since not showing on app
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from shiny.express import ui

ui.page_opts(id="page_navbar_selected", selected="View", fluid=False)

with ui.nav_panel("Data"):
"This page could be used to pick a dataset."

with ui.nav_panel("View"):
"This page could be used to view the dataset."
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from playwright.sync_api import Page

from shiny.playwright import controller
from shiny.run import ShinyAppProc


def test_page_navbar_selected(page: Page, local_app: ShinyAppProc) -> None:
page.goto(local_app.url)

page_navbar_selected = controller.PageNavbar(page, "page_navbar_selected")
page_navbar_selected.expect_value("View")
page_navbar_selected._expect_content_text(
"This page could be used to view the dataset."
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from shiny.express import ui


def navset_sidebar():
from shiny import ui as core_ui

return core_ui.sidebar(core_ui.markdown("Sidebar content"))


ui.page_opts(id="page_navbar_sidebar", sidebar=navset_sidebar())

with ui.nav_panel("Data"):
"This page could be used to pick a dataset."

with ui.nav_panel("View"):
"This page could be used to view the dataset."
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from playwright.sync_api import Page

from shiny.playwright import controller
from shiny.run import ShinyAppProc


def test_page_navbar_sidebar(page: Page, local_app: ShinyAppProc) -> None:
page.goto(local_app.url)

page_navbar_sidebar = controller.PageNavbar(page, "page_navbar_sidebar")
page_navbar_sidebar.expect_value("Data")
page_navbar_sidebar._expect_content_text(
"This page could be used to pick a dataset."
)
page_navbar_sidebar.expect_sidebar(True)