Skip to content

Commit

Permalink
tests review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
l0uden committed Feb 26, 2025
1 parent 537820a commit 8e47ba9
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


@capture("table")
def custom_table(data_frame=None, chosen_columns: Optional[list[str]] = None):
def table_with_filtered_columns(data_frame=None, chosen_columns: Optional[list[str]] = None):
"""Custom table with added logic to filter on chosen columns."""
columns = [{"name": i, "id": i} for i in chosen_columns]
defaults = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
controls=[
vm.Filter(
column="species",
targets=[cnst.AREA_GRAPH_ID],
selector=vm.Dropdown(id=cnst.DROPDOWN_FILTER_HOMEPAGE, multi=False),
),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from custom_charts.table_custom import custom_table
from custom_charts.table_custom import table_with_filtered_columns
from e2e.vizro import constants as cnst

import vizro.models as vm
Expand All @@ -13,15 +13,15 @@
vm.Table(
id=cnst.TABLE_DROPDOWN,
title="Dropdown",
figure=custom_table(
figure=table_with_filtered_columns(
data_frame=gapminder_2007,
chosen_columns=["country", "continent", "lifeExp", "pop", "gdpPercap"],
),
),
vm.Table(
id=cnst.TABLE_CHECKLIST,
title="Checklist",
figure=custom_table(
figure=table_with_filtered_columns(
data_frame=gapminder_2007,
chosen_columns=["country", "continent", "lifeExp", "pop", "gdpPercap"],
),
Expand All @@ -38,7 +38,6 @@
id=cnst.DROPDOWN_PARAM_MULTI,
title="Choose columns",
options=gapminder_2007.columns.to_list(),
multi=True,
),
),
],
Expand Down
55 changes: 40 additions & 15 deletions vizro-core/tests/e2e/vizro/test_dom_elements/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,37 @@
check_slider_value,
)
from e2e.vizro.navigation import page_select
from e2e.vizro.paths import categorical_components_value_path, select_all_path, slider_value_path
from e2e.vizro.paths import categorical_components_value_path, dropdown_arrow_path, select_all_path, slider_value_path
from e2e.vizro.waiters import graph_load_waiter
from hamcrest import assert_that, equal_to


def test_dropdown_all_value(dash_br):
def test_dropdown_select_all_value(dash_br):
"""Test interacts with Select All checkbox in dropdown.
1. Click 'Select All'. It will clear all chosen options.
2. Check how options in dropdown looks like.
3. Click 'Select All'. It will make all options chosen.
4. Check how options in dropdown looks like.
"""
page_select(dash_br, page_path=cnst.FILTERS_PAGE_PATH, page_name=cnst.FILTERS_PAGE, graph_id=cnst.SCATTER_GRAPH_ID)
# unselect 'ALL'
dash_br.multiple_click(".Select-arrow", 1)
# click dropdown arrow to open the list
dash_br.multiple_click(dropdown_arrow_path(), 1)
# unselect 'Select All'
dash_br.multiple_click(select_all_path(elem_id=cnst.DROPDOWN_FILTER_FILTERS_PAGE), 1)
check_graph_is_loading(dash_br, graph_id=cnst.SCATTER_GRAPH_ID)
dash_br.multiple_click(".Select-arrow", 1)
dash_br.multiple_click(dropdown_arrow_path(), 1)
check_selected_dropdown(
dash_br,
dropdown_id=cnst.DROPDOWN_FILTER_FILTERS_PAGE,
all_value=False,
expected_selected_options=[],
expected_unselected_options=["setosa", "versicolor", "virginica"],
)
# select 'ALL'
# select 'Select All'
dash_br.multiple_click(select_all_path(elem_id=cnst.DROPDOWN_FILTER_FILTERS_PAGE), 1)
check_graph_is_loading(dash_br, graph_id=cnst.SCATTER_GRAPH_ID)
dash_br.multiple_click(".Select-arrow", 1)
dash_br.multiple_click(dropdown_arrow_path(), 1)
check_selected_dropdown(
dash_br,
dropdown_id=cnst.DROPDOWN_FILTER_FILTERS_PAGE,
Expand All @@ -39,7 +47,14 @@ def test_dropdown_all_value(dash_br):
)


def test_dropdown_options_value(dash_br):
def test_dropdown_options_values(dash_br):
"""Test interacts with options values in dropdown.
1. Delete 'virginica' option.
2. Check how options in dropdown looks like.
3. Clear all chosen options and select 'setosa' only.
4. Check how options in dropdown looks like.
"""
page_select(dash_br, page_path=cnst.FILTERS_PAGE_PATH, page_name=cnst.FILTERS_PAGE, graph_id=cnst.SCATTER_GRAPH_ID)
# delete last option 'virginica'
dash_br.clear_input(f"#{cnst.DROPDOWN_FILTER_FILTERS_PAGE}")
Expand All @@ -51,11 +66,13 @@ def test_dropdown_options_value(dash_br):
expected_selected_options=["setosa", "versicolor"],
expected_unselected_options=["virginica"],
)
# clear dropdown and choose one option 'setosa'
dash_br.multiple_click(".Select-clear", 1)
# clear dropdown
dash_br.clear_input(f"#{cnst.DROPDOWN_FILTER_FILTERS_PAGE}")
dash_br.clear_input(f"#{cnst.DROPDOWN_FILTER_FILTERS_PAGE}")
# choose one option 'setosa'
dash_br.select_dcc_dropdown(f"#{cnst.DROPDOWN_FILTER_FILTERS_PAGE}", "setosa")
check_graph_is_loading(dash_br, graph_id=cnst.SCATTER_GRAPH_ID)
dash_br.multiple_click(".Select-arrow", 1)
dash_br.multiple_click(dropdown_arrow_path(), 1)
check_selected_dropdown(
dash_br,
dropdown_id=cnst.DROPDOWN_FILTER_FILTERS_PAGE,
Expand All @@ -66,13 +83,14 @@ def test_dropdown_options_value(dash_br):


def test_dropdown_persistence(dash_br):
"""Check that chosen values persistent after page reload."""
page_select(dash_br, page_path=cnst.FILTERS_PAGE_PATH, page_name=cnst.FILTERS_PAGE, graph_id=cnst.SCATTER_GRAPH_ID)
# delete last option 'virginica'
dash_br.clear_input(f"#{cnst.DROPDOWN_FILTER_FILTERS_PAGE}")
check_graph_is_loading(dash_br, graph_id=cnst.SCATTER_GRAPH_ID)
page_select(dash_br, page_path=cnst.HOME_PAGE_PATH, page_name=cnst.HOME_PAGE, graph_id=cnst.AREA_GRAPH_ID)
page_select(dash_br, page_path=cnst.FILTERS_PAGE_PATH, page_name=cnst.FILTERS_PAGE, graph_id=cnst.SCATTER_GRAPH_ID)
dash_br.multiple_click(".Select-arrow", 1)
dash_br.multiple_click(dropdown_arrow_path(), 1)
check_selected_dropdown(
dash_br,
dropdown_id=cnst.DROPDOWN_FILTER_FILTERS_PAGE,
Expand All @@ -88,6 +106,7 @@ def test_dropdown_persistence(dash_br):
ids=["checklist", "radio_items"],
)
def test_categorical_filters(dash_br, filter_id):
"""Check if checklist and radio_items available and triggering graph reload."""
page_select(dash_br, page_path=cnst.FILTERS_PAGE_PATH, page_name=cnst.FILTERS_PAGE, graph_id=cnst.SCATTER_GRAPH_ID)
dash_br.multiple_click(categorical_components_value_path(elem_id=filter_id, value=2), 1)
check_graph_is_loading(dash_br, graph_id=cnst.SCATTER_GRAPH_ID)
Expand Down Expand Up @@ -136,11 +155,12 @@ def test_categorical_filters(dash_br, filter_id):
"unchecked one option",
"checked one option only",
"unchecked all options",
"unchecked 'ALL' only",
"checked 'ALL' only",
"unchecked 'Select All' only",
"checked 'Select All' only",
],
)
def test_checklist(dash_br, value_paths, select_all_status, options_value_status):
"""Checks checklist with different options selected."""
filter_id = cnst.CHECK_LIST_FILTER_FILTERS_PAGE
page_select(dash_br, page_path=cnst.FILTERS_PAGE_PATH, page_name=cnst.FILTERS_PAGE, graph_id=cnst.SCATTER_GRAPH_ID)
for path in value_paths:
Expand All @@ -152,6 +172,7 @@ def test_checklist(dash_br, value_paths, select_all_status, options_value_status


def test_checklist_persistence(dash_br):
"""Check that chosen values persistent after page reload."""
filter_id = cnst.CHECK_LIST_FILTER_FILTERS_PAGE
page_select(dash_br, page_path=cnst.FILTERS_PAGE_PATH, page_name=cnst.FILTERS_PAGE, graph_id=cnst.SCATTER_GRAPH_ID)
dash_br.multiple_click(categorical_components_value_path(elem_id=cnst.CHECK_LIST_FILTER_FILTERS_PAGE, value=2), 1)
Expand All @@ -171,6 +192,7 @@ def test_checklist_persistence(dash_br):


def test_slider(dash_br):
"""Checks if slider available and triggering graph reload. Also checks new slider value."""
page_select(dash_br, page_path=cnst.FILTERS_PAGE_PATH, page_name=cnst.FILTERS_PAGE, graph_id=cnst.SCATTER_GRAPH_ID)
dash_br.multiple_click(slider_value_path(elem_id=cnst.SLIDER_FILTER_FILTERS_PAGE, value=2), 1)
check_graph_is_loading(dash_br, graph_id=cnst.SCATTER_GRAPH_ID)
Expand All @@ -181,6 +203,7 @@ def test_slider(dash_br):
# Right now is failing with the next error:
# AssertionError: Element number is '4', but expected number is '4.3'
def test_range_slider(dash_br):
"""Checks if range_slider available and triggering graph reload. Also checks new range_slider values."""
page_select(dash_br, page_path=cnst.FILTERS_PAGE_PATH, page_name=cnst.FILTERS_PAGE, graph_id=cnst.SCATTER_GRAPH_ID)
dash_br.multiple_click(slider_value_path(elem_id=cnst.RANGE_SLIDER_FILTER_FILTERS_PAGE, value=4), 1)
check_graph_is_loading(dash_br, graph_id=cnst.SCATTER_GRAPH_ID)
Expand All @@ -189,13 +212,15 @@ def test_range_slider(dash_br):
)


def test_dropdown_homepage(dash_br):
def test_dropdown_multi_false_homepage(dash_br):
"""Checks dropdown with multi=False."""
graph_load_waiter(dash_br, graph_id=cnst.AREA_GRAPH_ID)
dash_br.select_dcc_dropdown(f"#{cnst.DROPDOWN_FILTER_HOMEPAGE}", "virginica")
check_graph_is_loading(dash_br, cnst.AREA_GRAPH_ID)


def test_dropdown_kpi_indicators_page(dash_br):
"""Checks filtering for KPI cards."""
page_select(dash_br, page_path=cnst.KPI_INDICATORS_PAGE_PATH, page_name=cnst.KPI_INDICATORS_PAGE)
dash_br.wait_for_text_to_equal(".card-body", "67434")
values = dash_br.find_elements(".card-body")
Expand Down
24 changes: 18 additions & 6 deletions vizro-core/tests/e2e/vizro/test_dom_elements/test_parameters.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import e2e.vizro.constants as cnst
from e2e.vizro.checkers import check_selected_checklist, check_selected_dropdown
from e2e.vizro.navigation import page_select
from e2e.vizro.paths import categorical_components_value_path, select_all_path
from e2e.vizro.paths import categorical_components_value_path, dropdown_arrow_path, select_all_path


def test_checklist_all_value(dash_br):
def test_checklist_select_all_value(dash_br):
"""Checks parametrizing with multiple params by selecting columns for the table."""
page_select(dash_br, page_path=cnst.PARAMETERS_MULTI_PAGE_PATH, page_name=cnst.PARAMETERS_MULTI_PAGE)
# unselect 'Select All'
dash_br.multiple_click(select_all_path(elem_id=cnst.CHECKLIST_PARAM), 1)
# select 'country' parameter
dash_br.multiple_click(categorical_components_value_path(elem_id=cnst.CHECKLIST_PARAM, value=1), 1)
# select 'year' parameter
dash_br.multiple_click(categorical_components_value_path(elem_id=cnst.CHECKLIST_PARAM, value=3), 1)
# check if table column 'country' is available
dash_br.wait_for_element(f"#{cnst.TABLE_CHECKLIST} th[data-dash-column='country']")
# check if table column 'year' is available and no other column appears on the right
dash_br.wait_for_element(
f"#{cnst.TABLE_CHECKLIST} th[data-dash-column='year'][class='dash-header column-1 cell--right-last ']"
)
Expand All @@ -30,18 +36,24 @@ def test_checklist_all_value(dash_br):
)


def test_dropdown_all_value(dash_br):
def test_dropdown_select_all_value(dash_br):
"""Checks parametrizing with multiple params by selecting columns for the table."""
page_select(dash_br, page_path=cnst.PARAMETERS_MULTI_PAGE_PATH, page_name=cnst.PARAMETERS_MULTI_PAGE)
dash_br.multiple_click(".Select-arrow", 1)
dash_br.multiple_click(dropdown_arrow_path(), 1)
# unselect 'Select All'
dash_br.multiple_click(select_all_path(elem_id=cnst.DROPDOWN_PARAM_MULTI), 1)
dash_br.multiple_click(".Select-arrow", 1)
dash_br.multiple_click(dropdown_arrow_path(), 1)
# select 'pop' parameter
dash_br.select_dcc_dropdown(f"#{cnst.DROPDOWN_PARAM_MULTI}", "pop")
# select 'gdpPercap' parameter
dash_br.select_dcc_dropdown(f"#{cnst.DROPDOWN_PARAM_MULTI}", "gdpPercap")
# check if table column 'pop' is available
dash_br.wait_for_element(f"#{cnst.TABLE_DROPDOWN} th[data-dash-column='pop']")
# check if table column 'gdpPercap' is available and no other column appears on the right
dash_br.wait_for_element(
f"#{cnst.TABLE_DROPDOWN} th[data-dash-column='gdpPercap'][class='dash-header column-1 cell--right-last ']"
)
dash_br.multiple_click(".Select-arrow", 1)
dash_br.multiple_click(dropdown_arrow_path(), 1)
check_selected_dropdown(
dash_br,
dropdown_id=cnst.DROPDOWN_PARAM_MULTI,
Expand Down
4 changes: 4 additions & 0 deletions vizro-core/tests/tests_utils/e2e/vizro/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ def categorical_components_value_path(elem_id, value):
def select_all_path(elem_id):
"""Select All option path for checklist and dropdown."""
return f"input[id='{elem_id}_select_all']"


def dropdown_arrow_path():
return ".Select-arrow"

0 comments on commit 8e47ba9

Please sign in to comment.