Skip to content

Commit

Permalink
Merge branch 'qa/move_integration_tests_to_vizro' of https://github.c…
Browse files Browse the repository at this point in the history
…om/mckinsey/vizro into qa/move_integration_tests_to_vizro
  • Loading branch information
l0uden committed Jan 13, 2025
2 parents 33141fe + 40b382c commit 87229fb
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 132 deletions.
16 changes: 5 additions & 11 deletions vizro-core/tests/e2e/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from datetime import datetime

import e2e_constants as cnst
import pytest
from e2e_checkers import browser_console_warnings_checker
from selenium.common import WebDriverException
from selenium.webdriver.chrome.options import Options as ChromeOptions
from e2e_checkers import browser_console_warnings_checker
import e2e_constants as cnst

# functions

Expand All @@ -20,11 +20,7 @@ def pytest_setup_options():
def make_teardown(driver):
# checking for browser console errors
try:
log_levels = [
level
for level in driver.get_log("browser")
if level["level"] == "SEVERE" or "WARNING"
]
log_levels = [level for level in driver.get_log("browser") if level["level"] == "SEVERE" or "WARNING"]
if log_levels:
for log_level in log_levels:
browser_console_warnings_checker(log_level, log_levels)
Expand All @@ -35,10 +31,8 @@ def make_teardown(driver):

# make a screenshot with a name of the test, date and time
def take_screenshot(driver, nodeid):
file_name = (
f'{nodeid}_{datetime.today().strftime("%Y-%m-%d_%H-%M-%S-%f")}.png'.replace(
"/", "_"
).replace("::", "__")
file_name = f'{nodeid}_{datetime.today().strftime("%Y-%m-%d_%H-%M-%S-%f")}.png'.replace("/", "_").replace(
"::", "__"
)
driver.save_screenshot(file_name)

Expand Down
37 changes: 5 additions & 32 deletions vizro-core/tests/e2e/dashboards/default/dashboard.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
from functools import partial
import e2e_constants as cnst
from dashboard_pages import ag_grid_page, datepicker_page, filters_page, homepage, kpi_indicators_page, parameters_page

import pandas as pd
import vizro.models as vm
import vizro.plotly.express as px
import yaml
from flask_caching import Cache
from vizro import Vizro
from vizro.actions import export_data, filter_interaction
from vizro.figures import kpi_card, kpi_card_reference
from vizro.managers import data_manager
from vizro.tables import dash_ag_grid, dash_data_table

import e2e_constants as cnst
from e2e_custom_feature_helpers.custom_actions.custom_actions import my_custom_action
from e2e_custom_feature_helpers.custom_charts.bar_custom import bar_with_highlight
from e2e_custom_feature_helpers.custom_components.new_dropdown import NewDropdown
from e2e_custom_feature_helpers.custom_components.range_slider_non_cross import RangeSliderNonCross

from dashboard_pages import homepage, filters_page, parameters_page, kpi_indicators_page, datepicker_page, ag_grid_page

dashboard = vm.Dashboard(
title="Vizro dashboard for integration testing",
pages=[
homepage,
filters_page,
parameters_page,
kpi_indicators_page,
datepicker_page,
ag_grid_page
],
pages=[homepage, filters_page, parameters_page, kpi_indicators_page, datepicker_page, ag_grid_page],
navigation=vm.Navigation(
pages={
cnst.GENERAL_ACCORDION: [
Expand All @@ -37,13 +15,8 @@
cnst.PARAMETERS_PAGE,
cnst.KPI_INDICATORS_PAGE,
],
cnst.DATEPICKER_ACCORDION: [
cnst.DATEPICKER_PAGE
],
cnst.AG_GRID_ACCORDION: [
cnst.TABLE_AG_GRID_PAGE
],

cnst.DATEPICKER_ACCORDION: [cnst.DATEPICKER_PAGE],
cnst.AG_GRID_ACCORDION: [cnst.TABLE_AG_GRID_PAGE],
}
),
theme="vizro_light",
Expand Down
103 changes: 72 additions & 31 deletions vizro-core/tests/e2e/dashboards/default/dashboard_pages.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import e2e_constants as cnst
import pandas as pd
from flask_caching import Cache

import vizro.models as vm
import e2e_constants as cnst
import vizro.plotly.express as px
import pandas as pd
from vizro.actions import export_data
from vizro.figures import kpi_card, kpi_card_reference
from vizro.tables import dash_data_table, dash_ag_grid
from vizro.managers import data_manager
from vizro.tables import dash_ag_grid, dash_data_table

iris = px.data.iris()
gapminder = px.data.gapminder()
Expand All @@ -17,12 +17,67 @@
)
datepicker_df = pd.DataFrame(
[
["2016-05-16 20:42:31", "Male", 35, "$30,000 to $39,999", "Employed for wages", "mechanical drafter", "Associate degree", None],
["2016-05-16", "Male", 21, "$1 to $10,000", "Out of work and looking for work", "-", "Some college, no degree", "join clubs/socual clubs/meet ups"],
["2016-05-17", "Male", 22, "$0", "Out of work but not currently looking for work", "unemployed, Some college", "no degree", "Other exercise"],
["2016-05-18", "Male", 19, "$1 to $10,000", "A student", "student", "Some college, no degree", "Joined a gym/go to the gym"],
["2016-05-18", "Male", 23, "$30,000 to $39,999", "Employed for wages", "Factory worker", "High school graduate, diploma or the equivalent (for example: GED)", None],
["2016-05-19", "Male", 23, "$30,000 to $39,999", "Employed for wages", "Factory worker", "High school graduate, diploma or the equivalent (for example: GED)", None]],
[
"2016-05-16 20:42:31",
"Male",
35,
"$30,000 to $39,999",
"Employed for wages",
"mechanical drafter",
"Associate degree",
None,
],
[
"2016-05-16",
"Male",
21,
"$1 to $10,000",
"Out of work and looking for work",
"-",
"Some college, no degree",
"join clubs/socual clubs/meet ups",
],
[
"2016-05-17",
"Male",
22,
"$0",
"Out of work but not currently looking for work",
"unemployed, Some college",
"no degree",
"Other exercise",
],
[
"2016-05-18",
"Male",
19,
"$1 to $10,000",
"A student",
"student",
"Some college, no degree",
"Joined a gym/go to the gym",
],
[
"2016-05-18",
"Male",
23,
"$30,000 to $39,999",
"Employed for wages",
"Factory worker",
"High school graduate, diploma or the equivalent (for example: GED)",
None,
],
[
"2016-05-19",
"Male",
23,
"$30,000 to $39,999",
"Employed for wages",
"Factory worker",
"High school graduate, diploma or the equivalent (for example: GED)",
None,
],
],
columns=["time", "gender", "age", "income", "employment", "job_title", "edu_level", "improve_yourself_how"],
)

Expand All @@ -32,9 +87,7 @@ def load_datepicker_data():
return datepicker_df


data_manager.cache = Cache(
config={"CACHE_TYPE": "FileSystemCache", "CACHE_DIR": "cache"}
)
data_manager.cache = Cache(config={"CACHE_TYPE": "FileSystemCache", "CACHE_DIR": "cache"})
data_manager["datepicker_df"] = load_datepicker_data
data_manager["datepicker_df"].timeout = 10

Expand Down Expand Up @@ -273,31 +326,23 @@ def load_datepicker_data():
controls=[
vm.Parameter(
targets=[f"{cnst.HISTOGRAM_GRAPH_ID}.color_discrete_map.setosa"],
selector=vm.Dropdown(
options=["NONE", "red", "blue"], multi=False, value="blue"
),
selector=vm.Dropdown(options=["NONE", "red", "blue"], multi=False, value="blue"),
),
vm.Parameter(
targets=[f"{cnst.BAR_GRAPH_ID}.color_discrete_map.virginica"],
selector=vm.Dropdown(
options=["NONE", "red", "blue"], multi=False, value="blue"
),
selector=vm.Dropdown(options=["NONE", "red", "blue"], multi=False, value="blue"),
),
vm.Parameter(
targets=[f"{cnst.BAR_GRAPH_ID}.title", f"{cnst.HISTOGRAM_GRAPH_ID}.title"],
selector=vm.RadioItems(options=["red", "blue"], value="blue"),
),
vm.Parameter(
targets=[f"{cnst.BAR_GRAPH_ID}.y"],
selector=vm.RadioItems(
options=["petal_width", "petal_length"], value="petal_width"
),
selector=vm.RadioItems(options=["petal_width", "petal_length"], value="petal_width"),
),
vm.Parameter(
targets=[f"{cnst.BAR_GRAPH_ID}.opacity"],
selector=vm.Slider(
min=0, max=1, value=0.2, step=0.2, title="Bubble opacity"
),
selector=vm.Slider(min=0, max=1, value=0.2, step=0.2, title="Bubble opacity"),
),
vm.Parameter(
targets=[f"{cnst.HISTOGRAM_GRAPH_ID}.range_x"],
Expand Down Expand Up @@ -467,15 +512,11 @@ def load_datepicker_data():
vm.AgGrid(
id=cnst.TABLE_AG_GRID_ID,
title="Equal Title One",
figure=dash_ag_grid(
data_frame=gapminder, dashGridOptions={"pagination": True}
),
figure=dash_ag_grid(data_frame=gapminder, dashGridOptions={"pagination": True}),
),
vm.Graph(
id=cnst.BOX_AG_GRID_PAGE_ID,
figure=px.box(
gapminder, x="continent", y="lifeExp", title="Equal Title One"
)
figure=px.box(gapminder, x="continent", y="lifeExp", title="Equal Title One"),
),
],
)
Expand All @@ -502,4 +543,4 @@ def load_datepicker_data():
selector=vm.RangeSlider(step=1000000.0, min=1000000, max=10000000),
),
],
)
)
2 changes: 1 addition & 1 deletion vizro-core/tests/e2e/dashboards/wait_for_dashboard.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

tests/e2e/dashboards/wait-for-it.sh 127.0.0.1:5001 -t 30
tests/e2e/dashboards/wait-for-it.sh 127.0.0.1:5001 -t 30
2 changes: 1 addition & 1 deletion vizro-core/tests/e2e/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[pytest]
markers =
e2e_integration_tests: marks only tests for running as e2e_integration
e2e_integration_tests: marks only tests for running as e2e_integration
3 changes: 1 addition & 2 deletions vizro-core/tests/e2e/test_charts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest

import e2e_constants as cnst
import pytest
from e2e_checkers import check_text
from e2e_helpers import webdriver_click_waiter, webdriver_waiter
from e2e_paths import href_path, nav_card_text_path
Expand Down
9 changes: 4 additions & 5 deletions vizro-core/tests/e2e/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import pytest
from hamcrest import assert_that, equal_to
from selenium.webdriver.common.by import By

import e2e_constants as cnst
import pytest
from e2e_checkers import (
check_graph_is_loading,
check_range_slider_value,
check_slider_value,
)
from e2e_helpers import webdriver_click_waiter, webdriver_waiter, graph_load_waiter
from e2e_helpers import graph_load_waiter, webdriver_click_waiter, webdriver_waiter
from e2e_navigation import page_select
from e2e_paths import (
checklist_value_path,
Expand All @@ -20,6 +17,8 @@
range_slider_value_path,
slider_value_path,
)
from hamcrest import assert_that, equal_to
from selenium.webdriver.common.by import By

pytestmark = pytest.mark.e2e_integration_tests

Expand Down
21 changes: 14 additions & 7 deletions vizro-core/tests/e2e/test_pages.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import pytest

import e2e_constants as cnst
import pytest
from e2e_checkers import (
check_accordion,
check_ag_grid_theme_color,
check_graph_color,
check_text,
check_theme_color, check_ag_grid_theme_color,
check_theme_color,
)
from e2e_helpers import (
graph_load_waiter,
webdriver_click_waiter,
webdriver_waiter, graph_load_waiter,
webdriver_waiter,
)
from e2e_navigation import page_select
from e2e_paths import (
Expand Down Expand Up @@ -79,8 +80,12 @@ def test_themes(dash_br_driver, dashboard_id):
indirect=["dash_br_driver"],
)
def test_ag_grid_themes(dash_br_driver, dashboard_id):
page_select(dash_br_driver, page_name=cnst.TABLE_AG_GRID_PAGE,
graph_id=cnst.BOX_AG_GRID_PAGE_ID, accordion_name=cnst.AG_GRID_ACCORDION)
page_select(
dash_br_driver,
page_name=cnst.TABLE_AG_GRID_PAGE,
graph_id=cnst.BOX_AG_GRID_PAGE_ID,
accordion_name=cnst.AG_GRID_ACCORDION,
)
if dashboard_id == cnst.DASHBOARD_DEFAULT:
check_ag_grid_theme_color(dash_br_driver, ag_grid_id=cnst.TABLE_AG_GRID_ID, color=cnst.AG_GRID_LIGHT)
webdriver_click_waiter(dash_br_driver, xpath=theme_toggle_path())
Expand All @@ -106,7 +111,9 @@ def test_themes_page_change(dash_br_driver, dashboard_id):
def _logic(style_background, graph_color, theme_color):
check_graph_color(dash_br_driver, xpath=graph_bar, style_background=style_background, color=graph_color)
check_theme_color(dash_br_driver, color=theme_color)
webdriver_click_waiter(dash_br_driver, tab_path(tab_id=cnst.PARAMETERS_SUB_TAB_CONTAINER_TWO, classname="nav-link"))
webdriver_click_waiter(
dash_br_driver, tab_path(tab_id=cnst.PARAMETERS_SUB_TAB_CONTAINER_TWO, classname="nav-link")
)
check_graph_color(dash_br_driver, xpath=graph_bar, style_background=style_background, color=graph_color)
page_select(dash_br_driver, page_name=cnst.FILTERS_PAGE, graph_id=cnst.SCATTER_GRAPH_ID)
page_select(dash_br_driver, page_name=cnst.PARAMETERS_PAGE, graph_id=cnst.BAR_GRAPH_ID)
Expand Down
Loading

0 comments on commit 87229fb

Please sign in to comment.