templates: add templ components and equivalence tests for already-converted pages#201
Open
sumnerevans wants to merge 3 commits intomasterfrom
Open
templates: add templ components and equivalence tests for already-converted pages#201sumnerevans wants to merge 3 commits intomasterfrom
sumnerevans wants to merge 3 commits intomasterfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Retroactively adds templ components and equivalence tests for all pages already converted in the
templ-refactorbranch, before those conversions land on master. This establishes the test baseline so future conversions can be proven equivalent.a-h/templandgolang.org/x/netas direct depsinternal/contextkeyspackage andinternal/templates/partials/pagenames.gobase,home,info,authors,rules,register,faq,archive, navbar partial, footer partial, teacher logininternal/archive.goto remove duplicate type definitions (moved toarchive.templ) — no runtime behavior change,GetArchiveTemplatestill worksapplication.go— runtime still useshtml/templateFixes found during conversion (vs templ-refactor):
home.templcontent synced to current master (2026 competition info)archive.templaccordion structure fixed: collapse div now nested inside accordion-item (was a sibling — broken Bootstrap accordion)navbar.templusesregistration-link/registration-link-activeto match old HTML class nameslogin.templonly emitsvalue=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 withgolang.org/x/net/html, skips whitespace-only text nodes and comments, normalizes attribute order and CSS class whitespacehtml/template(viaExecuteTemplate("content", ...)) and templ component directly, then asserts DOM equivalenceTest plan
go test ./internal/templates/...— all 12 tests passgo build ./...— compiles cleanly🤖 Generated with Claude Code