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 98cbea8 commit 1aeaee9
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
3 changes: 2 additions & 1 deletion qe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
"outputs": [],
"source": [
"import ipywidgets as ipw\n",
"from aiidalab_qe.app import static\n",
"from importlib_resources import files\n",
"from IPython.display import display\n",
"\n",
"from aiidalab_qe.app import static\n",
"\n",
"# load CSS stylesheets\n",
"for stylesheet in [\"style\", \"custom\"]:\n",
" css = files(static).joinpath(f\"{stylesheet}.css\")\n",
Expand Down
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 1aeaee9

Please sign in to comment.