Skip to content

Commit

Permalink
Move test for default navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
huong-li-nguyen committed Oct 30, 2023
1 parent 63391a2 commit 14ae166
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 10 additions & 6 deletions vizro-core/tests/unit/vizro/models/_navigation/test_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
class TestNavigationInstantiation:
"""Tests navigation model instantiation ."""

@pytest.mark.parametrize("navigation", [None, vm.Navigation()])
def test_navigation_default(self, page1, page2, navigation):
# Navigation is optional inside Dashboard and navigation.pages will always be auto-populated if not provided
dashboard = vm.Dashboard(pages=[page1, page2], navigation=navigation)
assert hasattr(dashboard.navigation, "id")
assert dashboard.navigation.pages == ["Page 1", "Page 2"]
def test_navigation_mandatory_only(self):
navigation = vm.Navigation()
assert hasattr(navigation, "id")
assert navigation.pages == ["Page 1", "Page 2"]

# TODO: Extend this test with optional selectors
def test_navigation_mandatory_and_optional(self):
navigation = vm.Navigation(id="navigation")
assert navigation.id == "navigation"
assert navigation.pages == ["Page 1", "Page 2"]

def test_navigation_valid_pages_as_list(self, pages_as_list):
navigation = vm.Navigation(pages=pages_as_list, id="navigation")
Expand Down
4 changes: 4 additions & 0 deletions vizro-core/tests/unit/vizro/models/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,17 @@ def test_create_dashboard_mandatory_only(self, page1, page2):
assert dashboard.pages == [page1, page2]
assert dashboard.theme == "vizro_dark"
assert dashboard.title is None
assert isinstance(dashboard.navigation, vm.Navigation)
assert dashboard.navigation.pages == ["Page 1", "Page 2"]

def test_create_dashboard_mandatory_and_optional(self, page1, page2):
dashboard = vm.Dashboard(pages=[page1, page2], theme="vizro_light", title="Vizro")
assert hasattr(dashboard, "id")
assert dashboard.pages == [page1, page2]
assert dashboard.theme == "vizro_light"
assert dashboard.title == "Vizro"
assert isinstance(dashboard.navigation, vm.Navigation)
assert dashboard.navigation.pages == ["Page 1", "Page 2"]

def test_mandatory_pages_missing(self):
with pytest.raises(ValidationError, match="field required"):
Expand Down

0 comments on commit 14ae166

Please sign in to comment.