Skip to content

templates: add templ components and equivalence tests for already-converted pages#201

Open
sumnerevans wants to merge 3 commits intomasterfrom
test/templ-equivalence
Open

templates: add templ components and equivalence tests for already-converted pages#201
sumnerevans wants to merge 3 commits intomasterfrom
test/templ-equivalence

Conversation

@sumnerevans
Copy link
Copy Markdown
Contributor

Summary

Retroactively adds templ components and equivalence tests for all pages already converted in the templ-refactor branch, before those conversions land on master. This establishes the test baseline so future conversions can be proven equivalent.

  • Adds a-h/templ and golang.org/x/net as direct deps
  • Adds internal/contextkeys package and internal/templates/partials/pagenames.go
  • Adds templ components: base, home, info, authors, rules, register, faq, archive, navbar partial, footer partial, teacher login
  • Updates internal/archive.go to remove duplicate type definitions (moved to archive.templ) — no runtime behavior change, GetArchiveTemplate still works
  • Does not delete any HTML files or change application.go — runtime still uses html/template

Fixes found during conversion (vs templ-refactor):

  • home.templ content synced to current master (2026 competition info)
  • archive.templ accordion structure fixed: collapse div now nested inside accordion-item (was a sibling — broken Bootstrap accordion)
  • navbar.templ uses registration-link / registration-link-active to match old HTML class names
  • login.templ only emits value= attribute when email is non-empty (matches {{ with .Data.Email }} behavior)

Test infrastructure:

  • internal/templates/testhelpers/html.go — DOM-based HTML comparison: parses both renders with golang.org/x/net/html, skips whitespace-only text nodes and comments, normalizes attribute order and CSS class whitespace
  • 12 equivalence tests across 5 files (home ×2, register ×2, archive ×1, navbar ×3, teacher login ×3)
  • Each test renders both html/template (via ExecuteTemplate("content", ...)) and templ component directly, then asserts DOM equivalence

Test plan

  • go test ./internal/templates/... — all 12 tests pass
  • go build ./... — compiles cleanly

🤖 Generated with Claude Code

sumnerevans and others added 3 commits April 12, 2026 13:15
Add github.com/a-h/templ v0.2.697 for type-safe HTML templates and
golang.org/x/net v0.52.0 as a direct dependency for test HTML parsing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Bring in templ component equivalents of the HTML templates for: home,
info, authors, rules, register, faq, archive, navbar partial, footer
partial, base layout, and teacher login page.

Update internal/archive.go to remove duplicate type definitions
(Link, WinningTeam, CompetitionResult, YearInfo now live in the
templates package). Add archiveInfo package variable and update
GetArchiveTemplate to convert to the struct types expected by the
html/template renderer.

Add internal/contextkeys/keys.go with context key constants shared by
both the HTTP handlers and the templ components.

The runtime application.go is unchanged and continues to use
html/template; the templ components are not yet wired up.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add testhelpers.CompareHTML which parses HTML fragments into DOM trees
and diffs them structurally, ignoring whitespace-only text nodes,
HTML comments, spurious attributes from HTML syntax errors (e.g. trailing
commas), and normalises CSS class attribute whitespace.

Add equivalence tests for:
- Home page (registration enabled/disabled)
- Register page (registration enabled/disabled)
- Archive page (minimal fixture with 1 year, 2 divisions, 2 teams each)
- Navbar partial (no active page, active home page, logged-in user)
- Teacher login page (no error, email-not-found, email-not-confirmed)

Each test renders the same data with both the old html/template path
(executing the "content" or "navbar" named template) and the new templ
component, then asserts the resulting DOM trees are equivalent.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant