refactor(homeview): extract formatDesc into testable functions #167

Merged
fuzzy merged 1 commit from refactor/165-extract-formatdesc into main 2026-07-07 06:17:54 +00:00
Owner

What

Extract formatDesc, opTypeLabel, activityColor, and timeAgo from closures inside HomeView.renderActivities() into package-level functions so they can be unit tested.

Adds homeview_test.go with 46 table-driven subtests covering:

  • All known op type labels
  • Time ago formatting edge cases (now, minutes, hours, days, months)
  • Activity description formatting for all op types with both empty and non-empty comments

Why

Closes #165. The closures were impossible to unit test. The refactored functions are simple, stateless, and fully covered.

Testing

  • 46 new unit tests pass
  • go build ./... passes
  • go test ./... passes
  • All pre-commit hooks pass (golangci-lint, go fmt, go mod tidy)

Breaking Changes

None — pure refactor, no behavior changes.

Closes #165

## What Extract `formatDesc`, `opTypeLabel`, `activityColor`, and `timeAgo` from closures inside `HomeView.renderActivities()` into package-level functions so they can be unit tested. Adds `homeview_test.go` with 46 table-driven subtests covering: - All known op type labels - Time ago formatting edge cases (now, minutes, hours, days, months) - Activity description formatting for all op types with both empty and non-empty comments ## Why Closes #165. The closures were impossible to unit test. The refactored functions are simple, stateless, and fully covered. ## Testing - [x] 46 new unit tests pass - [x] `go build ./...` passes - [x] `go test ./...` passes - [x] All pre-commit hooks pass (golangci-lint, go fmt, go mod tidy) ## Breaking Changes None — pure refactor, no behavior changes. Closes #165
refactor(homeview): extract formatDesc into testable functions
All checks were successful
Test and Release / test (pull_request) Successful in 8m12s
Test and Release / lint (pull_request) Successful in 8m27s
50b1c7f8e9
Extract formatDesc, opTypeLabel, activityColor, and timeAgo from
closures inside renderActivities() into package-level functions so
they can be unit tested. Add table-driven test suite covering all
op types, time formatting, and edge cases.

Closes #165
the.auditor approved these changes 2026-07-07 06:11:24 +00:00
Dismissed
the.auditor left a comment

Review

Result: Approved — no blocking issues. Closes #165.

Summary: Pure refactor — extracts 4 closures to package-level functions with zero behavior change. Adds 46 table-driven subtests coverting opTypeLabel, timeAgo, and formatActivityDesc across known types, edge cases, and fallback paths. Tests pass, build passes.

Checklist:

  • Correctness: Identical logic, no captured state leaked or lost.
  • Completeness: All four closures extracted, all references updated.
  • Test coverage: 46 subtests covering happy paths, empty comments, fallbacks. Missing activityColor (trivial) and commit payload parsing (complex) — acceptable gaps.
  • Error handling: Unchanged — same fallback chains.
  • Performance: No change — same allocations, same paths.
  • Maintainability: Significantly improved — functions now testable and independently understandable.
  • Security: No concerns (display-only code).
## Review **Result: Approved** — no blocking issues. Closes #165. **Summary:** Pure refactor — extracts 4 closures to package-level functions with zero behavior change. Adds 46 table-driven subtests coverting opTypeLabel, timeAgo, and formatActivityDesc across known types, edge cases, and fallback paths. Tests pass, build passes. **Checklist:** - Correctness: ✅ Identical logic, no captured state leaked or lost. - Completeness: ✅ All four closures extracted, all references updated. - Test coverage: ✅ 46 subtests covering happy paths, empty comments, fallbacks. Missing activityColor (trivial) and commit payload parsing (complex) — acceptable gaps. - Error handling: ✅ Unchanged — same fallback chains. - Performance: ✅ No change — same allocations, same paths. - Maintainability: ✅ Significantly improved — functions now testable and independently understandable. - Security: ✅ No concerns (display-only code).
fuzzy force-pushed refactor/165-extract-formatdesc from 50b1c7f8e9
All checks were successful
Test and Release / test (pull_request) Successful in 8m12s
Test and Release / lint (pull_request) Successful in 8m27s
to 9ede7e1670
All checks were successful
Test and Release / test (pull_request) Successful in 2m50s
Test and Release / lint (pull_request) Successful in 3m46s
2026-07-07 06:13:23 +00:00
Compare
fuzzy dismissed the.auditor's review 2026-07-07 06:13:23 +00:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

the.auditor left a comment

Re-Review

Result: Approved — no blocking issues.

Changes since previous review:

  • Added TestActivityColor (20 cases) — covers all known op types + default
  • Added 4 commit/push payload tests to TestFormatActivityDesc — covers first commit, push, head commit fallback, and malformed JSON
  • Total tests: 74 subtests (up from 50)

Minor (non-blocking): Test name "commit_repo returns empty on malformed payload" is misleading — expected value is "not json" (raw content fallback), not empty string. Consider renaming to "commit_repo falls back to content on malformed payload".

Updated checklist:

  • Correctness: No behavior change — pure refactor
  • Completeness: All four closures extracted
  • Test coverage: 74 subtests covering all functions, all known types, edge cases, fallbacks
  • Maintainability: Significantly improved — testable, independent functions
## Re-Review **Result: Approved** — no blocking issues. **Changes since previous review:** - Added `TestActivityColor` (20 cases) — covers all known op types + default - Added 4 commit/push payload tests to `TestFormatActivityDesc` — covers first commit, push, head commit fallback, and malformed JSON - Total tests: 74 subtests (up from 50) **Minor (non-blocking):** Test name `"commit_repo returns empty on malformed payload"` is misleading — expected value is `"not json"` (raw content fallback), not empty string. Consider renaming to `"commit_repo falls back to content on malformed payload"`. **Updated checklist:** - Correctness: ✅ No behavior change — pure refactor - Completeness: ✅ All four closures extracted - Test coverage: ✅ 74 subtests covering all functions, all known types, edge cases, fallbacks - Maintainability: ✅ Significantly improved — testable, independent functions
fuzzy scheduled this pull request to auto merge when all checks succeed 2026-07-07 06:17:18 +00:00
fuzzy merged commit 9ede7e1670 into main 2026-07-07 06:17:54 +00:00
fuzzy deleted branch refactor/165-extract-formatdesc 2026-07-07 06:17:54 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thwap/steeper!167
No description provided.