63 lines
2.6 KiB
Python
63 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import unittest
|
|
|
|
|
|
class HomeTemplateTests(unittest.TestCase):
|
|
def setUp(self) -> None:
|
|
site_root = Path(__file__).resolve().parents[1]
|
|
self.template = (site_root / "templates" / "home.html").read_text(
|
|
encoding="utf-8"
|
|
)
|
|
|
|
def test_recent_activity_uses_shared_generated_record_paths(self) -> None:
|
|
recent_activity = self.template.split(
|
|
'<section class="homepage-panel featured-projects-panel"', 1
|
|
)[0]
|
|
|
|
self.assertIn("for item_path in this.recent_activity_paths", recent_activity)
|
|
self.assertIn("site.get(item_path)", recent_activity)
|
|
self.assertNotIn("entries.append", recent_activity)
|
|
|
|
def test_recent_activity_exposes_visible_atom_and_rss_links(self) -> None:
|
|
recent_activity = self.template.split(
|
|
'<section class="homepage-panel featured-projects-panel"', 1
|
|
)[0]
|
|
|
|
self.assertIn("https://www.labyricorn.com/feed.xml", recent_activity)
|
|
self.assertIn("https://www.labyricorn.com/rss.xml", recent_activity)
|
|
|
|
def test_tag_matrix_is_last_homepage_section_and_uses_canonical_tags(self) -> None:
|
|
matrix_position = self.template.index("{% set tracked_tags")
|
|
featured_position = self.template.index(
|
|
'class="homepage-panel featured-projects-panel"'
|
|
)
|
|
|
|
self.assertGreater(matrix_position, featured_position)
|
|
self.assertIn("site.get('/tags').children", self.template[matrix_position:])
|
|
self.assertIn('href="{{ tag|url }}"', self.template[matrix_position:])
|
|
self.assertNotIn("'/tags/' ~ tag", self.template[matrix_position:])
|
|
|
|
def test_tag_matrix_counts_all_discovery_content_and_caps_weighting(self) -> None:
|
|
matrix = self.template.split('class="homepage-tag-section"', 1)[1]
|
|
|
|
self.assertIn("['projects', 'blog', 'articles']", matrix)
|
|
self.assertIn("entry.topic_tag_slugs", matrix)
|
|
self.assertIn("usage.count >= 8", matrix)
|
|
self.assertIn("usage.count >= 4", matrix)
|
|
self.assertIn("usage.count >= 2", matrix)
|
|
self.assertIn("tag-matrix-level-{{ weight }}", matrix)
|
|
|
|
def test_tag_matrix_keeps_links_semantic_and_summary_optional(self) -> None:
|
|
matrix = self.template.split('class="homepage-tag-section"', 1)[1]
|
|
|
|
self.assertIn('aria-label="Explore content by topic"', matrix)
|
|
self.assertIn('rel="tag"', matrix)
|
|
self.assertIn("data-tag-summary", matrix)
|
|
self.assertIn("published {% if usage.count == 1 %}entry", matrix)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|