WS-3132 Cleanup for followtopic button component - #14376
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new test suite currently mocks #app/hooks/useTopicFollowButton in a way that can unintentionally mock the FollowAction enum export, making the assertions unreliable and potentially causing test failures.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This pull request cleans up the FollowTopicButton implementation by simplifying the topic follow data contract, ensuring the follow action derives service from ServiceContext (instead of topicData), and significantly expanding/refactoring the component’s test coverage.
Changes:
- Simplified
TopicFollowDataand updated UAS follow payload creation to takeserviceas a separate argument. - Updated
useTopicFollowButtonto readservicefromServiceContextand pass it through tocreateFollowsPayload. - Refactored and expanded
FollowTopicButtontests to cover guest/auth states, hydration/loading, modal interactions, and allowlisting/IDCTA gating.
File summaries
| File | Description |
|---|---|
src/app/pages/TopicPage/TopicPage.jsx |
Stops passing service/description/imageUrl in topicData, aligning callers with the simplified follow contract. |
src/app/lib/uasApi/uasUtility.ts |
Updates TopicFollowData and adjusts follow payload/metadata builders to accept service separately. |
src/app/hooks/useTopicFollowButton/index.ts |
Sources service from ServiceContext and uses it when creating the UAS follow payload. |
src/app/components/FollowTopicButton/index.test.tsx |
Adds broader, more maintainable test coverage for Follow Topic behaviors and edge cases. |
Review details
Suppressed comments (1)
src/app/components/FollowTopicButton/index.test.tsx:54
topicDatastill includes aservicefield, butTopicFollowDatano longer containsserviceand the runtime code now readsservicefromServiceContext. Keeping this property in the test data is misleading and makes it easier for future changes to accidentally reintroduce the old contract.
const topicData = {
topicId: 'cw90edn9kw4t',
title: 'India',
service: 'hindi' as const,
url: 'https://www.bbc.com/hindi/topics/cw90edn9kw4t',
};
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
elvinasv
left a comment
There was a problem hiding this comment.
LGTM! 👍
Out of scope of this task, but we could probably add ErrorBoundary to the FollowTopicButton? Similar to SaveArticleButton
Thanks for the reminder .Will add this as part of this error handling ticket https://bbc.atlassian.net/browse/WS-3131 |
https://bbc.atlassian.net/browse/WS-3132
Note:
The parent PR for this is #14274, which has not yet been merged into the latest branch. We are productionizing this parent PR by creating smaller, subtask PRs.
Summary
This pull request refactors and expands the tests for the
FollowTopicButtoncomponent, improves the handling of theserviceproperty in topic follow actions, and simplifies the topic data model. The most significant changes are grouped below:Code changes
Testing improvements for
FollowTopicButton:index.test.tsxto add more comprehensive tests for both guest and authenticated states, including modal interactions, loading, followed/unfollowed states, and edge cases (e.g., service allowlisting and IDCTA availability). Introduced utility functions and mocks for better test isolation and maintainability.Service context and topic follow actions:
useTopicFollowButtonto obtain theservicefromServiceContextinstead of relying on it being passed intopicData. This ensures consistency and reduces redundancy. [createFollowsPayloadandbuildTopicMetadatato acceptserviceas a separate argument, and removedservice,description, andimageUrlfrom theTopicFollowDatainterface and payloads.Topic data model simplification:
TopicPage.jsxand related files to stop passingservice,description, andimageUrlintopicData, reflecting the streamlined interface.Testing