Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common components integration tests #82

Merged
merged 19 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
143 changes: 143 additions & 0 deletions tests/test_integration/test_common_layout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import dash
import pytest
import selenium
from dash.testing.composite import DashComposite

from wazp.app import app


@pytest.fixture
def map_page_name_to_title():
sfmig marked this conversation as resolved.
Show resolved Hide resolved
"""Map page names to page head titles

Returns
-------
dict
dictionary with page names as keys, and page titles as values
"""
return {
"Home": "Home",
"01 metadata": "Metadata",
"02 roi": "ROI definition",
"03 pose estimation": "Pose estimation inference",
"04 dashboard": "Dashboard & data export",
}


@pytest.fixture()
sfmig marked this conversation as resolved.
Show resolved Hide resolved
def timeout():
sfmig marked this conversation as resolved.
Show resolved Hide resolved
"""Maximum time to wait for a component
to be located in layout

Returns
-------
timeout : float
maximum time to wait in seconds
"""
return 4 # Q for review: is this overkill?
sfmig marked this conversation as resolved.
Show resolved Hide resolved


def test_components_created(
dash_duo: DashComposite,
timeout: float,
) -> None:
"""Check that the components common to all pages are created.

The components common to all pages are the page content container and
the sidebar.

Parameters:
dash_duo : DashComposite
Default fixture for Dash Python integration tests.
timeout : float
maximum time to wait in seconds for a component
"""

# start server
dash_duo.start_server(app)

# wait for main content to be rendered
try:
dash_duo.wait_for_element("#page-content", timeout=timeout)
except selenium.common.exceptions.TimeoutException:
pytest.fail("Main content component not generated")
sfmig marked this conversation as resolved.
Show resolved Hide resolved

# wait for sidebar to be rendered
try:
dash_duo.wait_for_text_to_equal(
"#sidebar h2", "WAZP 🐝", timeout=timeout
)
except selenium.common.exceptions.TimeoutException:
pytest.fail("Sidebar component not generated")

# check there are no errors in browser console
assert (
dash_duo.get_logs() == []
), "There are errors in the browser console!"
sfmig marked this conversation as resolved.
Show resolved Hide resolved


@pytest.mark.xfail(
raises=AssertionError,
reason=(
"Feature not yet implemented:"
"When config has not been loaded, "
"warnings should show in pages that are not Home"
),
strict=True,
# with strict=True
# if the test passes unexpectedly,
# it will fail the test suite
)
def test_sidebar_links(
dash_duo: DashComposite,
map_page_name_to_title: dict,
timeout: float,
) -> None:
"""Check the sidebar links take to pages with the expected title
and that no errors occur in the browser console

Parameters:
dash_duo : DashComposite
Default fixture for Dash Python integration tests.
map_page_name_to_title: dictionary : dict
dictionary with page names as keys, and page titles as values
timeout : float
maximum time to wait in seconds for a component
"""

# start server
dash_duo.start_server(app)

# click through links in sidebar
for page in dash.page_registry.values():

# click thru each page
dash_duo.find_element(
"#sidebar #link-" + page["name"].replace(" ", "-"),
).click()
sfmig marked this conversation as resolved.
Show resolved Hide resolved

# check page title
try:
dash_duo.wait_for_text_to_equal(
"h1", map_page_name_to_title[page["name"]], timeout=timeout
)

except selenium.common.exceptions.TimeoutException:
pytest.fail(
f'Timeout waiting for page {page["name"]} '
"to show a title with the text: "
f'{map_page_name_to_title[page["name"]]}'
)

# click back to home
# Q for review: I do this to make the starting point consistent...
# but is it required? should I use fixtures instead?
dash_duo.find_element("#sidebar #link-Home").click()
sfmig marked this conversation as resolved.
Show resolved Hide resolved

# TODO: if no config file has been loaded, check a warning is shown?
# ...

# NOTE: this is expected to fail
assert (
dash_duo.get_logs() == []
), "There are errors in the browser console!"
2 changes: 2 additions & 0 deletions wazp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
dbc.Nav(
children=[
dcc.Link(
id="link-" + page["name"].replace(" ", "-"),
children=f"{page['name']}",
href=page["relative_path"], # url of each page
)
Expand All @@ -64,6 +65,7 @@
),
],
style=SIDEBAR_STYLE,
id="sidebar",
)

# Main content style
Expand Down