diff --git a/qe.ipynb b/qe.ipynb index 19accf105..32e3604e1 100644 --- a/qe.ipynb +++ b/qe.ipynb @@ -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", diff --git a/tests/test_infobox.py b/tests/test_infobox.py new file mode 100644 index 000000000..40d9f66a7 --- /dev/null +++ b/tests/test_infobox.py @@ -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", + ) + ) diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py new file mode 100644 index 000000000..609fa40d8 --- /dev/null +++ b/tests/test_wrapper.py @@ -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)