From 72e1b938da9b5f730317687e6225159c822852e4 Mon Sep 17 00:00:00 2001 From: hausman-gdit Date: Mon, 5 Feb 2024 10:51:04 -0500 Subject: [PATCH] naming update, req update, tab test --- bmds_server/desktop/cli.py | 10 +++++++--- requirements/base.txt | 1 + tests/desktop/test_cli.py | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/bmds_server/desktop/cli.py b/bmds_server/desktop/cli.py index e3e115cb..fa080c13 100644 --- a/bmds_server/desktop/cli.py +++ b/bmds_server/desktop/cli.py @@ -411,7 +411,7 @@ class ConfigTab(Static): """Configuration Tab""" # Content Switch - @on(Button.Pressed, "#dir-container,#fn-container") + @on(Button.Pressed, "#btn-dir-container,#btn-fn-container") def btn_container_switch(self, event: Button.Pressed) -> None: self.query_one(ContentSwitcher).current = event.button.id self.query_one(DirectoryContainer).reload() @@ -419,8 +419,12 @@ def btn_container_switch(self, event: Button.Pressed) -> None: def compose(self) -> ComposeResult: with Horizontal(classes="config-tab"): with Vertical(classes="config-btns"): - yield Button("Change Directory / Project", id="dir-container", classes="btn-auto") - yield Button("Create New Project", id="fn-container", classes="btn-auto") + yield Button( + "Change Directory / Project", + id="btn-dir-container", + classes="btn-auto", + ) + yield Button("Create New Project", id="btn-fn-container", classes="btn-auto") yield Rule(orientation="vertical") with ContentSwitcher(initial="dir-container"): diff --git a/requirements/base.txt b/requirements/base.txt index 816a224e..9e467033 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -22,3 +22,4 @@ redis==5.0.1 # desktop textual==0.45.1 whitenoise==6.6.0 +pytest-asyncio==0.23.4 diff --git a/tests/desktop/test_cli.py b/tests/desktop/test_cli.py index 22ca865f..5a114a75 100644 --- a/tests/desktop/test_cli.py +++ b/tests/desktop/test_cli.py @@ -1,4 +1,5 @@ import pytest +from textual.widgets import Tabs from bmds_server.desktop.cli import BmdsDesktop @@ -13,3 +14,38 @@ async def test_keys(): await pilot.press("s") btn_start = app.query_one("#runner-button") assert btn_start.label.__str__() == "Stop BMDS Desktop" + + +@pytest.mark.asyncio +async def test_tab_navigation_keyboard(): + """Keyboard Navigation""" + app = BmdsDesktop() + + async with app.run_test() as pilot: + tabs = pilot.app.query_one(Tabs) + # That there are 3 tabs + assert tabs.tab_count == 3 + # That when open app, a tab is active, and is "app" tab + assert tabs.active_tab is not None + assert tabs.active_tab.id == "app" + assert tabs.active == tabs.active_tab.id + # set focus to window + await pilot.press("tab") + # Check app tab content + btn_start = app.query_one("#runner-button") + assert btn_start.label.__str__() == "Start BMDS Desktop" + # Go to Logging tab + await pilot.press("right") # press right arrow key + assert tabs.active_tab is not None + assert tabs.active_tab.id == "tab-2" + assert tabs.active == tabs.active_tab.id + # Go to Config Tab + await pilot.press("right") # press right arrow key + assert tabs.active_tab is not None + assert tabs.active_tab.id == "config" + assert tabs.active == tabs.active_tab.id + # check Config tab buttons + btn_fn = app.query_one("#btn-fn-container") + assert btn_fn.label.__str__() == "Create New Project" + btn_dir = app.query_one("#btn-dir-container") + assert btn_dir.label.__str__() == "Change Directory / Project"