From c3880d0c10fd4febe18c2f6bbf423b17e4eecf34 Mon Sep 17 00:00:00 2001 From: Edan Bainglass Date: Wed, 21 Aug 2024 18:03:19 +0000 Subject: [PATCH] Add notebook test for CSS loader --- aiidalab_widgets_base/static/styles/test.css | 3 + notebooks/test.ipynb | 68 ++++++++++++++++++++ tests_notebooks/test_notebooks.py | 7 ++ 3 files changed, 78 insertions(+) create mode 100644 aiidalab_widgets_base/static/styles/test.css create mode 100644 notebooks/test.ipynb diff --git a/aiidalab_widgets_base/static/styles/test.css b/aiidalab_widgets_base/static/styles/test.css new file mode 100644 index 000000000..94497588b --- /dev/null +++ b/aiidalab_widgets_base/static/styles/test.css @@ -0,0 +1,3 @@ +.for-testing-purposes { + color: rgb(255, 0, 0); +} diff --git a/notebooks/test.ipynb b/notebooks/test.ipynb new file mode 100644 index 000000000..a03b887cd --- /dev/null +++ b/notebooks/test.ipynb @@ -0,0 +1,68 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import ipywidgets as ipw" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from aiida import load_profile\n", + "\n", + "load_profile();" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# DO NOT REMOVE!\n", + "# This triggers required jupyter-notebook specific actions.\n", + "# See `aiidalab_widgets_base.__init__.py` for details\n", + "import aiidalab_widgets_base" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "label = ipw.Label(\"Testing\")\n", + "label.add_class(\"for-testing-purposes\")\n", + "display(label)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/tests_notebooks/test_notebooks.py b/tests_notebooks/test_notebooks.py index a1d6c3977..84084f14a 100644 --- a/tests_notebooks/test_notebooks.py +++ b/tests_notebooks/test_notebooks.py @@ -5,6 +5,13 @@ from selenium.webdriver.common.keys import Keys +def test_load_css_stylesheet(selenium_driver): + """Test `load_css_stylesheet` function.""" + driver = selenium_driver("notebooks/test.ipynb") + element = driver.find_element(By.CLASS_NAME, "for-testing-purposes") + assert element.value_of_css_property("color") == "rgba(255, 0, 0)" + + def test_notebook_service_available(notebook_service): url, token = notebook_service response = requests.get(f"{url}/?token={token}")