Skip to content

Commit b458c35

Browse files
test: Consolidate playwright nav component test (#1158)
Co-authored-by: Barret Schloerke <[email protected]>
1 parent eaaf86e commit b458c35

File tree

2 files changed

+39
-73
lines changed

2 files changed

+39
-73
lines changed

tests/playwright/shiny/components/nav/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def make_navset(
9191

9292

9393
app_ui = ui.page_navbar(
94-
*nav_controls("page_navbar"),
94+
*nav_controls("page_navbar()"),
9595
# bg="#0062cc",
9696
# inverse=True,
9797
id="page_navbar",
Lines changed: 38 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from __future__ import annotations
2+
3+
from dataclasses import dataclass
4+
15
import pytest
26
from conftest import ShinyAppProc
37
from controls import (
@@ -20,75 +24,37 @@ def test_nav(page: Page, local_app: ShinyAppProc) -> None:
2024
# Update the page size to be wider
2125
page.set_viewport_size({"width": 1500, "height": 800})
2226

23-
# make it in a funcn and then loop through it
24-
# navset_tab
25-
navset_tab = LayoutNavsetTab(page, "navset_tab")
26-
navset_tab.expect_nav_values(["a", "b", "c"])
27-
navset_tab.expect_value("a")
28-
navset_tab.expect_content("navset_tab(): tab a content")
29-
navset_tab.set("b")
30-
navset_tab.expect_value("b")
31-
navset_tab.expect_content("navset_tab(): tab b content")
32-
33-
# # navset_pill
34-
navset_pill = LayoutNavSetPill(page, "navset_pill")
35-
navset_pill.expect_nav_values(["a", "b", "c"])
36-
navset_pill.expect_value("a")
37-
navset_pill.expect_content("navset_pill(): tab a content")
38-
navset_pill.set("b")
39-
navset_pill.expect_value("b")
40-
navset_pill.expect_content("navset_pill(): tab b content")
41-
42-
# navset_underline
43-
navset_underline = LayoutNavSetUnderline(page, "navset_underline")
44-
navset_underline.expect_nav_values(["a", "b", "c"])
45-
navset_underline.expect_value("a")
46-
navset_underline.expect_content("navset_underline(): tab a content")
47-
navset_underline.set("b")
48-
navset_underline.expect_value("b")
49-
navset_underline.expect_content("navset_underline(): tab b content")
50-
51-
# navset_card_tab
52-
navset_card_tab = LayoutNavSetCardTab(page, "navset_card_tab")
53-
navset_card_tab.expect_nav_values(["a", "b", "c"])
54-
navset_card_tab.expect_value("a")
55-
navset_card_tab.expect_content("navset_card_tab(): tab a content")
56-
navset_card_tab.set("b")
57-
navset_card_tab.expect_value("b")
58-
navset_card_tab.expect_content("navset_card_tab(): tab b content")
59-
60-
# navset_card_pill
61-
navset_card_pill = LayoutNavSetCardPill(page, "navset_card_pill")
62-
navset_card_pill.expect_nav_values(["a", "b", "c"])
63-
navset_card_pill.expect_value("a")
64-
navset_card_pill.expect_content("navset_card_pill(): tab a content")
65-
navset_card_pill.set("b")
66-
navset_card_pill.expect_value("b")
67-
navset_card_pill.expect_content("navset_card_pill(): tab b content")
68-
69-
# navset_card_underline
70-
navset_card_underline = LayoutNavSetCardUnderline(page, "navset_card_underline")
71-
navset_card_underline.expect_nav_values(["a", "b", "c"])
72-
navset_card_underline.expect_value("a")
73-
navset_card_underline.expect_content("navset_card_underline(): tab a content")
74-
navset_card_underline.set("b")
75-
navset_card_underline.expect_value("b")
76-
navset_card_underline.expect_content("navset_card_underline(): tab b content")
77-
78-
# navset_pill_list
79-
navset_card_pill = LayoutNavSetPillList(page, "navset_pill_list")
80-
navset_card_pill.expect_nav_values(["a", "b", "c"])
81-
navset_card_pill.expect_value("a")
82-
navset_card_pill.expect_content("navset_pill_list(): tab a content")
83-
navset_card_pill.set("b")
84-
navset_card_pill.expect_value("b")
85-
navset_card_pill.expect_content("navset_pill_list(): tab b content")
86-
87-
# Page_navbar
88-
navset_bar = LayoutNavSetBar(page, "page_navbar")
89-
navset_bar.expect_nav_values(["a", "b", "c"])
90-
navset_bar.expect_value("a")
91-
navset_bar.expect_content("page_navbar: tab a content")
92-
navset_bar.set("b")
93-
navset_bar.expect_value("b")
94-
navset_bar.expect_content("page_navbar: tab b content")
27+
@dataclass
28+
class LayoutInfo:
29+
control: type[
30+
LayoutNavSetBar
31+
| LayoutNavSetCardPill
32+
| LayoutNavSetCardTab
33+
| LayoutNavSetCardUnderline
34+
| LayoutNavSetPill
35+
| LayoutNavSetPillList
36+
| LayoutNavsetTab
37+
| LayoutNavSetUnderline
38+
]
39+
verify: str
40+
41+
nav_data: list[LayoutInfo] = [
42+
LayoutInfo(LayoutNavsetTab, "navset_tab()"),
43+
LayoutInfo(LayoutNavSetPill, "navset_pill()"),
44+
LayoutInfo(LayoutNavSetUnderline, "navset_underline()"),
45+
LayoutInfo(LayoutNavSetCardTab, "navset_card_tab()"),
46+
LayoutInfo(LayoutNavSetCardPill, "navset_card_pill()"),
47+
LayoutInfo(LayoutNavSetCardUnderline, "navset_card_underline()"),
48+
LayoutInfo(LayoutNavSetPillList, "navset_pill_list()"),
49+
LayoutInfo(LayoutNavSetBar, "page_navbar()"),
50+
]
51+
52+
for nav_info in nav_data:
53+
el_name = nav_info.verify.replace("()", "")
54+
element = nav_info.control(page, el_name)
55+
element.expect_nav_values(["a", "b", "c"])
56+
element.expect_value("a")
57+
element.expect_content(nav_info.verify + ": tab a content")
58+
element.set("b")
59+
element.expect_value("b")
60+
element.expect_content(nav_info.verify + ": tab b content")

0 commit comments

Comments
 (0)