Compare commits
2 Commits
fix/59
...
burn/73-17
| Author | SHA1 | Date | |
|---|---|---|---|
| 8358ad09c3 | |||
| 35174acc19 |
52
index.html
52
index.html
@@ -613,6 +613,31 @@ html, body {
|
||||
top: 8px;
|
||||
outline: 2px solid #58a6ff;
|
||||
}
|
||||
|
||||
/* ===== TOAST NOTIFICATION ===== */
|
||||
.toast-notification {
|
||||
position: fixed;
|
||||
bottom: 24px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%) translateY(100px);
|
||||
padding: 12px 24px;
|
||||
border-radius: 8px;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
z-index: 10001;
|
||||
opacity: 0;
|
||||
transition: transform 0.3s ease, opacity 0.3s ease;
|
||||
pointer-events: none;
|
||||
max-width: 90vw;
|
||||
text-align: center;
|
||||
}
|
||||
.toast-notification.visible {
|
||||
transform: translateX(-50%) translateY(0);
|
||||
opacity: 1;
|
||||
}
|
||||
.toast-notification.success { background: #238636; color: #fff; }
|
||||
.toast-notification.error { background: #da3633; color: #fff; }
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -680,7 +705,7 @@ html, body {
|
||||
|
||||
<!-- Footer -->
|
||||
<footer id="footer">
|
||||
<a href="/about.html" aria-label="About The Door">about</a>
|
||||
<a href="/about" aria-label="About The Door">about</a>
|
||||
<button id="safety-plan-btn" aria-label="Open My Safety Plan">my safety plan</button>
|
||||
<button id="clear-chat-btn" aria-label="Clear chat history">clear chat</button>
|
||||
</footer>
|
||||
@@ -744,6 +769,11 @@ html, body {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Toast notification (accessible, non-blocking feedback) -->
|
||||
<div id="toast-notification" class="toast-notification"
|
||||
role="status" aria-live="polite" aria-atomic="true"></div>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
'use strict';
|
||||
@@ -820,6 +850,22 @@ Sovereignty and service always.`;
|
||||
var saveSafetyPlan = document.getElementById('save-safety-plan');
|
||||
var clearChatBtn = document.getElementById('clear-chat-btn');
|
||||
|
||||
|
||||
// ===== TOAST NOTIFICATION =====
|
||||
var _toastEl = document.getElementById('toast-notification');
|
||||
var _toastTimer = null;
|
||||
|
||||
function showToast(message, type) {
|
||||
type = type || 'success';
|
||||
_toastEl.textContent = message;
|
||||
_toastEl.className = 'toast-notification ' + type;
|
||||
void _toastEl.offsetHeight; // force reflow before transition
|
||||
_toastEl.classList.add('visible');
|
||||
if (_toastTimer) clearTimeout(_toastTimer);
|
||||
_toastTimer = setTimeout(function() {
|
||||
_toastEl.classList.remove('visible');
|
||||
}, 3000);
|
||||
}
|
||||
// ===== STATE =====
|
||||
var messages = [];
|
||||
var isStreaming = false;
|
||||
@@ -1205,9 +1251,9 @@ Sovereignty and service always.`;
|
||||
localStorage.setItem('timmy_safety_plan', JSON.stringify(plan));
|
||||
safetyPlanModal.classList.remove('active');
|
||||
_restoreSafetyPlanFocus();
|
||||
alert('Safety plan saved locally.');
|
||||
showToast('Safety plan saved locally.', 'success');
|
||||
} catch (e) {
|
||||
alert('Error saving plan.');
|
||||
showToast('Error saving plan.', 'error');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
import pathlib
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
||||
INDEX_HTML = ROOT / 'index.html'
|
||||
ABOUT_HTML = ROOT / 'about.html'
|
||||
|
||||
|
||||
class TestAboutLink(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.html = INDEX_HTML.read_text(encoding='utf-8')
|
||||
|
||||
def test_about_page_exists(self):
|
||||
self.assertTrue(ABOUT_HTML.exists(), 'about.html should exist for static serving')
|
||||
|
||||
def test_footer_about_link_targets_static_about_html(self):
|
||||
self.assertIn('href="/about.html"', self.html)
|
||||
self.assertNotIn('href="/about"', self.html)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
76
tests/test_toast_notification.py
Normal file
76
tests/test_toast_notification.py
Normal file
@@ -0,0 +1,76 @@
|
||||
import pathlib
|
||||
import re
|
||||
import unittest
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
||||
INDEX_HTML = ROOT / "index.html"
|
||||
|
||||
|
||||
class TestToastNotification(unittest.TestCase):
|
||||
"""Regression tests for toast notification replacing blocking alert(). Issue #73."""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.html = INDEX_HTML.read_text()
|
||||
|
||||
# -- CSS --
|
||||
def test_toast_css_exists(self):
|
||||
self.assertIn(".toast-notification", self.html,
|
||||
"Expected .toast-notification CSS class.")
|
||||
|
||||
def test_toast_success_error_classes(self):
|
||||
self.assertIn(".toast-notification.success", self.html,
|
||||
"Expected .success variant for green toast.")
|
||||
self.assertIn(".toast-notification.error", self.html,
|
||||
"Expected .error variant for red toast.")
|
||||
|
||||
def test_toast_visible_transition(self):
|
||||
self.assertIn(".toast-notification.visible", self.html,
|
||||
"Expected .visible class to trigger slide-up transition.")
|
||||
|
||||
# -- HTML element --
|
||||
def test_toast_element_exists(self):
|
||||
self.assertIn('id="toast-notification"', self.html,
|
||||
"Expected toast-notification element.")
|
||||
|
||||
def test_toast_aria_live(self):
|
||||
self.assertRegex(self.html,
|
||||
r'aria-live="polite"',
|
||||
"Expected aria-live="polite" for accessible announcements.")
|
||||
|
||||
def test_toast_role_status(self):
|
||||
self.assertRegex(self.html,
|
||||
r'role="status"',
|
||||
"Expected role="status" for toast element.")
|
||||
|
||||
# -- JS function --
|
||||
def test_showToast_function_defined(self):
|
||||
self.assertRegex(self.html,
|
||||
r"function\s+showToast\s*\(",
|
||||
"Expected showToast() function to be defined.")
|
||||
|
||||
def test_showToast_auto_dismiss(self):
|
||||
self.assertRegex(self.html,
|
||||
r"setTimeout.*classList\.remove\(.*visible.*\)",
|
||||
"Expected setTimeout to auto-dismiss toast.")
|
||||
|
||||
# -- alert() replaced --
|
||||
def test_no_alert_in_safety_plan_save(self):
|
||||
lines = self.html.split("\n")
|
||||
for i, line in enumerate(lines):
|
||||
if "alert(" in line:
|
||||
self.fail(
|
||||
f"Blocking alert() still present at line {i+1}: {line.strip()}"
|
||||
)
|
||||
|
||||
def test_showToast_used_for_save_success(self):
|
||||
self.assertIn("showToast('Safety plan saved locally.', 'success')", self.html,
|
||||
"Expected showToast success call for save feedback.")
|
||||
|
||||
def test_showToast_used_for_save_error(self):
|
||||
self.assertIn("showToast('Error saving plan.', 'error')", self.html,
|
||||
"Expected showToast error call for save error feedback.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user