Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def nav_items(prefix: str) -> list[NavSetArg]:
sidebar=my_sidebar,
title="page_navbar()",
bg="#0062cc",
id="page_navbar",
header=ui.markdown(
"Testing app for `bslib::nav_spacer()` and `bslib::nav_item()` [#319](https://github.com/rstudio/bslib/pull/319)."
),
Expand All @@ -55,17 +56,20 @@ def nav_items(prefix: str) -> list[NavSetArg]:
ui.h4("navset_card_tab()"),
ui.navset_card_tab(
*nav_items("navset_card_tab()"),
id="navset_card_tab",
sidebar=my_sidebar,
),
ui.h4("navset_card_pill()"),
ui.navset_card_pill(
*nav_items("navset_card_pill()"),
id="navset_card_pill",
sidebar=my_sidebar,
),
# Do not include `navset_bar()` in example. Ok for testing only
ui.h4("navset_bar()"),
ui.navset_bar(
*nav_items("navset_bar()"),
id="navset_bar",
title="Test!",
sidebar=my_sidebar,
),
Expand Down
70 changes: 70 additions & 0 deletions tests/playwright/shiny/navbar/test_navbar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from typing import Union

import pytest
from examples.example_apps import reruns, reruns_delay
from playwright.sync_api import Page

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


@pytest.mark.flaky(reruns=reruns, reruns_delay=reruns_delay)
def test_navbar(page: Page, local_app: ShinyAppProc) -> None:
values = ["a", "b", "c"]

def verify_panel_updates(
elem: Union[
controller.PageNavbar,
controller.NavsetCardTab,
controller.NavsetCardPill,
controller.NavsetBar,
]
) -> None:
a_panel = elem.nav_panel("a")
b_panel = elem.nav_panel("b")
c_panel = elem.nav_panel("c")

a_panel.click()
a_panel.expect_active(True)
b_panel.expect_active(False)
c_panel.expect_active(False)
assert (
f"{elem.id}(): tab a content\n"
in elem.get_loc_active_content().all_text_contents()
)

b_panel.click()
a_panel.expect_active(False)
b_panel.expect_active(True)
c_panel.expect_active(False)
assert (
f"{elem.id}(): tab b content\n"
in elem.get_loc_active_content().all_text_contents()
)

c_panel.click()
a_panel.expect_active(False)
b_panel.expect_active(False)
c_panel.expect_active(True)
assert (
f"{elem.id}(): tab c content\n"
in elem.get_loc_active_content().all_text_contents()
)

page.goto(local_app.url)

nav_bar = controller.PageNavbar(page, "page_navbar")
nav_bar.expect_nav_values(values)
verify_panel_updates(nav_bar)

navset_card_tab = controller.NavsetCardTab(page, "navset_card_tab")
navset_card_tab.expect_nav_values(values)
verify_panel_updates(navset_card_tab)

navset_card_pill = controller.NavsetCardPill(page, "navset_card_pill")
navset_card_pill.expect_nav_values(values)
verify_panel_updates(navset_card_pill)

navset_bar = controller.NavsetBar(page, "navset_bar")
navset_bar.expect_nav_values(values)
verify_panel_updates(navset_bar)
Loading