Give every page of trails one layout, with the map beside the rows, and set no tables
Every page that shows a set of trails (home, places, lists, Routes, authors, Triple Crown, rankings, newest) has the same layout: the trails as rows with their map beside them from 900 px wide up, and a short map band above the rows when narrower. The home page gets its headline back on the contour ground, with the ten lists as one line of links. A trail page has its actions in its head and the map in a fixed frame beside At a glance. No page sets a table: every set of trails is the standard trail row, and other sets are rows in the same language. Route authors' names link to their pages from route rows and trail pages, the Routes page says how many routes by how many authors, and the Lists index has a Route authors entry. No trail's facts changed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
59f912c47c
commit
298f1b9fd9
28 files changed
+843
-541
No files matched your search
+40
-6
@@ -68,6 +68,40 @@ class ExtraPagesTest(unittest.TestCase):
|
||||
self.assertIn(f'href="/trails/{r["id"]}/"', page, r["id"])
|
||||
self.assertIn(r["route"]["creator"], text, r["id"])
|
||||
|
||||
def test_ways_into_the_authors_pages_are_routes(self):
|
||||
"""A route's row names its author as a link to their page (each named person who has one);
|
||||
the Routes page head counts routes and authors and links /authors/; /lists/ lists Route
|
||||
authors beside Routes; the trail page links the author where it names them."""
|
||||
import html as _html
|
||||
from olt import authors
|
||||
routes = [r for r in self.records if r["derived"]["kind"] == "route"]
|
||||
gs = authors.author_pages(self.records, ROOT)
|
||||
links = authors.link_map(self.records, ROOT)
|
||||
row = re.compile(r'<p class="entry__by">(.*?)</p>')
|
||||
home = read_out("index.html")
|
||||
by_line = {m for m in row.findall(home)}
|
||||
for r in routes:
|
||||
for name, href in links.get(r["route"]["creator"], []):
|
||||
self.assertIn(f'<a href="{href}">{_html.escape(name)}</a>', "".join(by_line), r["id"])
|
||||
# a credit with two people links each; a credit with no page stays plain
|
||||
self.assertTrue(any(len(v) > 1 for v in links.values()))
|
||||
self.assertEqual(len(gs), len({n for v in links.values() for n, _ in v}))
|
||||
# Routes page head
|
||||
page = read_out("routes/index.html")
|
||||
head = page[:page.index('<div class="container section place">')]
|
||||
self.assertIn(f'<p class="page-head__lede">{len(routes)} routes by <a href="/authors/">{len(gs)} authors</a></p>', head)
|
||||
# Lists index: in the group Routes is in
|
||||
lists = read_out("lists/index.html")
|
||||
group = lists[lists.index('id="group-standing"'):]
|
||||
group = group[:group.index("</section>")]
|
||||
self.assertIn('<a href="/routes/">Routes</a>', group)
|
||||
self.assertIn('<a href="/authors/">Route authors</a>', group)
|
||||
# the trail page links the author's name in its head and its Author fact
|
||||
for r in routes:
|
||||
for name, href in links.get(r["route"]["creator"], []):
|
||||
trail_page = read_out(f"trails/{r['id']}/index.html")
|
||||
self.assertGreaterEqual(trail_page.count(f'<a href="{href}">'), 2, r["id"])
|
||||
|
||||
def test_every_logo_on_logos_page(self):
|
||||
page = read_out("logos/index.html")
|
||||
for r in self.records:
|
||||
@@ -185,9 +219,9 @@ class ExtraPagesTest(unittest.TestCase):
|
||||
# no dataset filters
|
||||
for name in ("tier", "policy", "designated", "line", "country", "region"):
|
||||
self.assertNotIn(f'name="{name}"', form, name)
|
||||
# the map is in the tool, beside the list it filters (after it in the page, beside it on a wide screen)
|
||||
main = doc[doc.index('<div class="home__results">'):]
|
||||
self.assertLess(main.index('<ol class="entries" id="entries"'), main.index('data-map="overview"'))
|
||||
# the map is in the tool, beside the list it filters (above it in the page, beside it on a wide screen)
|
||||
main = doc[doc.index('<div class="browse">'):]
|
||||
self.assertLess(main.index('data-map="overview"'), main.index('<ol class="entries" id="entries"'))
|
||||
longest_km = max(r["length_km"] for r in self.records)
|
||||
maxsel = form[form.index('id="max"'):form.index("</select>", form.index('id="max"'))]
|
||||
minsel = form[form.index('id="min"'):form.index("</select>", form.index('id="min"'))]
|
||||
@@ -221,9 +255,9 @@ class ExtraPagesTest(unittest.TestCase):
|
||||
self.assertIn(f"<dt>Track measured</dt><dd>{measured}<", page)
|
||||
self.assertIn("<dt>Source status: OpenStreetMap only</dt>", page)
|
||||
# a record's "none (no line included)" is shown in words, not as the raw value
|
||||
self.assertIn("<td>None (no track included)</td>", page)
|
||||
self.assertIn('<p class="entry__name">None (no track included)</p>', page)
|
||||
self.assertNotIn("none (no line included)", page)
|
||||
self.assertEqual(page.count('<th scope="col">Trails</th>'), 2)
|
||||
self.assertNotIn("<table", page)
|
||||
self.assertNotRegex(page, r'<td><a href="/trails/[^"]+/">[^<]*</a>, <a')
|
||||
|
||||
def test_data_page_licences_from_the_records(self):
|
||||
@@ -240,7 +274,7 @@ class ExtraPagesTest(unittest.TestCase):
|
||||
self.assertRegex(page, rf'<a href="/data/{re.escape(name)}">')
|
||||
for name in ("all-gpx.zip", "all-geojson.zip"):
|
||||
size = words.fmt_bytes(os.path.getsize(os.path.join(OUT, "data", name)))
|
||||
self.assertRegex(page, rf'/data/{re.escape(name)}</a></td><td>[^<]*</td><td class="num">{re.escape(size)}<')
|
||||
self.assertRegex(page, rf'/data/{re.escape(name)}</a></p>.*?<span class="entry__label">Size</span> {re.escape(size)}<')
|
||||
self.assertIn(f'"contentUrl":"{site.load().base_url}/data/{name}"', page)
|
||||
|
||||
def test_archives_hold_every_line(self):
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""The first screen: what the top of the trail page and the home page hold, the home page's lists
|
||||
(read from data), the header's Lists item, the tables that stack on a phone, and the maps' static
|
||||
drawings (olt/sketch.py) with the script's handover from them.
|
||||
(read from data), the header's Lists item, the shared layout of every page that shows a set of
|
||||
trails, the rows that take the place of tables, and the maps' static drawings (olt/sketch.py) with
|
||||
the script's handover from them.
|
||||
|
||||
Pages are rendered one at a time; the site is not built. The sketch reads the track files of a
|
||||
site directory, so those are written to a temporary one here. The behaviour of the script in a
|
||||
@@ -56,15 +57,23 @@ class HomePageTest(unittest.TestCase):
|
||||
self.assertEqual(keys, ["national-scenic-trails", "routes", "high-routes", "loops", "under-100-miles",
|
||||
"a-week-or-less", "one-to-two-weeks", "a-month-or-more", "with-gpx", "canada"])
|
||||
row = home.lists_row(self.recs, keys)
|
||||
titles = re.findall(r'<li><a href="[^"]+">(.*?) <span class="chips__n">', row)
|
||||
titles = re.findall(r'<li><a href="[^"]+">(.*?)<span class="lists-row__n">', row)
|
||||
self.assertEqual(titles, [browse.by_key(k).title for k in keys])
|
||||
self.assertTrue(row.rstrip().endswith("</nav>"))
|
||||
self.assertIn('<a href="/lists/">All lists</a>', row)
|
||||
self.assertIn('<li class="lists-row__all"><a href="/lists/">All lists</a></li></ul>', row)
|
||||
self.assertNotIn("Hiking in", row)
|
||||
self.assertNotIn("chips", row) # one quiet line of links, not pills
|
||||
# a different file gives a different row: the set is not a constant of the generator
|
||||
other = home.home_picks([{"key": "loops", "home": 2}, {"key": "routes", "home": 1}, {"key": "canada"}])
|
||||
self.assertEqual(other, ["routes", "loops"])
|
||||
self.assertEqual(re.findall(r'<li><a href="[^"]+">(.*?) <span', home.lists_row(self.recs, other)), ["Routes", "Loops"])
|
||||
self.assertEqual(re.findall(r'<li><a href="[^"]+">(.*?)<span', home.lists_row(self.recs, other)), ["Routes", "Loops"])
|
||||
|
||||
def test_the_introduction_is_the_headline_its_sentence_and_the_lists(self):
|
||||
intro = self.body[:self.body.index('class="container home"')]
|
||||
self.assertIn('<section class="intro"', intro)
|
||||
h1, lede, lists = intro.index("<h1"), intro.index('class="intro__lede"'), intro.index('class="lists-row"')
|
||||
self.assertLess(h1, lede)
|
||||
self.assertLess(lede, lists)
|
||||
|
||||
def test_search_and_filters_are_one_bar_with_a_clear_control_that_starts_hidden(self):
|
||||
bar = self.body[self.body.index('class="filters__bar"'):self.body.index('id="filters-panels"')]
|
||||
@@ -75,15 +84,19 @@ class HomePageTest(unittest.TestCase):
|
||||
self.assertIn('class="filters__panel"', self.body)
|
||||
self.assertIn('class="filters__more"', self.body)
|
||||
|
||||
def test_the_results_precede_the_map_in_the_page_and_the_map_has_its_own_address(self):
|
||||
self.assertLess(self.body.index('class="home__results"'), self.body.index('class="home__map"'))
|
||||
self.assertIn('id="map"', self.body)
|
||||
def test_the_trails_and_the_map_are_the_shared_browsing_layout_with_the_search_bar_over_the_rows(self):
|
||||
grid = self.body[self.body.index('<div class="browse">'):]
|
||||
self.assertLess(grid.index('class="browse__map" id="map"'), grid.index('class="browse__list"'))
|
||||
self.assertLess(grid.index('class="browse__list"'), grid.index('id="finder-form"'))
|
||||
self.assertLess(grid.index('id="finder-form"'), grid.index('id="entries"'))
|
||||
self.assertNotIn("filters__maplink", self.body)
|
||||
|
||||
def test_the_stylesheet_puts_the_map_beside_the_list_on_a_wide_screen(self):
|
||||
def test_the_open_filters_lie_over_the_rows_and_can_be_closed(self):
|
||||
css = read(WEB, "assets", "style.css")
|
||||
self.assertRegex(css, r"\.home \{[^}]*grid-template-areas: \"lists\" \"bar\" \"results\" \"map\" \"notes\"")
|
||||
self.assertIn('grid-template-areas: "lists lists" "bar map" "results map" "notes ."', css)
|
||||
self.assertRegex(css, r"\.lists-row \.chips \{[^}]*flex-wrap: nowrap; overflow-x: auto")
|
||||
self.assertRegex(css, r"html\.js \.filters__panels \{[^}]*position: absolute;")
|
||||
self.assertIn('class="button filters__done"', self.body)
|
||||
js = read(WEB, "assets", "app.js")
|
||||
self.assertIn("e.key === 'Escape'", js)
|
||||
|
||||
|
||||
class ListEntriesCheckTest(unittest.TestCase):
|
||||
@@ -150,36 +163,57 @@ class HeaderTest(unittest.TestCase):
|
||||
self.assertIn("layout.UNDER_LISTS.add(path)", read(WEB, "olt", "pages.py"))
|
||||
|
||||
|
||||
class TablesTest(unittest.TestCase):
|
||||
def test_every_cell_carries_its_label_and_a_wide_table_is_set_by_row(self):
|
||||
t = str(pagekit.table(["Trail", "Length", "States", "Time"], [["A", "1", "X", "2"]], caption="c"))
|
||||
self.assertIn('<table data-stack="rows">', t)
|
||||
self.assertEqual(re.findall(r'data-label="([^"]+)"', t), ["Trail", "Length", "States", "Time"])
|
||||
small = str(pagekit.table(["A", "B", "C"], [["1", "2", "3"]]))
|
||||
self.assertNotIn("data-stack", small)
|
||||
class NoTablesTest(unittest.TestCase):
|
||||
"""The site sets no tables. A set of trails is the site's trail rows; a set of other things is
|
||||
rows in the same language (pagekit.rows_list); a table written in Markdown is set the same way."""
|
||||
|
||||
def test_a_compare_table_labels_each_cell_with_its_row_and_stacks_by_column(self):
|
||||
t = str(pagekit.table(["Figure", "AT", "PCT"], [["Length", "2,198", "2,650"], ["States", "14", "3"]],
|
||||
row_heads=True, compare=True))
|
||||
self.assertIn('<table data-stack="columns">', t)
|
||||
self.assertEqual(re.findall(r'<td data-label="([^"]+)"', t), ["Length", "Length", "States", "States"])
|
||||
def test_a_set_of_things_is_rows_with_a_name_a_sentence_and_a_line_of_facts(self):
|
||||
t = str(pagekit.table(["File", "What it holds", "Size"],
|
||||
[["a.json", "Every trail with all its fields, written out for the programs that read it", "3 MB"]],
|
||||
caption="c"))
|
||||
self.assertNotIn("<table", t)
|
||||
self.assertIn('<ol class="entries entries--plain" aria-label="c">', t)
|
||||
self.assertLess(t.index('class="entry__name">a.json'), t.index('class="entry__desc">Every trail'))
|
||||
self.assertIn('<p class="entry__meta"><span><span class="entry__label">Size</span> 3 MB</span></p>', t)
|
||||
|
||||
def test_the_triple_crown_table_is_a_compare_table_with_equal_columns(self):
|
||||
def test_a_table_written_in_markdown_or_by_hand_is_set_as_rows(self):
|
||||
html = ('<p>x</p><div class="table-wrap"><table><thead><tr><th scope="col">Tier</th><th>Records</th></tr></thead>'
|
||||
'<tbody><tr><td>Measured</td><td>12</td></tr><tr><td>Stated</td><td>3</td></tr></tbody></table></div><p>y</p>')
|
||||
out = pagekit.untable(html)
|
||||
self.assertNotIn("<table", out)
|
||||
self.assertNotIn("table-wrap", out)
|
||||
self.assertEqual(re.findall(r'class="entry__name">(\w+)<', out), ["Measured", "Stated"])
|
||||
self.assertTrue(out.startswith("<p>x</p>") and out.endswith("<p>y</p>"))
|
||||
|
||||
def test_the_triple_crown_is_three_trail_rows_with_their_map_and_the_compared_figures_in_each_row(self):
|
||||
from olt import standing
|
||||
recs = records.load_records(ROOT)
|
||||
c = datafiles.collections(ROOT)[0]
|
||||
title, desc, body, _ = standing.collection_page(c, recs, SITE)
|
||||
self.assertIn('data-stack="columns"', str(body))
|
||||
css = read(WEB, "assets", "style.css")
|
||||
self.assertIn('table[data-stack="columns"] { table-layout: fixed;', css)
|
||||
self.assertIn('th:first-child { inline-size: 9rem; }', css)
|
||||
self.assertIn("order: 3", css) # one block per trail on a phone, from the same cells
|
||||
self.assertNotIn("min-inline-size: 34rem !important", css)
|
||||
title, desc, body, members = standing.collection_page(c, recs, SITE)
|
||||
body = str(body)
|
||||
self.assertNotIn("<table", body)
|
||||
self.assertEqual(body.count('<li class="entry"'), len(members))
|
||||
self.assertIn('class="browse__map"', body)
|
||||
self.assertIn("<dt>High point</dt>", body)
|
||||
self.assertIn("<dt>Designated</dt>", body)
|
||||
|
||||
def test_the_left_out_tables_stack_on_a_phone_too(self):
|
||||
def test_a_ranking_is_the_trail_rows_in_rank_order_led_by_the_rank_and_the_figure(self):
|
||||
from olt import standing
|
||||
recs = records.load_records(ROOT)
|
||||
title, desc, body, have = standing.ranking_page(standing.RANKINGS[0], recs, SITE)
|
||||
body = str(body)
|
||||
self.assertNotIn("<table", body)
|
||||
ranks = [int(n) for n in re.findall(r'data-rank="(\d+)"', body)]
|
||||
self.assertEqual(ranks, list(range(1, len(have) + 1)))
|
||||
first = body[body.index('data-rank="1"'):]
|
||||
self.assertLess(first.index('class="entry__lead"'), first.index('class="entry__length"'))
|
||||
self.assertIn('<span class="entry__rank">No. 1</span>', first)
|
||||
self.assertIn('<option value="rank" selected>', body)
|
||||
|
||||
def test_the_left_out_entries_are_rows_in_the_trail_row_language(self):
|
||||
src = read(WEB, "olt", "leftout.py")
|
||||
self.assertIn('<table data-stack="rows">', src)
|
||||
self.assertEqual(src.count("data-label="), 6)
|
||||
self.assertNotIn("<table", src)
|
||||
self.assertIn("pagekit.plain_entry(", src)
|
||||
|
||||
|
||||
class SketchTest(unittest.TestCase):
|
||||
@@ -276,12 +310,27 @@ class HandoverTest(unittest.TestCase):
|
||||
|
||||
|
||||
class PageTopsTest(unittest.TestCase):
|
||||
def test_a_place_or_list_page_puts_its_list_before_the_text_and_the_map_in_the_narrow_order(self):
|
||||
grid = home.place_grid("TEXT", "LIST", "MAP")
|
||||
self.assertLess(grid.index("TEXT"), grid.index("LIST")) # the text is first in the page
|
||||
def test_a_browsing_page_is_the_map_and_the_rows_then_the_text_about_the_set(self):
|
||||
grid = str(home.browse_view("LIST", '<figure class="mapfig">MAP</figure>', about="<p>TEXT</p>", about_title="About X"))
|
||||
self.assertLess(grid.index("MAP"), grid.index("LIST")) # the map is a band above the rows when narrow
|
||||
self.assertLess(grid.index("LIST"), grid.index("TEXT")) # the text about the set follows the rows
|
||||
self.assertIn('<h2 id="about-these">About X</h2>', grid)
|
||||
css = read(WEB, "assets", "style.css")
|
||||
self.assertIn('grid-template-areas: "list" "map" "text";', css)
|
||||
self.assertIn('grid-template-areas: "list text" "list map";', css)
|
||||
self.assertIn('grid-template-areas: "list map";', css)
|
||||
self.assertRegex(css, r"\.browse__map \{ grid-area: map; position: sticky;")
|
||||
|
||||
def test_a_set_too_small_to_map_is_the_rows_with_the_note_under_them(self):
|
||||
grid = str(home.browse_view("LIST", '<p class="note">NOTE</p>'))
|
||||
self.assertIn('class="browse browse--no-map"', grid)
|
||||
self.assertLess(grid.index("LIST"), grid.index("NOTE"))
|
||||
|
||||
def test_a_place_page_has_its_rows_before_its_summary(self):
|
||||
from olt import regions
|
||||
recs = records.load_records(ROOT)
|
||||
_, _, body, _ = regions.region_page("us-co", recs, SITE)
|
||||
body = str(body)
|
||||
self.assertLess(body.index('class="browse__list"'), body.index('class="browse-about"'))
|
||||
self.assertNotIn("percent", body)
|
||||
|
||||
def test_every_page_head_is_compact(self):
|
||||
css = read(WEB, "assets", "style.css")
|
||||
|
||||
@@ -183,13 +183,13 @@ class TrailPageTest(unittest.TestCase):
|
||||
def test_credit_licence_and_partial_warning_stay_in_view(self):
|
||||
rec = with_line(sample_record("X Trail"))
|
||||
top = top_part(render(rec))
|
||||
# the credit and licence beside the downloads, and on the map's caption
|
||||
# the credit and licence beside the downloads, and the map's credit under them
|
||||
panel = top[top.index('id="download"'):]
|
||||
self.assertIn('id="credit-text">Example Trail Association (CC BY 4.0)<', panel)
|
||||
self.assertIn('Licence: <a href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a>', panel)
|
||||
self.assertLess(panel.index('<ul class="downloads">'), panel.index('class="credit"'))
|
||||
caption = top[top.index('<figcaption class="mapfig__caption">'):]
|
||||
self.assertIn("Credit: Example Trail Association (CC BY 4.0).", caption)
|
||||
credit = top[top.index('<section class="map-credit"'):]
|
||||
self.assertIn("Track credit: Example Trail Association (CC BY 4.0).", credit)
|
||||
# the partial warning above the buttons, and in the glance
|
||||
self.assertLess(panel.index("notice--partial"), panel.index('<ul class="downloads">'))
|
||||
self.assertIn("Partial GPX to download here", top)
|
||||
|
||||
@@ -44,7 +44,7 @@ def unfinished():
|
||||
|
||||
def glance_length(rec):
|
||||
body = top_part(render(rec))
|
||||
start = body.index('<dt>Length</dt>')
|
||||
start = body.index('<dt>Length</dt>', body.index('id="glance-title"'))
|
||||
return body[start:body.index("</div>", start)]
|
||||
|
||||
|
||||
@@ -55,6 +55,10 @@ class GlanceTest(unittest.TestCase):
|
||||
self.assertIn(f"Whole system: 1,584 mi 2,549 km, counting {NOTE}", text(row))
|
||||
self.assertLess(row.index("len--stack"), row.index("Whole system"))
|
||||
self.assertIn("<small>", row)
|
||||
# a line of its own across the whole panel
|
||||
self.assertIn('<span class="glance__aside">Whole system', row)
|
||||
body = top_part(render(florida()))
|
||||
self.assertIn('<div class="glance__wide glance__length"><dt>Length</dt>', body)
|
||||
|
||||
def test_the_built_figure_sits_beneath_the_length(self):
|
||||
row = glance_length(unfinished())
|
||||
|
||||
@@ -214,9 +214,11 @@ class CreditsTest(unittest.TestCase):
|
||||
for rec in records.load_records(ROOT):
|
||||
page = read(OUT, "trails", rec["id"], "index.html")
|
||||
if 'data-map="' in page:
|
||||
caption = page[page.index('<figcaption class="mapfig__caption'):]
|
||||
caption = caption[:caption.index("</figcaption>")]
|
||||
self.assertIn(credit, caption, rec["id"])
|
||||
# beside the map, under the downloads
|
||||
beside = page[page.index('<section class="map-credit"'):]
|
||||
beside = beside[:beside.index("</section>")]
|
||||
self.assertIn(credit, beside, rec["id"])
|
||||
self.assertLess(page.index('class="mapfig '), page.index('<section class="map-credit"'))
|
||||
|
||||
def test_footer_credits_the_elevation_data_on_every_page(self):
|
||||
for base, _, names in os.walk(OUT):
|
||||
|
||||
+16
-5
@@ -241,7 +241,18 @@ class BuiltSiteTest(unittest.TestCase):
|
||||
self.assertNotIn("swatch", group, rec["id"])
|
||||
self.assertGreater(groups, 85)
|
||||
|
||||
def test_raw_record_table_holds_every_field(self):
|
||||
def test_no_page_in_the_build_sets_a_table(self):
|
||||
"""The site sets no tables: sets of trails are the trail rows, other sets are rows in the
|
||||
same language, and a record's raw fields are a definition list."""
|
||||
pages = 0
|
||||
for path in html_files(OUT):
|
||||
with open(path, encoding="utf-8") as f:
|
||||
doc = f.read()
|
||||
pages += 1
|
||||
self.assertNotIn("<table", doc, os.path.relpath(path, OUT))
|
||||
self.assertGreater(pages, 20)
|
||||
|
||||
def test_raw_record_listing_holds_every_field(self):
|
||||
for rec in self.records:
|
||||
with open(os.path.join(ROOT, rec["id"], "trail.toml"), "rb") as f:
|
||||
raw = tomllib.load(f)
|
||||
@@ -250,9 +261,9 @@ class BuiltSiteTest(unittest.TestCase):
|
||||
# the last block of the page's main column
|
||||
tail = page[page.index('<details class="rawrecord">'):]
|
||||
self.assertNotIn('<section class="block"', tail, rec["id"])
|
||||
table = re.search(r'<table class="rawrecord__table">(.*?)</table>', tail, re.S).group(1)
|
||||
listing = re.search(r'<dl class="rawrecord__fields">(.*?)</dl>', tail, re.S).group(1)
|
||||
rows = {html.unescape(f): re.sub(r"\s+", " ", html.unescape(v)).strip()
|
||||
for f, v in re.findall(r'<tr><th scope="row"><code>(.*?)</code></th><td>(.*?)</td></tr>', table, re.S)}
|
||||
for f, v in re.findall(r'<div><dt><code>(.*?)</code></dt><dd>(.*?)</dd></div>', listing, re.S)}
|
||||
fields = dict(leaves(raw))
|
||||
self.assertEqual(set(rows), set(fields), rec["id"])
|
||||
for field, value in fields.items():
|
||||
@@ -445,7 +456,7 @@ class RenderUnitTest(unittest.TestCase):
|
||||
rec = sample_record("L Trail")
|
||||
rec["hike"] = {"official_url": "https://official.example/"}
|
||||
rec["link"] = [{"title": "T", "publisher": "Wiki", "url": "https://wiki.example/t"}]
|
||||
buttons = re.search(r'<p class="cluster trail-actions">.*?</p>', trail.action_buttons(rec), re.S).group(0)
|
||||
buttons = re.search(r'<p class="trail-actions">.*?</p>', trail.action_buttons(rec), re.S).group(0)
|
||||
self.assertIn("Official site", buttons)
|
||||
self.assertNotIn("wiki.example", buttons)
|
||||
|
||||
@@ -453,7 +464,7 @@ class RenderUnitTest(unittest.TestCase):
|
||||
rec = sample_record("L Trail")
|
||||
rec["link"] = [{"title": "T", "publisher": "Wiki Pub", "url": "https://wiki.example/t"},
|
||||
{"title": "U", "publisher": "Other", "url": "https://other.example/u"}]
|
||||
buttons = re.search(r'<p class="cluster trail-actions">.*?</p>', trail.action_buttons(rec), re.S).group(0)
|
||||
buttons = re.search(r'<p class="trail-actions">.*?</p>', trail.action_buttons(rec), re.S).group(0)
|
||||
self.assertIn('href="https://wiki.example/t"', buttons)
|
||||
self.assertIn("Wiki Pub", buttons)
|
||||
self.assertNotIn("other.example", buttons)
|
||||
|
||||
@@ -175,7 +175,7 @@ class SaveButtonsTest(unittest.TestCase):
|
||||
def test_every_trail_page_has_a_save_button_by_its_actions(self):
|
||||
for rec in self.records:
|
||||
doc = read_out(f"trails/{rec['id']}/index.html")
|
||||
actions = doc[doc.index('<p class="cluster trail-actions">'):doc.index("</p>", doc.index('<p class="cluster trail-actions">'))]
|
||||
actions = doc[doc.index('<p class="trail-actions">'):doc.index("</p>", doc.index('<p class="trail-actions">'))]
|
||||
m = re.search(r'<button class="button button--quiet save save--page js-only" type="button" '
|
||||
r'data-save="([^"]+)" aria-pressed="false">', actions)
|
||||
self.assertTrue(m, rec["id"])
|
||||
|
||||
@@ -294,9 +294,9 @@ class LeftOutLayoutTest(unittest.TestCase):
|
||||
entries = [{"id": "a", "name": "A", "country": "US", "regions": ["AZ"], "reason": "below-floor",
|
||||
"note": "Short.", "decided": "2026-11-14", "source_url": "https://e.org/"}]
|
||||
body = str(leftout.left_out_page(entries, S, "")[2])
|
||||
# .place spaces its children apart (the intro from the first heading), and
|
||||
# .section--finder gives the intro the same short space above as the home page's list.
|
||||
opening = '<div class="container section section--finder place">'
|
||||
# .place spaces its children apart (the intro from the first heading); each reason is a
|
||||
# section of rows in the language of a trail's row.
|
||||
opening = '<div class="container section place left-out">'
|
||||
self.assertIn(opening, body)
|
||||
main = body[body.index(opening):]
|
||||
self.assertLess(main.index('<p class="prose">'), main.index("<section"))
|
||||
|
||||
+14
-14
@@ -242,25 +242,25 @@ class InBrief(unittest.TestCase):
|
||||
def test_the_map_area_comes_first_and_the_paragraph_is_under_it(self):
|
||||
rec = load("appalachian")
|
||||
body = str(trail.render(rec, SITE, [rec])[2])
|
||||
order = ['class="titleblock', 'class="cluster trail-actions"', 'id="glance-title"', 'class="mapfig ',
|
||||
'id="brief-title"', 'class="trail-brief"', 'class="note trail-checked"']
|
||||
order = ['class="titleblock', 'class="trail-actions"', 'class="mapfig ', 'id="glance-title"',
|
||||
'class="detail__text"', 'id="brief-title"', 'class="trail-summary"', 'class="trail-brief"',
|
||||
'class="note trail-checked"']
|
||||
at = [body.index(x) for x in order]
|
||||
self.assertEqual(at, sorted(at), order)
|
||||
self.assertIn("<h2 id=\"brief-title\">In brief</h2>", body)
|
||||
self.assertIn('class="trail-summary"', body) # the summary in full stays in the page, as text
|
||||
self.assertIn('<h2 id="brief-title" class="vh">In brief</h2>', body)
|
||||
self.assertIn("<strong>In brief.</strong>", body)
|
||||
self.assertLess(body.index('id="brief-title"'), body.index('id="morelinks-title"') if 'id="morelinks-title"' in body else len(body))
|
||||
|
||||
def test_the_lead_above_the_map_is_the_first_sentence_and_only_when_short(self):
|
||||
def test_nothing_stands_between_the_head_and_the_map(self):
|
||||
rec = load("appalachian")
|
||||
lead = text_of(trail.lead_text(rec))
|
||||
self.assertTrue(hike.summary(rec).startswith(lead))
|
||||
self.assertLessEqual(len(lead), trail.LEAD_MAX)
|
||||
long_rec = copy.deepcopy(rec)
|
||||
long_rec["hike"]["summary"] = "A " + "very " * 60 + "long first sentence. A second one."
|
||||
self.assertEqual(str(trail.lead_text(long_rec)), "")
|
||||
body = str(trail.render(long_rec, SITE, [long_rec])[2])
|
||||
self.assertNotIn('class="trail-lede"', body)
|
||||
self.assertIn("very very", body) # but the whole summary is under the map
|
||||
body = str(trail.render(rec, SITE, [rec])[2])
|
||||
between = body[body.index('class="page-head page-head--trail"'):body.index('class="mapfig ')]
|
||||
self.assertNotIn("trail-lede", between)
|
||||
self.assertNotIn("trail-summary", between)
|
||||
# the actions are part of the head, and the phone's strip of key facts is the only thing after it
|
||||
head = between[:between.index('<div class="container detail')]
|
||||
self.assertIn('class="trail-actions"', head)
|
||||
self.assertIn('class="trail-strip"', between[len(head):])
|
||||
|
||||
|
||||
def words_km(rec):
|
||||
|
||||
+22
-13
@@ -252,15 +252,19 @@ class AuthorTest(unittest.TestCase):
|
||||
self.assertIn("also credited to <a href=\"/authors/andrew-skurka/\">Andrew Skurka</a>", str(body))
|
||||
self.assertEqual(person["@type"], "Person")
|
||||
|
||||
def test_featured_authors_are_cards_with_lengths_that_follow_the_units_switch(self):
|
||||
def test_featured_authors_lead_the_page_with_their_routes_as_the_site_s_rows(self):
|
||||
recs = self.routes(["Cam Honan"] * 3 + ["A Club"])
|
||||
_, _, body, _ = authors.index_page(recs, SITE, ROOT)
|
||||
html = str(body)
|
||||
self.assertIn('<li class="shelf shelf--author">', html)
|
||||
self.assertIn('class="shelf__count"', html)
|
||||
self.assertIn('class="shelf__len"><span class="len len--inline"><span class="len__mi">', html)
|
||||
self.assertIn("All 3 routes by Cam Honan", html)
|
||||
self.assertNotIn("A Club</a></h3>", html)
|
||||
self.assertNotIn("<table", html)
|
||||
self.assertNotIn("shelf", html)
|
||||
head = '<h2 class="results__group"><a href="/authors/cam-honan/">Cam Honan</a> <span class="results__n">3 routes</span></h2>'
|
||||
self.assertIn(head, html)
|
||||
rows = html[html.index(head):]
|
||||
self.assertEqual(rows[:rows.index("</ol>")].count('<li class="entry"'), 3)
|
||||
self.assertIn('class="len__mi"', rows) # lengths follow the units switch
|
||||
self.assertNotIn('class="results__group"><a href="/authors/a-club/"', html)
|
||||
self.assertIn('/authors/a-club/', html) # listed among the other authors
|
||||
|
||||
def test_every_author_has_a_page_however_few_routes(self):
|
||||
recs = self.routes(["Andrew Skurka"] * 3 + ["Andrew Skurka and Ryan Jordan"] * 2 + ["Cam Honan"] * 4 + ["A Club"])
|
||||
@@ -273,7 +277,8 @@ class AuthorTest(unittest.TestCase):
|
||||
one = next(g for g in gs if len(g["routes"]) == 1 and g["kind"] == "person")
|
||||
title, desc, body, _, routes, person = authors.author_page(one, real, SITE, gs)
|
||||
self.assertIn('class="trail-brief"', str(body))
|
||||
self.assertIn("<table", str(body))
|
||||
self.assertNotIn("<table", str(body))
|
||||
self.assertIn('<li class="entry"', str(body))
|
||||
self.assertLessEqual(len(title), 60)
|
||||
self.assertEqual(person["name"], one["name"])
|
||||
club = next(g for g in gs if g["name"] == "Wilderness Mindset")
|
||||
@@ -290,10 +295,10 @@ class AuthorTest(unittest.TestCase):
|
||||
counts = [len(g["routes"]) for g in top]
|
||||
self.assertEqual(counts, sorted(counts, reverse=True))
|
||||
body = str(authors.index_page(real, SITE, ROOT)[2])
|
||||
self.assertLess(body.index('id="most-routes"'), body.index('id="other-authors"'))
|
||||
self.assertLess(body.index('id="most-routes"'), body.index('class="browse-about"'))
|
||||
for g in top:
|
||||
self.assertLess(body.index(f'<h3 class="shelf__title"><a href="/authors/{g["slug"]}/">'), body.index('id="other-authors"'))
|
||||
self.assertEqual(body.count('class="shelf shelf--author"'), len(top))
|
||||
self.assertLess(body.index(f'<h2 class="results__group"><a href="/authors/{g["slug"]}/">'), body.index('class="browse-about"'))
|
||||
self.assertEqual(body.count('<h2 class="results__group">'), len(top))
|
||||
old = authors.PROMINENT_MIN
|
||||
try:
|
||||
authors.PROMINENT_MIN = 5
|
||||
@@ -384,10 +389,14 @@ class SummaryTest(unittest.TestCase):
|
||||
self.assertIn("Its high point is Top", text)
|
||||
self.assertEqual(str(summary.details([fake(i) for i in range(summary.DETAIL_MAX + 1)])), "")
|
||||
|
||||
def test_place_page_says_how_many_trails_and_the_share(self):
|
||||
def test_place_page_says_what_its_trails_are_after_the_rows_without_arithmetic(self):
|
||||
recs = [fake(i, regions=["AZ"]) for i in range(4)] + [fake(5, regions=["UT"])]
|
||||
title, desc, body, _ = regions.region_page("us-az", recs, SITE)
|
||||
self.assertIn("4 trails of the 5 trails on this site, 80.0 percent", str(body))
|
||||
body = str(body)
|
||||
self.assertIn("The longest is", body)
|
||||
self.assertNotIn("percent", body)
|
||||
self.assertLess(body.index('class="browse__list"'), body.index("The longest is"))
|
||||
self.assertEqual(body[body.index('class="browse-about"'):].count("<p>"), 1) # one short paragraph
|
||||
|
||||
|
||||
class RealDataTest(unittest.TestCase):
|
||||
@@ -438,7 +447,7 @@ class RealDataTest(unittest.TestCase):
|
||||
by_slug, _ = regions.collect_regions(self.records)
|
||||
for slug in by_slug:
|
||||
_, _, body, _ = regions.region_page(slug, self.records, SITE)
|
||||
self.assertIn("place-summary", str(body))
|
||||
self.assertIn('class="browse-about"', str(body))
|
||||
if len(by_slug[slug]["records"]) > 1:
|
||||
self.assertIn("The longest is", str(body))
|
||||
|
||||
|
||||
Reference in new issue
Block a user