From ca5ebc898039d73fcc208c4eccf87226e4a0f7c2 Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Wed, 25 Oct 2023 21:47:27 -0700 Subject: [PATCH 1/5] Add sidebar position tests --- tests/e2e/bugs/0666-sidebar/app.py | 1 + tests/e2e/bugs/0666-sidebar/test_sidebar_colors.py | 10 +++++----- tests/e2e/controls.py | 8 ++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/e2e/bugs/0666-sidebar/app.py b/tests/e2e/bugs/0666-sidebar/app.py index a0ae77b0d..7095a6648 100644 --- a/tests/e2e/bugs/0666-sidebar/app.py +++ b/tests/e2e/bugs/0666-sidebar/app.py @@ -14,6 +14,7 @@ ui.layout_sidebar( ui.panel_sidebar("Sidebar content - 1", id="s1"), ui.panel_main("Main content - 1", id="m1"), + "left" ), ui.layout_sidebar( ui.panel_sidebar("Sidebar content - 2", id="s2"), diff --git a/tests/e2e/bugs/0666-sidebar/test_sidebar_colors.py b/tests/e2e/bugs/0666-sidebar/test_sidebar_colors.py index 1f519f35a..4024e3995 100644 --- a/tests/e2e/bugs/0666-sidebar/test_sidebar_colors.py +++ b/tests/e2e/bugs/0666-sidebar/test_sidebar_colors.py @@ -3,7 +3,7 @@ from colors import bg_color, fg_color from conftest import ShinyAppProc -# from controls import Sidebar +from controls import Sidebar from playwright.sync_api import Page, expect @@ -30,7 +30,7 @@ def test_sidebar_bg_colors(page: Page, local_app: ShinyAppProc) -> None: expect(first_sidebar).to_have_css("color", fg_color) # # TODO-karan; Test that sidebar position is left - # s1 = Sidebar(page, "s1") - # s1.expect_position("left") - # s2 = Sidebar(page, "s2") - # s2.expect_position("right") + s1 = Sidebar(page, "s1") + s1.expect_position("left") + s2 = Sidebar(page, "s2") + s2.expect_position("right") diff --git a/tests/e2e/controls.py b/tests/e2e/controls.py index 4e337361e..05b1aaa94 100644 --- a/tests/e2e/controls.py +++ b/tests/e2e/controls.py @@ -2390,10 +2390,18 @@ def __init__(self, page: Page, id: str) -> None: loc_container="div.bslib-sidebar-layout", ) self.loc_handle = self.loc_container.locator("button.collapse-toggle") + self.loc_position = self.loc.locator("..") def expect_title(self, value: PatternOrStr, *, timeout: Timeout = None) -> None: playwright_expect(self.loc).to_have_text(value, timeout=timeout) + def expect_position(self, position: str, *, timeout: Timeout = None) -> None: + if position == 'right': + is_sidebar_right = True + else: + is_sidebar_right = False + _expect_class_value(self.loc_position, f"sidebar-{position}", is_sidebar_right, timeout=timeout) + def expect_handle(self, exists: bool, *, timeout: Timeout = None) -> None: playwright_expect(self.loc_handle).to_have_count(int(exists), timeout=timeout) From 29e9c373359e9698c163f646376b417c57af76f7 Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Fri, 27 Oct 2023 08:29:51 -0700 Subject: [PATCH 2/5] Refactor method --- tests/e2e/controls.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/e2e/controls.py b/tests/e2e/controls.py index 05b1aaa94..b44ae26a1 100644 --- a/tests/e2e/controls.py +++ b/tests/e2e/controls.py @@ -2395,12 +2395,16 @@ def __init__(self, page: Page, id: str) -> None: def expect_title(self, value: PatternOrStr, *, timeout: Timeout = None) -> None: playwright_expect(self.loc).to_have_text(value, timeout=timeout) - def expect_position(self, position: str, *, timeout: Timeout = None) -> None: - if position == 'right': - is_sidebar_right = True - else: - is_sidebar_right = False - _expect_class_value(self.loc_position, f"sidebar-{position}", is_sidebar_right, timeout=timeout) + def expect_position( + self, position: Literal["left", "right"], *, timeout: Timeout = None + ) -> None: + is_right_sidebar = position == "right" + _expect_class_value( + self.loc_position, + f"sidebar-{position}", + is_right_sidebar, + timeout=timeout, + ) def expect_handle(self, exists: bool, *, timeout: Timeout = None) -> None: playwright_expect(self.loc_handle).to_have_count(int(exists), timeout=timeout) From a8867de00aa11f40490a692656e12fb4979dced4 Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Fri, 27 Oct 2023 08:56:32 -0700 Subject: [PATCH 3/5] remove TODO comment --- tests/e2e/bugs/0666-sidebar/test_sidebar_colors.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/bugs/0666-sidebar/test_sidebar_colors.py b/tests/e2e/bugs/0666-sidebar/test_sidebar_colors.py index 4024e3995..e9613921a 100644 --- a/tests/e2e/bugs/0666-sidebar/test_sidebar_colors.py +++ b/tests/e2e/bugs/0666-sidebar/test_sidebar_colors.py @@ -29,7 +29,6 @@ def test_sidebar_bg_colors(page: Page, local_app: ShinyAppProc) -> None: expect(first_sidebar).to_have_css("background-color", bg_color) expect(first_sidebar).to_have_css("color", fg_color) - # # TODO-karan; Test that sidebar position is left s1 = Sidebar(page, "s1") s1.expect_position("left") s2 = Sidebar(page, "s2") From 26601f4c0dcfa9997afc095da5cc14a62017203d Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Fri, 27 Oct 2023 08:57:18 -0700 Subject: [PATCH 4/5] remove left since that is default --- tests/e2e/bugs/0666-sidebar/app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/bugs/0666-sidebar/app.py b/tests/e2e/bugs/0666-sidebar/app.py index 7095a6648..a0ae77b0d 100644 --- a/tests/e2e/bugs/0666-sidebar/app.py +++ b/tests/e2e/bugs/0666-sidebar/app.py @@ -14,7 +14,6 @@ ui.layout_sidebar( ui.panel_sidebar("Sidebar content - 1", id="s1"), ui.panel_main("Main content - 1", id="m1"), - "left" ), ui.layout_sidebar( ui.panel_sidebar("Sidebar content - 2", id="s2"), From ab656f793b1540791c1829ab86088bd377ecd70e Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Fri, 27 Oct 2023 09:16:28 -0700 Subject: [PATCH 5/5] add a newline --- tests/e2e/bugs/0666-sidebar/test_sidebar_colors.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/bugs/0666-sidebar/test_sidebar_colors.py b/tests/e2e/bugs/0666-sidebar/test_sidebar_colors.py index e9613921a..4949550b0 100644 --- a/tests/e2e/bugs/0666-sidebar/test_sidebar_colors.py +++ b/tests/e2e/bugs/0666-sidebar/test_sidebar_colors.py @@ -2,7 +2,6 @@ from colors import bg_color, fg_color from conftest import ShinyAppProc - from controls import Sidebar from playwright.sync_api import Page, expect