From 20e3826360ff6411b18c10e2478977abf16c92d7 Mon Sep 17 00:00:00 2001 From: Edan Bainglass Date: Fri, 30 Aug 2024 11:57:59 +0000 Subject: [PATCH] Add notebook test for CSS loader --- tests_notebooks/static/styles/test.css | 3 ++ tests_notebooks/test_notebook.ipynb | 67 ++++++++++++++++++++++++++ tests_notebooks/test_notebooks.py | 9 ++++ 3 files changed, 79 insertions(+) create mode 100644 tests_notebooks/static/styles/test.css create mode 100644 tests_notebooks/test_notebook.ipynb diff --git a/tests_notebooks/static/styles/test.css b/tests_notebooks/static/styles/test.css new file mode 100644 index 000000000..9e805f497 --- /dev/null +++ b/tests_notebooks/static/styles/test.css @@ -0,0 +1,3 @@ +.red-text { + color: rgb(255, 0, 0); +} diff --git a/tests_notebooks/test_notebook.ipynb b/tests_notebooks/test_notebook.ipynb new file mode 100644 index 000000000..5bf91429e --- /dev/null +++ b/tests_notebooks/test_notebook.ipynb @@ -0,0 +1,67 @@ +{ + "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": [ + "from aiidalab_widgets_base.utils.loaders import load_css\n", + "\n", + "load_css(css_path=\"static/styles/test.css\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "label = ipw.Label(\"Testing\")\n", + "label.add_class(\"red-text\")\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..9fdf08f23 100644 --- a/tests_notebooks/test_notebooks.py +++ b/tests_notebooks/test_notebooks.py @@ -5,6 +5,15 @@ from selenium.webdriver.common.keys import Keys +def test_loaded_css(selenium_driver): + driver = selenium_driver("tests_notebooks/test_notebook.ipynb") + element = driver.find_element(By.CLASS_NAME, "red-text") + assert element.value_of_css_property("color") in ( + "rgba(255, 0, 0, 1)", # Chrome + "rgb(255, 0, 0)", # Firefox + ) + + def test_notebook_service_available(notebook_service): url, token = notebook_service response = requests.get(f"{url}/?token={token}")