Compare commits
1 Commits
burn/73-in
...
fix/issue-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8f2b0925f |
65
index.html
65
index.html
@@ -613,31 +613,6 @@ 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>
|
||||
@@ -1054,12 +1029,12 @@ Sovereignty and service always.`;
|
||||
overlayDismissBtn.textContent = 'Continue to chat (' + countdown + 's)';
|
||||
|
||||
// Disable background interaction via inert attribute
|
||||
var mainApp = document.querySelector('.app');
|
||||
var mainApp = document.getElementById('app');
|
||||
if (mainApp) mainApp.setAttribute('inert', '');
|
||||
// Also hide from assistive tech
|
||||
var chatSection = document.getElementById('chat');
|
||||
var chatSection = document.getElementById('chat-area');
|
||||
if (chatSection) chatSection.setAttribute('aria-hidden', 'true');
|
||||
var footerEl = document.querySelector('footer');
|
||||
var footerEl = document.getElementById('footer');
|
||||
if (footerEl) footerEl.setAttribute('aria-hidden', 'true');
|
||||
|
||||
if (overlayTimer) clearInterval(overlayTimer);
|
||||
@@ -1075,7 +1050,10 @@ Sovereignty and service always.`;
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
overlayDismissBtn.focus();
|
||||
var overlayCallLink = crisisOverlay.querySelector('.overlay-call');
|
||||
if (overlayCallLink && typeof overlayCallLink.focus === 'function') {
|
||||
overlayCallLink.focus();
|
||||
}
|
||||
}
|
||||
|
||||
// Register focus trap on document (always listening, gated by class check)
|
||||
@@ -1090,11 +1068,11 @@ Sovereignty and service always.`;
|
||||
}
|
||||
|
||||
// Re-enable background interaction
|
||||
var mainApp = document.querySelector('.app');
|
||||
var mainApp = document.getElementById('app');
|
||||
if (mainApp) mainApp.removeAttribute('inert');
|
||||
var chatSection = document.getElementById('chat');
|
||||
var chatSection = document.getElementById('chat-area');
|
||||
if (chatSection) chatSection.removeAttribute('aria-hidden');
|
||||
var footerEl = document.querySelector('footer');
|
||||
var footerEl = document.getElementById('footer');
|
||||
if (footerEl) footerEl.removeAttribute('aria-hidden');
|
||||
|
||||
// Restore focus to the element that had it before the overlay opened
|
||||
@@ -1230,9 +1208,9 @@ Sovereignty and service always.`;
|
||||
localStorage.setItem('timmy_safety_plan', JSON.stringify(plan));
|
||||
safetyPlanModal.classList.remove('active');
|
||||
_restoreSafetyPlanFocus();
|
||||
showToast('Safety plan saved locally.', 'success');
|
||||
alert('Safety plan saved locally.');
|
||||
} catch (e) {
|
||||
showToast('Error saving plan.', 'error');
|
||||
alert('Error saving plan.');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1477,22 +1455,6 @@ Sovereignty and service always.`;
|
||||
msgInput.focus();
|
||||
}
|
||||
|
||||
// ===== 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);
|
||||
}
|
||||
|
||||
// ===== BOOT =====
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
@@ -1502,8 +1464,5 @@ Sovereignty and service always.`;
|
||||
|
||||
})();
|
||||
</script>
|
||||
|
||||
<div id="toast-notification" class="toast-notification"
|
||||
role="status" aria-live="polite" aria-atomic="true"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
55
tests/test_crisis_overlay_initial_focus.py
Normal file
55
tests/test_crisis_overlay_initial_focus.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import pathlib
|
||||
import re
|
||||
import unittest
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
||||
INDEX_HTML = ROOT / 'index.html'
|
||||
|
||||
|
||||
class TestCrisisOverlayInitialFocus(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.html = INDEX_HTML.read_text()
|
||||
|
||||
def test_overlay_focuses_enabled_call_link_on_open(self):
|
||||
self.assertRegex(
|
||||
self.html,
|
||||
r"overlayCallLink\s*=\s*crisisOverlay\.querySelector\('\.overlay-call'\)",
|
||||
'Expected showOverlay() to capture the enabled 988 call link as the initial focus target.',
|
||||
)
|
||||
self.assertRegex(
|
||||
self.html,
|
||||
r"overlayCallLink\.focus\(\)",
|
||||
'Expected showOverlay() to focus the enabled 988 call link on open.',
|
||||
)
|
||||
self.assertNotRegex(
|
||||
self.html,
|
||||
r"overlayDismissBtn\.focus\(\)",
|
||||
'Initial focus should not target the disabled dismiss button.',
|
||||
)
|
||||
|
||||
def test_overlay_uses_live_dom_targets_for_background_locking(self):
|
||||
self.assertRegex(
|
||||
self.html,
|
||||
r"document\.getElementById\('app'\)",
|
||||
'Expected overlay to inert the live #app container.',
|
||||
)
|
||||
self.assertRegex(
|
||||
self.html,
|
||||
r"document\.getElementById\('chat-area'\)",
|
||||
'Expected overlay to hide the live #chat-area region from assistive tech while active.',
|
||||
)
|
||||
self.assertNotRegex(
|
||||
self.html,
|
||||
r"document\.querySelector\('\.app'\)",
|
||||
'The overlay should not target a nonexistent .app selector.',
|
||||
)
|
||||
self.assertNotRegex(
|
||||
self.html,
|
||||
r"document\.getElementById\('chat'\)",
|
||||
'The overlay should not target a nonexistent #chat region.',
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -1,47 +0,0 @@
|
||||
"""Tests for inline toast notification replacing blocking alert() — issue #73."""
|
||||
import pathlib
|
||||
import unittest
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
||||
INDEX_HTML = ROOT / "index.html"
|
||||
|
||||
|
||||
class TestToastNotification(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.html = INDEX_HTML.read_text(encoding="utf-8")
|
||||
|
||||
def test_no_blocking_alerts_in_safety_plan_save(self):
|
||||
"""Safety plan save handler must not use alert()."""
|
||||
idx = self.html.find("localStorage.setItem('timmy_safety_plan'")
|
||||
self.assertGreater(idx, 0, "Safety plan save handler not found")
|
||||
section = self.html[idx : idx + 300]
|
||||
self.assertNotIn(
|
||||
"alert(",
|
||||
section,
|
||||
"Safety plan save handler still uses blocking alert()",
|
||||
)
|
||||
|
||||
def test_toast_element_exists_in_dom(self):
|
||||
self.assertIn('id="toast-notification"', self.html)
|
||||
|
||||
def test_toast_has_aria_live(self):
|
||||
self.assertIn('aria-live="polite"', self.html)
|
||||
|
||||
def test_showToast_function_defined(self):
|
||||
self.assertIn("function showToast(", self.html)
|
||||
|
||||
def test_toast_css_classes_present(self):
|
||||
for cls in (".toast-notification", ".visible", ".success", ".error"):
|
||||
self.assertIn(cls, self.html, f"Missing CSS class {cls}")
|
||||
|
||||
def test_toast_auto_dismiss_via_timeout(self):
|
||||
idx = self.html.find("function showToast")
|
||||
self.assertGreater(idx, 0, "showToast function not found")
|
||||
self.assertIn("setTimeout", self.html[idx:])
|
||||
|
||||
|
||||
def test_showToast_replaces_alert():
|
||||
html = INDEX_HTML.read_text(encoding="utf-8")
|
||||
assert "showToast('Safety plan saved locally.'" in html
|
||||
assert "showToast('Error saving plan.'" in html
|
||||
Reference in New Issue
Block a user