ci: add site building and testing
authorPetr Štetiar <ynezz@true.cz>
Thu, 6 Aug 2020 12:37:23 +0000 (14:37 +0200)
committerPetr Štetiar <ynezz@true.cz>
Thu, 6 Aug 2020 17:26:07 +0000 (19:26 +0200)
To improve the QA.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
.gitignore [new file with mode: 0644]
.gitlab-ci.yml
tests/test_spa.py [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..782eb43
--- /dev/null
@@ -0,0 +1,3 @@
+build/
+node_modules/
+__pycache__/
index f1761b59832f5ac02480fccf3de2e2f9a7c1ab8e..9356e56bba43f462e37314be502d4f1ddf70477c 100644 (file)
@@ -22,3 +22,36 @@ check HTML, CSS and SVG with html5validator:
   image: cyb3rjak3/html5validator:latest
   script:
     - html5validator --root www --also-check-css --also-check-svg --show-warnings --log INFO
+
+build site on Python 3.8:
+  stage: pre-build
+  image: python:3.8-slim-buster
+  before_script:
+    - apt-get update; apt-get install -y make
+  script:
+    - cp -R ./www ./build
+    - misc/collect.py scrape https://downloads.openwrt.org build
+  artifacts:
+    expire_in: 1 week
+    when: always
+    paths:
+      - build
+
+test site with selenium:
+  stage: test
+  image: selenium/standalone-firefox:latest
+  script:
+    - /opt/bin/entry_point.sh &
+    - sudo apt-get update; sudo apt-get install -y python3-pip python3-pytest
+    - pip3 install selenium-firefox
+    - (cd build; python3 -m http.server &)
+    - pytest-3 tests
+
+build site for target environment:
+  stage: test
+  image: debian:9
+  before_script:
+    - apt-get update; apt-get install -y make python3
+  script:
+    - cp -R ./www ./build
+    - misc/collect.py scrape https://downloads.openwrt.org build
diff --git a/tests/test_spa.py b/tests/test_spa.py
new file mode 100644 (file)
index 0000000..5a2cecb
--- /dev/null
@@ -0,0 +1,41 @@
+from selenium import webdriver
+from selenium.webdriver.support.ui import Select
+from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
+
+
+def init_driver():
+    driver = webdriver.Remote(
+        command_executor="http://localhost:4444/wd/hub",
+        desired_capabilities=DesiredCapabilities.FIREFOX,
+    )
+    return driver
+
+
+def test_spa():
+    driver = init_driver()
+    driver.get("http://localhost:8000")
+    assert "OpenWrt Firmware Selector" in driver.title
+
+    model = driver.find_element_by_id("models")
+    model.clear()
+    model.send_keys("a7 v5")
+
+    models = driver.find_element_by_id("models-autocomplete-list")
+    assert "TP-Link Archer A7 v5" in models.text
+
+    message = driver.find_element_by_xpath("/html/body/div/div/p")
+    assert "use the input below to download firmware" in message.text
+
+    lang = Select(driver.find_element_by_id("language-selection"))
+
+    lang.select_by_visible_text("Deutsch")
+    message = driver.find_element_by_xpath("/html/body/div/div/p")
+    assert "benutze die Eingabe um die passende" in message.text
+
+    lang.select_by_value("ca")
+    message = driver.find_element_by_xpath("/html/body/div/div/p")
+    assert "servir el formulari de sota per seleccionar" in message.text
+
+    lang.select_by_visible_text("Polski")
+    message = driver.find_element_by_xpath("/html/body/div/div/p")
+    assert "pola poniżej żeby znaleźć obraz" in message.text