Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Jul 8, 2024
1 parent 8a358d7 commit 2bb8bb8
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/test_infobox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from aiidalab_qe.app.infobox import InfoBox


def test_infobox_classes():
"""Test `InfoBox` classes."""
infobox = InfoBox()
assert "info-box" in infobox._dom_classes
infobox = InfoBox(**{"custom-css": "custom-info-box"})
assert all(
css_class in infobox._dom_classes
for css_class in [
"info-box",
"custom-info-box",
]
)
64 changes: 64 additions & 0 deletions tests/test_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from aiidalab_qe.app.wrapper import AppWrapperContoller, AppWrapperModel, AppWrapperView


class TestWrapper:
def test_enable_toggles(self):
"""Test enable_toggles method."""
self._instansiate_mvc_components()
assert self.view.guide_toggle.disabled is True
assert self.view.about_toggle.disabled is True
self.controller.enable_toggles()
assert self.view.guide_toggle.disabled is False
assert self.view.about_toggle.disabled is False

def test_guide_toggle(self):
"""Test guide_toggle method."""
self._instansiate_mvc_components()
self.controller.enable_toggles()
self.controller._on_guide_toggle({"new": True})
self._assert_guide_is_on()
self.controller._on_guide_toggle({"new": False})
self._assert_no_guide_info()

def test_about_toggle(self):
"""Test about_toggle method."""
self._instansiate_mvc_components()
self.controller.enable_toggles()
self.controller._on_about_toggle({"new": True})
self._assert_about_is_on()
self.controller._on_about_toggle({"new": False})
self._assert_no_guide_info()

def test_toggle_switch(self):
"""Test toggle_switch method."""
self._instansiate_mvc_components()
self.controller.enable_toggles()
self._assert_no_guide_info()
self.controller._on_guide_toggle({"new": True})
self._assert_guide_is_on()
self.controller._on_about_toggle({"new": True})
self._assert_about_is_on()
self.controller._on_guide_toggle({"new": True})
self._assert_guide_is_on()
self.controller._on_guide_toggle({"new": False})
self._assert_no_guide_info()

def _assert_guide_is_on(self):
"""Assert guide is on."""
assert len(self.view.info_container.children) == 1
assert self.view.guide in self.view.info_container.children

def _assert_about_is_on(self):
"""Assert about is on."""
assert len(self.view.info_container.children) == 1
assert self.view.about in self.view.info_container.children

def _assert_no_guide_info(self):
"""Assert no info is shown."""
assert len(self.view.info_container.children) == 0

def _instansiate_mvc_components(self):
"""Instansiate `AppWrapper` MVC components."""
self.model = AppWrapperModel()
self.view = AppWrapperView()
self.controller = AppWrapperContoller(self.model, self.view)

0 comments on commit 2bb8bb8

Please sign in to comment.