75 lines
2.2 KiB
Python
75 lines
2.2 KiB
Python
import pathlib
|
|
import re
|
|
import unittest
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
|
INDEX_HTML = ROOT / 'index.html'
|
|
|
|
|
|
class TestSafetyPlanInlineFeedback(unittest.TestCase):
|
|
"""Test that safety plan uses inline feedback instead of blocking alert()."""
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.html = INDEX_HTML.read_text()
|
|
|
|
def test_no_alert_calls(self):
|
|
"""Safety plan save must not use browser alert()."""
|
|
alert_matches = re.findall(r'alert\(', self.html)
|
|
self.assertEqual(
|
|
len(alert_matches), 0,
|
|
f'Found {len(alert_matches)} alert() calls - must use inline feedback instead.',
|
|
)
|
|
|
|
def test_sp_status_element_exists(self):
|
|
"""Modal footer must contain #sp-status element for inline feedback."""
|
|
self.assertRegex(
|
|
self.html,
|
|
r'id=["\']sp-status["\']',
|
|
'Expected #sp-status element in the safety plan modal.',
|
|
)
|
|
|
|
def test_sp_status_has_aria_live(self):
|
|
"""#sp-status must have aria-live for accessible announcements."""
|
|
self.assertRegex(
|
|
self.html,
|
|
r'aria-live=["\']polite["\']',
|
|
'Expected #sp-status to have aria-live="polite".',
|
|
)
|
|
|
|
def test_success_feedback_exists(self):
|
|
"""Must show success message on save."""
|
|
self.assertIn(
|
|
'Safety plan saved locally.',
|
|
self.html,
|
|
'Expected success message for safety plan save.',
|
|
)
|
|
|
|
def test_error_feedback_exists(self):
|
|
"""Must show error message on save failure."""
|
|
self.assertIn(
|
|
'Error saving plan.',
|
|
self.html,
|
|
'Expected error message for safety plan save failure.',
|
|
)
|
|
|
|
def test_css_success_state(self):
|
|
"""Must have CSS for .sp-status.success state."""
|
|
self.assertIn(
|
|
'sp-status.success',
|
|
self.html,
|
|
'Expected CSS for .sp-status.success state.',
|
|
)
|
|
|
|
def test_css_error_state(self):
|
|
"""Must have CSS for .sp-status.error state."""
|
|
self.assertIn(
|
|
'sp-status.error',
|
|
self.html,
|
|
'Expected CSS for .sp-status.error state.',
|
|
)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|