From b1763135aa26c309d6b4934c9a9785fe9e494023 Mon Sep 17 00:00:00 2001 From: Kantine Wrapper Date: Tue, 24 Feb 2026 20:50:19 +0100 Subject: [PATCH] test(ui): massively expand DOM testing suite to cover all Modals and Actions (v1.4.18) --- changelog.md | 3 ++ tests/test_dom.js | 93 +++++++++++++++++++++++++++++++++++++++++++++-- version.txt | 2 +- 3 files changed, 93 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index 937741d..93d1bf1 100755 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,6 @@ +## v1.4.18 +- 🧪 **Testing**: Die automatische DOM-Testing Suite (`test_dom.js`) wurde massiv ausgebaut. Sie prüft nun neben der Alarmglocke und den Highlights auch systematisch alle anderen UI-Komponenten (Login-Modal, History-Modal, Versionen-Modal, Theme-Toggle, und Navigation Tabs) auf korrekte Event-Listener-Bindungen, um Regressionen (tote Buttons) endgültig auszuschließen. + ## v1.4.17 - 🐛 **Bugfix**: Regression behoben: Der "Persönliche Highlights" (Stern-Button) Dialog öffnet sich nun wieder korrekt. - 🧪 **Testing**: Es wurde ein initialer UI-Testing-Hook (`test_dom.js` mit `jsdom`) in die Build-Pipeline integriert, um kritische DOM Event-Listener Regressionen (wie den Highlights-Button und die Alarmglocke) automatisch zu preventen. diff --git a/tests/test_dom.js b/tests/test_dom.js index 30502e9..bc870ab 100755 --- a/tests/test_dom.js +++ b/tests/test_dom.js @@ -29,6 +29,43 @@ const html = ` + + + + + + + + + + + v1.4.17 + + + + + + + + + + + +
Header
+ `; @@ -37,7 +74,8 @@ log("Reading file jsCode..."); const jsCode = fs.readFileSync('kantine.js', 'utf8') .replace('(function () {', '') .replace('})();', '') - .replace('if (window.__KANTINE_LOADED) return;', ''); + .replace('if (window.__KANTINE_LOADED) return;', '') + .replace('window.location.reload();', 'window.__RELOAD_CALLED = true;'); log("Instantiating JSDOM..."); const dom = new JSDOM(html, { runScripts: "dangerously", url: "http://localhost/" }); @@ -74,9 +112,6 @@ const testCode = ` const hlModal = document.getElementById('highlights-modal'); if (!hlModal.classList.contains('hidden')) throw new Error("Highlights modal should be hidden initially"); - // Call bindEvents manually to attach the listeners since the IIFE is stripped - bindEvents(); - // Click to open document.getElementById('btn-highlights').click(); if (hlModal.classList.contains('hidden')) throw new Error("Highlights modal did not open upon clicking btn-highlights!"); @@ -87,6 +122,56 @@ const testCode = ` console.log("✅ Highlights Modal Test Passed"); + console.log("--- Testing Login Modal ---"); + const loginModal = document.getElementById('login-modal'); + document.getElementById('btn-login-open').click(); + if (loginModal.classList.contains('hidden')) throw new Error("Login modal should open"); + document.getElementById('btn-login-close').click(); + if (!loginModal.classList.contains('hidden')) throw new Error("Login modal should close"); + console.log("✅ Login Modal Test Passed"); + + console.log("--- Testing History Modal ---"); + // We need authToken to be truthy to open history modal + authToken = "fake_token"; + const historyModal = document.getElementById('history-modal'); + document.getElementById('btn-history').click(); + if (historyModal.classList.contains('hidden')) throw new Error("History modal should open"); + document.getElementById('btn-history-close').click(); + if (!historyModal.classList.contains('hidden')) throw new Error("History modal should close"); + console.log("✅ History Modal Test Passed"); + + console.log("--- Testing Version Modal ---"); + const versionModal = document.getElementById('version-modal'); + document.querySelector('.version-tag').click(); + if (versionModal.classList.contains('hidden')) throw new Error("Version modal should open"); + document.getElementById('btn-version-close').click(); + if (!versionModal.classList.contains('hidden')) throw new Error("Version modal should close"); + console.log("✅ Version Modal Test Passed"); + + console.log("--- Testing Theme Toggle ---"); + const themeBtn = document.getElementById('theme-toggle'); + const initialTheme = document.documentElement.getAttribute('data-theme'); + themeBtn.click(); + const newTheme = document.documentElement.getAttribute('data-theme'); + if (initialTheme === newTheme) throw new Error("Theme did not toggle"); + console.log("✅ Theme Toggle Test Passed"); + + console.log("--- Testing Navigation Tabs ---"); + const btnThis = document.getElementById('btn-this-week'); + const btnNext = document.getElementById('btn-next-week'); + btnNext.click(); + if (!btnNext.classList.contains('active') || btnThis.classList.contains('active')) throw new Error("Next week tab not active"); + btnThis.click(); + if (!btnThis.classList.contains('active') || btnNext.classList.contains('active')) throw new Error("This week tab not active"); + console.log("✅ Navigation Tabs Test Passed"); + + console.log("--- Testing Clear Cache Button ---"); + // Mock confirm directly inside evaluated JSDOM context + window.confirm = () => true; + document.getElementById('btn-clear-cache').click(); + if (!window.__RELOAD_CALLED) throw new Error("Clear cache did not reload the page"); + console.log("✅ Clear Cache Button Test Passed"); + window.__TEST_PASSED = true; `; diff --git a/version.txt b/version.txt index 4c98421..d736151 100755 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v1.4.17 +v1.4.18