Skip to content

Add tests for shared components (FollowButton, PolicyActions, LabeledIcon, MessageBanner, TitledSectionCard, PaginatedItemsCard) - #2226

Open
olitreadwell wants to merge 3 commits into
codeforboston:mainfrom
olitreadwell:test/shared-components-coverage
Open

Add tests for shared components (FollowButton, PolicyActions, LabeledIcon, MessageBanner, TitledSectionCard, PaginatedItemsCard)#2226
olitreadwell wants to merge 3 commits into
codeforboston:mainfrom
olitreadwell:test/shared-components-coverage

Conversation

@olitreadwell

Copy link
Copy Markdown

Summary

Adds unit tests for the shared components that back the testimony, bill, and committee pages: FollowButton, PolicyActions, LabeledIcon, MessageBanner, TitledSectionCard, and PaginatedItemsCard. The tests lock in the logged-out Follow redirect, the follow/unfollow confirmation modals, and presentational rendering for the shared components.

Checklist

  • On the frontend, I've made my strings translate-able.
  • If I've added shared components, I've added a storybook story.
  • I've made pages responsive and look good on mobile.
  • If I've added new Firestore queries, I've added any new required indexes to firestore.indexes.json (Please do not only create indexes through the Firebase Web UI, even though the error messages may reccommend it - indexes created this way may be obliterated by subsequent deploys)

Screenshots

N/A. Test-only change.

Known issues

N/A

Steps to test/reproduce

  1. git fetch https://github.com/olitreadwell/maple.git test/shared-components-coverage
  2. git checkout FETCH_HEAD
  3. yarn install --frozen-lockfile
  4. yarn jest components/shared/ components/testimony/TestimonyDetailPage/PolicyActions.test.tsx --runInBand

AI assistance

Drafted with AI assistance. The gap was found and verified against the current code, the change was verified before opening, and this diff was reviewed line by line.

A logged-out visitor could click a Follow button (bill, profile, or
ballot question) and nothing would happen. The button called the
Firestore follow/unfollow write with an undefined uid, which fails
silently for a signed-out user, so the click looked broken (codeforboston#2059).

Following only makes sense for a signed-in user. This makes the
button send a logged-out visitor to /login, with a redirect back to
the current page, the same pattern the app already uses for other
auth-only pages (see requireAuth in components/auth/service.tsx).

- BaseFollowButton now checks for a uid before calling the follow or
  unfollow action. If there is no uid, it pushes to
  /login?redirect=<current path> instead.
- Added a test that covers both cases: a logged-out click redirects
  to login without calling followAction, and a logged-in click still
  calls followAction as before.
- Split the onClick assignment into two statements instead of a
  nested ternary, per an AI code review pass (open-code-review):
  the repo's rules disallow nested ternaries. Behaviour is unchanged.
…ny page

The testimony detail page has its own separate Follow/Unfollow list
item (PolicyActions), independent of BaseFollowButton. It had the same
bug: a logged-out visitor clicking "Follow" called followBill or
followBallotQuestion with an undefined uid, which writes to a Firestore
path keyed on "undefined" and fails silently, so the click looked
broken.

Reproduced with a test that mocks a logged-out user and confirms the
click called followBallotQuestion(undefined, ...) without any redirect.

- handleClick now checks for a uid before calling FollowClick or
  UnfollowClick. If there is no uid, it pushes to
  /login?redirect=<current path>, the same pattern BaseFollowButton
  uses.
- Added a test that covers the logged-out case: the click redirects to
  login and never calls followBallotQuestion or followBill.
@vercel

vercel Bot commented Aug 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
maple-dev Ready Ready Preview Aug 26, 2026 3:18pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
maple-prod Ignored Ignored Aug 26, 2026 3:18pm

Request Review

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