diff --git a/vizro-core/src/vizro/models/_components/table.py b/vizro-core/src/vizro/models/_components/table.py index ef5f85ecb..fdaa06aab 100644 --- a/vizro-core/src/vizro/models/_components/table.py +++ b/vizro-core/src/vizro/models/_components/table.py @@ -40,7 +40,7 @@ class Table(VizroBaseModel): # Convenience wrapper/syntactic sugar. def __call__(self, **kwargs): kwargs.setdefault("data_frame", data_manager._get_component_data(self.id)) # type: ignore[arg-type] - return self.table(**kwargs) + return self.figure(**kwargs) # Convenience wrapper/syntactic sugar. def __getitem__(self, arg_name: str): diff --git a/vizro-core/tests/unit/vizro/models/_components/test_table.py b/vizro-core/tests/unit/vizro/models/_components/test_table.py index 1987630cc..a072fdb56 100644 --- a/vizro-core/tests/unit/vizro/models/_components/test_table.py +++ b/vizro-core/tests/unit/vizro/models/_components/test_table.py @@ -1,8 +1,10 @@ """Unit tests for vizro.models.Table.""" import json +import pandas as pd +import plotly import pytest -from dash import dcc +from dash import dash_table, html from pydantic import ValidationError import vizro.models as vm @@ -10,29 +12,27 @@ from vizro.managers import data_manager from vizro.models._action._action import Action from vizro.tables import dash_data_table -import plotly -from dash import dash_table, html - -import pandas as pd @pytest.fixture def standard_dash_table(): return dash_data_table(data_frame=px.data.gapminder()) + @pytest.fixture def dash_table_with_arguments(): return dash_data_table(data_frame=px.data.gapminder(), style_header={"border": "1px solid green"}) + @pytest.fixture def dash_table_with_str_dataframe(): return dash_data_table(data_frame="gapminder") + @pytest.fixture def expected_table(): - return html.Div( - dash_table.DataTable(pd.DataFrame().to_dict("records"), []), id="text_table" - ) + return html.Div(dash_table.DataTable(pd.DataFrame().to_dict("records"), []), id="text_table") + class TestDunderMethodsTable: def test_create_graph_mandatory_only(self, standard_dash_table): @@ -59,14 +59,14 @@ def test_mandatory_figure_missing(self): with pytest.raises(ValidationError, match="field required"): vm.Table() - def test_failed_graph_with_no_captured_callable(self, standard_go_chart): + def test_failed_table_with_no_captured_callable(self, standard_go_chart): with pytest.raises(ValidationError, match="must provide a valid CapturedCallable object"): vm.Table( figure=standard_go_chart, ) @pytest.mark.xfail(reason="This test is failing as we are not yet detecting different types of captured callables") - def test_failed_graph_with_no_captured_callable(self, standard_px_chart): + def test_failed_table_with_wrong_captured_callable(self, standard_px_chart): with pytest.raises(ValidationError, match="must provide a valid table function vm.Table"): vm.Table( figure=standard_px_chart, @@ -118,7 +118,6 @@ def test_process_figure_data_frame_df(self, standard_dash_table, gapminder): table_with_str_df.figure["data_frame"] - class TestBuildTable: def test_graph_build(self, standard_dash_table, expected_table): table = vm.Table(