- New pages built from the records: lists by length, time to walk, month, kind of walking and holder; place-by-list pages; a Triple Crown table and key-figure tables for the National Scenic and Recreation Trails; highest points, most climbing and climb per mile; a page for every route author, with the authors of three or more routes leading the authors page; connected trails; recently added and changed; a glossary and a method page. Every place page opens with a summary. - Trail pages open with an "In brief" paragraph generated from the record and show when the record was last checked. The About page says who maintains the site and how to reach them. - The map starts when it is reached, not with the page. The site's own CSS, scripts and fonts are fingerprinted and cached for a year. Every image has its dimensions. - Titles are held to 60 characters and share previews get their own shorter description. - Social cards are redrawn so a long name can no longer push text into the footer, and the site-wide card takes its wording from the site settings instead of an old hand-made image. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
57 lines
2.7 KiB
Python
57 lines
2.7 KiB
Python
"""The maps start late: nothing for a map (MapLibre, its style, the contour add-on, the track
|
|
data) loads with the page. These pin the script's promises (the script has no unit tests; the
|
|
behaviour was checked by driving the pages in a browser)."""
|
|
import os
|
|
import re
|
|
import unittest
|
|
|
|
WEB = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
|
def read(*parts):
|
|
with open(os.path.join(WEB, *parts), encoding="utf-8") as f:
|
|
return f.read()
|
|
|
|
|
|
class MapStartTest(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.js = read("assets", "app.js")
|
|
|
|
def test_one_function_starts_a_map_and_it_is_the_only_caller_of_the_fetch_and_the_loader(self):
|
|
self.assertEqual(self.js.count("fetchData()"), 2) # its definition and the one call
|
|
self.assertEqual(self.js.count("loadLibraries()"), 2)
|
|
begin = re.search(r"function begin\(\) \{(.*?)\n \}\n", self.js, re.S)
|
|
self.assertIsNotNone(begin)
|
|
self.assertIn("dataReady = fetchData();", begin.group(1))
|
|
self.assertIn("loadLibraries().then(startMapLibre);", begin.group(1))
|
|
self.assertIn("if (outdoorUrl) fetchOutdoor(outdoorUrl);", begin.group(1))
|
|
self.assertEqual(self.js.count("fetchOutdoor(outdoorUrl)"), 2) # begin() and startMapLibre(), once started
|
|
|
|
def test_a_map_starts_when_near_the_screen_or_touched_never_at_once(self):
|
|
self.assertIn("new IntersectionObserver(", self.js)
|
|
self.assertIn("afterLoad(begin);", self.js) # near the screen, and the page has loaded
|
|
for event in ("pointerdown", "focusin", "keydown"):
|
|
self.assertIn(f"'{event}'", self.js)
|
|
self.assertNotIn("startMaps", self.js)
|
|
self.assertNotRegex(self.js, r"initMap\(fig\)[^}]*\n\s*(fetch|loadLibraries)")
|
|
|
|
def test_the_libraries_come_from_the_addresses_on_the_scripts_own_tag(self):
|
|
self.assertIn("var SCRIPT = document.currentScript;", self.js)
|
|
for attr in ("maplibreCss", "maplibreJs", "contourJs"):
|
|
self.assertIn(f"d.{attr}", self.js)
|
|
|
|
def test_maplibres_stylesheet_goes_before_the_sites_so_the_sites_frame_rules_win(self):
|
|
# MapLibre's .maplibregl-map sets position: relative; the site's .map__canvas needs absolute.
|
|
self.assertIn("document.head.querySelector('link[rel=\"stylesheet\"]')", self.js)
|
|
self.assertIn("document.head.insertBefore(el, before || null);", self.js)
|
|
# the page runs the scripts in order: the add-on needs MapLibre first
|
|
self.assertIn("script.async = false;", self.js)
|
|
|
|
def test_until_it_starts_the_frame_says_what_happens_and_the_page_text_stays_for_no_script(self):
|
|
self.assertIn("'The map loads when you scroll to it.'", self.js)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|