56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
import pathlib
|
|
import unittest
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
|
SERVICE_WORKER = (ROOT / 'sw.js').read_text(encoding='utf-8')
|
|
CRISIS_OFFLINE_PAGE = ROOT / 'crisis-offline.html'
|
|
MAKEFILE = (ROOT / 'Makefile').read_text(encoding='utf-8')
|
|
|
|
|
|
class TestServiceWorkerOffline(unittest.TestCase):
|
|
def test_crisis_offline_page_exists(self):
|
|
self.assertTrue(CRISIS_OFFLINE_PAGE.exists(), 'crisis-offline.html should exist')
|
|
|
|
def test_service_worker_precaches_crisis_offline_page(self):
|
|
self.assertIn('/crisis-offline.html', SERVICE_WORKER)
|
|
|
|
def test_service_worker_has_navigation_timeout_for_intermittent_connections(self):
|
|
self.assertIn('NAVIGATION_TIMEOUT_MS', SERVICE_WORKER)
|
|
self.assertIn('AbortController', SERVICE_WORKER)
|
|
|
|
def test_service_worker_uses_crisis_offline_fallback_for_navigation(self):
|
|
self.assertIn("event.request.mode === 'navigate'", SERVICE_WORKER)
|
|
self.assertIn("/crisis-offline.html", SERVICE_WORKER)
|
|
|
|
def test_make_push_includes_crisis_offline_page(self):
|
|
self.assertIn('crisis-offline.html', MAKEFILE)
|
|
|
|
|
|
class TestCrisisOfflinePage(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.html = CRISIS_OFFLINE_PAGE.read_text(encoding='utf-8') if CRISIS_OFFLINE_PAGE.exists() else ''
|
|
cls.lower_html = cls.html.lower()
|
|
|
|
def test_has_clickable_988_link(self):
|
|
self.assertIn('href="tel:988"', self.html)
|
|
|
|
def test_has_crisis_text_line(self):
|
|
self.assertIn('Crisis Text Line', self.html)
|
|
self.assertIn('741741', self.html)
|
|
|
|
def test_has_grounding_techniques(self):
|
|
required_phrases = [
|
|
'5 things you can see',
|
|
'4 things you can feel',
|
|
'3 things you can hear',
|
|
'2 things you can smell',
|
|
'1 thing you can taste',
|
|
]
|
|
for phrase in required_phrases:
|
|
self.assertIn(phrase, self.lower_html)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|