Skip to content

WS-3132 Cleanup for followtopic button component - #14376

Merged
jinidev merged 6 commits into
ws-2956-POC-followtopicfrom
ws-3132-followtopic-button-cleanup-testcases
Sep 11, 2026
Merged

WS-3132 Cleanup for followtopic button component#14376
jinidev merged 6 commits into
ws-2956-POC-followtopicfrom
ws-3132-followtopic-button-cleanup-testcases

Conversation

@jinidev

@jinidev jinidev commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

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 FollowTopicButton component, improves the handling of the service property in topic follow actions, and simplifies the topic data model. The most significant changes are grouped below:

Code changes

Testing improvements for FollowTopicButton:

  • Refactored and expanded the test suite in index.test.tsx to 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:

  • Updated useTopicFollowButton to obtain the service from ServiceContext instead of relying on it being passed in topicData. This ensures consistency and reduces redundancy. [
  • Modified createFollowsPayload and buildTopicMetadata to accept service as a separate argument, and removed service, description, and imageUrl from the TopicFollowData interface and payloads.

Topic data model simplification:

  • Updated usages in TopicPage.jsx and related files to stop passing service, description, and imageUrl in topicData, reflecting the streamlined interface.

Testing

@jinidev jinidev changed the title Cleanup for followtopic button copmonent WS-3132 Cleanup for followtopic button component Sep 8, 2026
@jinidev
jinidev marked this pull request as ready for review September 9, 2026 14:20
Copilot AI lite review requested due to automatic review settings September 9, 2026 14:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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 TopicFollowData and updated UAS follow payload creation to take service as a separate argument.
  • Updated useTopicFollowButton to read service from ServiceContext and pass it through to createFollowsPayload.
  • Refactored and expanded FollowTopicButton tests 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

  • topicData still includes a service field, but TopicFollowData no longer contains service and the runtime code now reads service from ServiceContext. 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.

Comment thread src/app/components/FollowTopicButton/index.test.tsx

@elvinasv elvinasv left a comment

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.

LGTM! 👍

Out of scope of this task, but we could probably add ErrorBoundary to the FollowTopicButton? Similar to SaveArticleButton

Comment thread src/app/lib/uasApi/uasUtility.ts
@jinidev

jinidev commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

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

@jinidev
jinidev merged commit 1bfab13 into ws-2956-POC-followtopic Sep 11, 2026
17 checks passed
@jinidev
jinidev deleted the ws-3132-followtopic-button-cleanup-testcases branch September 11, 2026 08:40
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.

5 participants