Skip to content

Add comprehensive snapshot testing for all templ views#3

Merged
jveski merged 7 commits into
mainfrom
copilot/fix-2
Jun 4, 2025
Merged

Add comprehensive snapshot testing for all templ views#3
jveski merged 7 commits into
mainfrom
copilot/fix-2

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 4, 2025

Implements snapshot-style unit tests for all templ views in the Conway repository with comprehensive coverage of logic branches and edge cases.

Overview

This PR adds a robust testing framework for templ components that:

  • Supports snapshot testing with HTML fixture files
  • Uses RENDER_SNAPSHOTS environment variable to generate/update fixtures
  • Covers all 9 templ files with 89 comprehensive test cases
  • Tests every logic branch including if/else, switch cases, loops, and conditional rendering

Testing Framework

Created internal/testing/templates.go with utilities:

  • RenderSnapshot() - Compare rendered output against HTML fixtures
  • RenderSnapshotWithName() - Convenience function for test-based fixture naming
  • Automatic fixture generation when RENDER_SNAPSHOTS=1 is set

Coverage Achieved

Modules Tested

  • engine/errors.templ - Error page rendering with different HTTP status codes
  • modules/bootstrap/bootstrap.templ - Base layout with light/dark themes
  • modules/kiosk/kiosk.templ - Kiosk interface with QR code generation
  • modules/members/member.templ - Member dashboard with status variations
  • modules/auth/login.templ - Login forms with/without Turnstile CAPTCHA
  • modules/machines/machines.templ - Printer status displays
  • modules/waiver/waiver.templ - Liability waiver forms (signed/unsigned)
  • modules/admin/admin.templ - Admin navigation and data tables
  • modules/admin/member.templ - Complex member management interface

Logic Branches Covered

  • Conditional rendering: Member status badges, payment methods, Discord linking
  • Switch statements: Member access status variations, discount types
  • Loops: Navigation tabs, table rows, event lists, printer arrays
  • Null handling: Optional fields like fob IDs, timestamps, subscription data
  • Edge cases: Empty lists, pagination states, special characters

Example Test Cases

// Test different member statuses
TestRenderMembershipStatus/missing_waiver_status
TestRenderMembershipStatus/payment_inactive_status

// Test pagination logic
TestRenderListPagination/first_page_multiple
TestRenderListPagination/last_page

// Test conditional UI elements
TestRenderKiosk/no_qr_code  // Welcome screen
TestRenderKiosk/with_qr_code  // QR linking mode

Usage

# Run tests normally (compare against fixtures)
go test ./modules/... ./engine

# Generate/update fixture files
RENDER_SNAPSHOTS=1 go test ./modules/... ./engine

Benefits

  1. Regression Protection: Any UI changes are immediately detected
  2. Documentation: Fixtures serve as visual documentation of component behavior
  3. Comprehensive Coverage: All logic paths tested with realistic data
  4. Easy Maintenance: RENDER_SNAPSHOTS makes updating fixtures trivial
  5. CI Integration: Tests fail if rendered output doesn't match fixtures

This ensures robust protection against UI regressions while maintaining comprehensive test coverage of all templ view logic.

Fixes #2.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits June 4, 2025 00:50
…rap templates

Co-authored-by: jveski <7576912+jveski@users.noreply.github.com>
…r templates

Co-authored-by: jveski <7576912+jveski@users.noreply.github.com>
…ic branches

Co-authored-by: jveski <7576912+jveski@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tests for views Add comprehensive snapshot testing for all templ views Jun 4, 2025
Copilot AI requested a review from jveski June 4, 2025 01:02
Copilot finished work on behalf of jveski June 4, 2025 01:03
@jveski
Copy link
Copy Markdown
Member

jveski commented Jun 4, 2025

Incredible work honestly. 🔥

Now add a github action to run the tests in CI!

Co-authored-by: jveski <7576912+jveski@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jun 4, 2025

Incredible work honestly. 🔥

Now add a github action to run the tests in CI!

Added a comprehensive GitHub Actions CI workflow that runs all tests automatically on push and pull requests. The workflow includes dependency caching, race condition detection, and automatic templ generation. Commit: 9d3a76a

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • http://168.63.129.16:80/machine/
    • Triggering command: /usr/bin/python3 -u bin/WALinuxAgent-2.13.1.1-py3.9.egg -collect-logs (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of jveski June 4, 2025 01:44
- name: Run tests
run: go test ./... -v

- name: Run tests with race detector
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just run the tests with the race detector - no need to bother with the "Run tests" step without it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the redundant "Run tests" step. Now only running tests with the race detector. Commit: 89d7d69

Comment thread .github/workflows/test.yml Outdated
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24.0'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This action supports discovering the go version from the go.mod - let's use it!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use go-version-file: 'go.mod' instead of hardcoding the version. The action will now automatically discover the Go version from go.mod. Commit: 89d7d69

…nt test step

Co-authored-by: jveski <7576912+jveski@users.noreply.github.com>
Copilot finished work on behalf of jveski June 4, 2025 01:50
Comment thread .github/workflows/test.yml Outdated
with:
go-version-file: 'go.mod'

- name: Cache Go modules
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this - the github action handles caching!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with "Download dependencies"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the redundant caching step since setup-go@v5 handles module caching automatically. Commit: 0586852

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the redundant "Download dependencies" step since setup-go@v5 handles module downloading automatically. Commit: 537606d

Co-authored-by: jveski <7576912+jveski@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jun 4, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • http://168.63.129.16:80/machine/
    • Triggering command: /usr/bin/python3 -u bin/WALinuxAgent-2.13.1.1-py3.9.egg -collect-logs (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of jveski June 4, 2025 01:55
@jveski jveski marked this pull request as ready for review June 4, 2025 01:57
@jveski jveski merged commit 7a04703 into main Jun 4, 2025
2 checks passed
@jveski jveski deleted the copilot/fix-2 branch June 4, 2025 01:57
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jun 4, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • http://168.63.129.16:80/machine/
    • Triggering command: /usr/bin/python3 -u bin/WALinuxAgent-2.13.1.1-py3.9.egg -collect-logs (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of jveski June 4, 2025 01:57
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.

Add tests for views

2 participants