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 10 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
39 changes: 39 additions & 0 deletions tests/test_integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from selenium.webdriver.chrome.options import Options


Expand All @@ -6,3 +7,41 @@ def pytest_setup_options():
options.add_argument("--headless")
options.add_argument("--disable-gpu")
return options


@pytest.fixture
def home_page_name_and_title():
return ("Home", "Home")


@pytest.fixture
def metadata_page_name_and_title():
return ("01 metadata", "Metadata")


@pytest.fixture
def roi_page_name_and_title():
return ("02 roi", "ROI definition")


@pytest.fixture
def pose_estimation_page_name_and_title():
return ("03 pose estimation", "Pose estimation inference")


@pytest.fixture
def dashboard_page_name_and_title():
return ("04 dashboard", "Dashboard & data export")


@pytest.fixture
def timeout() -> float:
"""Maximum time to wait for a component
to be located in layout

Returns
-------
timeout : float
maximum time to wait in seconds
"""
return 4
131 changes: 131 additions & 0 deletions tests/test_integration/test_common_layout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import pytest
import selenium
from dash.testing.composite import DashComposite

from wazp.app import app


def test_components_created(
dash_duo: DashComposite,
timeout: float,
) -> None:
"""Check that the components that are 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 container 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() == []
), f"There are {len(dash_duo.get_logs())} errors"
" in the browser console!"


unloaded_config_xfail = 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
)


# Q for review: is there a way to have this with
# one fixture only?
sfmig marked this conversation as resolved.
Show resolved Hide resolved
# https://docs.pytest.org/en/latest/how-to/skipping.html#skip-xfail-with-parametrize
@pytest.mark.parametrize(
("page_name_and_title"),
[
pytest.param(fx, marks=mark)
for fx, mark in [
("home_page_name_and_title", []),
("metadata_page_name_and_title", unloaded_config_xfail),
("roi_page_name_and_title", unloaded_config_xfail),
("pose_estimation_page_name_and_title", []),
("dashboard_page_name_and_title", unloaded_config_xfail),
]
],
)
def test_sidebar_links(
dash_duo: DashComposite,
page_name_and_title: str,
sfmig marked this conversation as resolved.
Show resolved Hide resolved
# page_title: str,
timeout: float,
request,
) -> None:
"""Check the sidebar links take to the corresponding pages
and that no errors occur in the browser console

The pages are checked via their title.

Parameters:
dash_duo : DashComposite
Default fixture for Dash Python integration tests.
page_name : str
name of the page in the dash registry
page_title: str
main title shown for a page
sfmig marked this conversation as resolved.
Show resolved Hide resolved
timeout : float
maximum time to wait in seconds for a component
"""

# get fixture value
(page_name, page_title) = request.getfixturevalue(page_name_and_title)

# start server
dash_duo.start_server(app)

# click sidebar link
dash_duo.find_element(
"#sidebar #link-" + page_name.replace(" ", "-"),
).click()

# check page title is expected
try:
dash_duo.wait_for_text_to_equal("h1", page_title, timeout=timeout)

except selenium.common.exceptions.TimeoutException:
pytest.fail(
f"Timeout waiting for page {page_name} "
"to show a title with the text: "
f"{page_title}"
)

dash_duo.find_element("#sidebar #link-Home").click()
# 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