Skip to content

Conversation

@Rohit3523
Copy link
Collaborator

@Rohit3523 Rohit3523 commented Oct 31, 2025

Proposed changes

Right now, we use text matching to check the unread count, which sometimes makes the iOS tests flaky. In this PR, I added a test ID for the badge to make it more reliable.
Along with that, I also added a test to verify that we display the normal badge for regular messages and the red badge for mentions.

Added Testcase

  1. Another user sends a message to the user — it should show 1 in a grey circle.
  2. Another user mentions the user in a channel — it should show 1 in a red circle.
  3. Another user sends a normal message and then mentions the user — it should show 2 in a red circle.
  4. Another user mentions the user and then sends a normal message — it should show 2 in a red circle.

Working Action Link: https://github.com/RocketChat/Rocket.Chat.ReactNative/actions/runs/18985162911

Issue(s)

https://rocketchat.atlassian.net/browse/COMM-74

How to test or reproduce

Screenshots

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Documentation update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Further comments

Summary by CodeRabbit

  • Tests
    • Added comprehensive automated tests covering unread and mention badge behavior across messaging scenarios (normal messages, mentions, ordering combinations).
    • Improved test validation for unread indicators to increase reliability of badge verification.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 31, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Replaces a text-regex wait with an element-based wait in an existing Maestro test, adds a new Maestro test for unread/mention badge scenarios, and assigns testID attributes to the UnreadBadge component via a new helper.

Changes

Cohort / File(s) Summary
Refactored Maestro wait
.maestro/tests/room/mark-as-unread.yaml
Replaced waiting for visible text matching .*1.* with waiting for the presence of a specific element id unread-badge-1 inside the other user's room list item.
New Maestro test
.maestro/tests/room/unread-badge.yaml
Added a comprehensive Maestro test exercising unread badge and mention badge behaviors across multiple message-order scenarios, using evalScript, extendedWaitUntil (element id checks), tapOn, and timeouts.
Component testID addition
app/containers/UnreadBadge/index.tsx
Introduced getTestId(userMentions, groupMentions, unread) helper and applied the computed testID to the root View for reliable UI targeting in tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Attention points:
    • app/containers/UnreadBadge/index.tsx: verify the priority logic in getTestId() and ensure no UI rendering side-effects.
    • .maestro/tests/room/unread-badge.yaml: validate timing/timeout choices and element id consistency with the app.
    • .maestro/tests/room/mark-as-unread.yaml: confirm selector path for unread-badge-1 matches list-item structure.

Possibly related PRs

  • test: 4th batch of room test #6673 — Introduces similar test synchronization changes and adds a testID to UnreadBadge; directly related to the mark-as-unread/testID adjustments.

Poem

🐇 I hopped through code with nimble paws,
Found badges hiding without a cause.
Now testIDs gleam where eyes can see,
Unread and mention — clear as tea.
🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'test: fix unread badge test' is partially related to the changeset but does not capture the main objective. The PR primarily adds a new e2e test and improves test flakiness by introducing a testId, not fixing an existing test. Consider updating the title to better reflect the main changes, such as 'test: add unread badge e2e test with testId' or 'test: add unread badge e2e test and reduce flakiness'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f181c65 and 8e3a778.

⛔ Files ignored due to path filters (3)
  • app/containers/Header/components/HeaderButton/__snapshots__/HeaderButtons.test.tsx.snap is excluded by !**/*.snap
  • app/containers/RoomItem/__snapshots__/RoomItem.test.tsx.snap is excluded by !**/*.snap
  • app/containers/UnreadBadge/__snapshots__/UnreadBadge.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (3)
  • .maestro/tests/room/mark-as-unread.yaml (1 hunks)
  • .maestro/tests/room/unread-badge.yaml (1 hunks)
  • app/containers/UnreadBadge/index.tsx (2 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Rohit3523 Rohit3523 temporarily deployed to approve_e2e_testing October 31, 2025 20:45 — with GitHub Actions Inactive
@Rohit3523 Rohit3523 marked this pull request as ready for review October 31, 2025 20:54
@Rohit3523 Rohit3523 marked this pull request as draft October 31, 2025 20:54
@Rohit3523 Rohit3523 temporarily deployed to approve_e2e_testing October 31, 2025 21:04 — with GitHub Actions Inactive
@Rohit3523 Rohit3523 had a problem deploying to experimental_android_build October 31, 2025 21:07 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to experimental_ios_build October 31, 2025 21:07 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to official_android_build October 31, 2025 21:07 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to experimental_ios_build November 1, 2025 09:23 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to official_android_build November 1, 2025 09:23 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to experimental_android_build November 1, 2025 09:23 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to official_android_build November 1, 2025 11:03 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to experimental_ios_build November 1, 2025 11:03 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to experimental_android_build November 1, 2025 11:03 — with GitHub Actions Error
@Rohit3523 Rohit3523 marked this pull request as ready for review November 5, 2025 15:13
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
app/containers/UnreadBadge/index.tsx (1)

111-111: Parameter alignment with function signature.

This line passes the formatted text string to getTestId, which expects a numeric unread parameter per its signature. This mismatch is the root cause of the issues identified in the getTestId function review.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 801c42a and f181c65.

⛔ Files ignored due to path filters (3)
  • app/containers/Header/components/HeaderButton/__snapshots__/HeaderButtons.test.tsx.snap is excluded by !**/*.snap
  • app/containers/RoomItem/__snapshots__/RoomItem.test.tsx.snap is excluded by !**/*.snap
  • app/containers/UnreadBadge/__snapshots__/UnreadBadge.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (3)
  • .maestro/tests/room/mark-as-unread.yaml (1 hunks)
  • .maestro/tests/room/unread-badge.yaml (1 hunks)
  • app/containers/UnreadBadge/index.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: format
🔇 Additional comments (3)
app/containers/UnreadBadge/index.tsx (1)

119-120: LGTM: testID application is correct.

The testID is properly applied to the View component using standard React Native conventions.

.maestro/tests/room/mark-as-unread.yaml (1)

54-59: LGTM: Element-based wait improves test reliability.

Switching from text-based regex matching to element ID targeting significantly reduces flakiness. The childOf constraint properly scopes the wait to the specific room list item, making the assertion more precise.

.maestro/tests/room/unread-badge.yaml (1)

18-110: Test logic is sound, but color verification is missing.

The test comprehensively covers the four scenarios described in the PR objectives and properly verifies badge counts and types (unread vs. mention). The test structure is well-organized with clear comments for each scenario.

However, the PR description states the test verifies "badge color and count behavior," but there are no color assertions in the test. Maestro's extendedWaitUntil with visible only confirms element presence, not visual properties like background color.

Consider whether color verification is necessary. If it is, you may need to:

  1. Use Maestro's assertion capabilities to check styling/color properties (if supported), or
  2. Update the PR description to accurately reflect that only count and badge type are verified, not colors.

Comment on lines +1 to +16
appId: chat.rocket.reactnative
name: Unread badge
onFlowStart:
- runFlow: '../../helpers/setup.yaml'
tags:
- test-13

---
- evalScript: ${output.user = output.utils.createUser()}
- evalScript: ${output.otherUser = output.utils.createUser()}

- runFlow:
file: '../../helpers/login-with-deeplink.yaml'
env:
USERNAME: ${output.user.username}
PASSWORD: ${output.user.password}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add cleanup step for created users.

The test creates users but doesn't clean them up. The mark-as-unread.yaml test includes an onFlowComplete hook to delete created users, which should be added here as well.

Add this after line 4:

 onFlowStart:
   - runFlow: '../../helpers/setup.yaml'
+onFlowComplete:
+  - evalScript: ${output.utils.deleteCreatedUsers()}
 tags:
   - test-13
🤖 Prompt for AI Agents
In .maestro/tests/room/unread-badge.yaml around lines 1 to 16, add an
onFlowComplete hook immediately after line 4 that runs the same cleanup flow
used in mark-as-unread.yaml to delete the created users; specifically invoke the
helper cleanup flow and pass the created users (output.user and
output.otherUser) via env (usernames/passwords or identifiers) so both users are
removed when the test finishes.

Comment on lines +42 to +53
function getTestId(userMentions: number | undefined, groupMentions: number | undefined, unread: number | undefined) {
if (userMentions) {
return `mention-badge-${unread}`;
}
if (groupMentions) {
return `group-mention-badge-${unread}`;
}
if (unread) {
return `unread-badge-${unread}`;
}
return '';
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Clarify parameter naming and handle edge cases.

The third parameter is named unread but receives the text variable (line 111), which is a formatted string that can be "+99", "+999", or a number string. This creates several issues:

  1. Misleading parameter name: The parameter should be named text or count to match what it actually receives.
  2. Unexpected testID formats: When large counts are formatted, testIDs become unread-badge-+99 or mention-badge-+999, which may complicate test maintenance.
  3. Missing validation: If text is undefined or empty, testIDs like mention-badge-undefined will be generated.

Consider this refactor for clarity and robustness:

-function getTestId(userMentions: number | undefined, groupMentions: number | undefined, unread: number | undefined) {
+function getTestId(userMentions: number | undefined, groupMentions: number | undefined, count: string) {
+	if (!count) {
+		return '';
+	}
 	if (userMentions) {
-		return `mention-badge-${unread}`;
+		return `mention-badge-${count}`;
 	}
 	if (groupMentions) {
-		return `group-mention-badge-${unread}`;
+		return `group-mention-badge-${count}`;
 	}
-	if (unread) {
-		return `unread-badge-${unread}`;
-	}
-	return '';
+	return `unread-badge-${count}`;
 }
🤖 Prompt for AI Agents
In app/containers/UnreadBadge/index.tsx around lines 42 to 53, the third
parameter is misleadingly named `unread` while callers pass the formatted `text`
(e.g. "+99"), which can produce invalid or brittle testIDs and even "undefined"
values; rename the parameter to `text` (or `displayText`), validate/normalize it
before building IDs (fallback to an empty string or "0" when undefined), strip
any leading "+" or other formatting characters used for display, and prefer
using the raw numeric count (if available) or a consistent token like "overflow"
for large counts so produced testIDs are deterministic and safe (e.g.
`mention-badge-99` or `unread-badge-overflow`) instead of `+99` or `undefined`.

@diegolmello diegolmello changed the title chore: added unread badge e2e test & improved flakiness test: fix unread badge test Nov 5, 2025
@Rohit3523 Rohit3523 temporarily deployed to approve_e2e_testing November 7, 2025 15:44 — with GitHub Actions Inactive
@Rohit3523 Rohit3523 had a problem deploying to official_android_build November 7, 2025 15:48 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to experimental_android_build November 7, 2025 15:48 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to experimental_ios_build November 7, 2025 15:48 — with GitHub Actions Error
@diegolmello diegolmello merged commit f3e1497 into develop Dec 3, 2025
5 of 7 checks passed
@diegolmello diegolmello deleted the unread-badge-test branch December 3, 2025 20:08
@diegolmello diegolmello requested a deployment to experimental_android_build December 3, 2025 20:11 — with GitHub Actions Waiting
@diegolmello diegolmello requested a deployment to official_android_build December 3, 2025 20:11 — with GitHub Actions Waiting
@diegolmello diegolmello requested a deployment to experimental_ios_build December 3, 2025 20:11 — with GitHub Actions Waiting
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.

3 participants