Skip to content

Tests/sdk 1556/pt unit tests #811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

Anush-Shand
Copy link
Contributor

@Anush-Shand Anush-Shand commented May 28, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved accuracy of notification timestamps and timer end calculations by explicitly using the current system time.
  • Tests
    • Updated tests to align with changes in timestamp and timer logic, and adjusted targeted Android SDK versions for timer template rendering scenarios.

Copy link
Contributor

coderabbitai bot commented May 28, 2025

Walkthrough

The changes update utility methods to accept the current timestamp as an explicit argument instead of obtaining it internally. Corresponding method calls in notification rendering and content view classes are updated to pass the current system time. Related unit tests are adjusted to match the new method signatures and target updated Android SDK versions.

Changes

File(s) Change Summary
.../PushTemplateReceiver.java
.../content/ContentView.kt
Updated calls to Utils.getTimeStamp to pass context and current system time as arguments.
.../TemplateRenderer.kt Updated call to Utils.getTimerEnd to pass extras and current system time as arguments.
.../Utils.java Modified getTimeStamp and getTimerEnd to accept current time as a parameter; updated method signatures accordingly.
.../TemplateRendererTest.kt Updated tests to use new method signatures, adjusted SDK versions, and renamed a test for clarity.

Sequence Diagram(s)

sequenceDiagram
    participant Caller (Renderer/ContentView/Receiver)
    participant Utils

    Caller->>Utils: getTimeStamp(context, System.currentTimeMillis())
    Utils-->>Caller: Returns formatted timestamp string

    Caller->>Utils: getTimerEnd(extras, System.currentTimeMillis())
    Utils-->>Caller: Returns timer end value (int)
Loading

Suggested labels

ptv2.0.0

Suggested reviewers

  • CTLalit

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 07dd385 and 4c249f9.

📒 Files selected for processing (5)
  • clevertap-pushtemplates/src/main/java/com/clevertap/android/pushtemplates/PushTemplateReceiver.java (1 hunks)
  • clevertap-pushtemplates/src/main/java/com/clevertap/android/pushtemplates/TemplateRenderer.kt (1 hunks)
  • clevertap-pushtemplates/src/main/java/com/clevertap/android/pushtemplates/Utils.java (3 hunks)
  • clevertap-pushtemplates/src/main/java/com/clevertap/android/pushtemplates/content/ContentView.kt (1 hunks)
  • clevertap-pushtemplates/src/test/java/com/clevertap/android/pushtemplates/TemplateRendererTest.kt (2 hunks)
🔇 Additional comments (8)
clevertap-pushtemplates/src/main/java/com/clevertap/android/pushtemplates/PushTemplateReceiver.java (1)

716-716: LGTM: Improved testability by making time dependency explicit.

The change to pass System.currentTimeMillis() explicitly to Utils.getTimeStamp() improves testability by removing the hidden time dependency. This allows tests to control the timestamp value when needed.

clevertap-pushtemplates/src/main/java/com/clevertap/android/pushtemplates/content/ContentView.kt (1)

26-26: LGTM: Consistent implementation of explicit timestamp pattern.

This change correctly follows the same pattern as the Java counterpart, making the time dependency explicit by passing System.currentTimeMillis() to Utils.getTimeStamp(). The consistency across both Java and Kotlin implementations demonstrates good refactoring execution.

clevertap-pushtemplates/src/main/java/com/clevertap/android/pushtemplates/TemplateRenderer.kt (1)

411-411: LGTM: Timer functionality benefits from explicit time control.

The change to pass System.currentTimeMillis() explicitly to Utils.getTimerEnd() is particularly beneficial for timer-related functionality, as it enables precise testing of time-dependent behavior. This follows the consistent pattern established in the other utility method updates.

clevertap-pushtemplates/src/test/java/com/clevertap/android/pushtemplates/TemplateRendererTest.kt (3)

574-574: LGTM: Correct SDK targeting for timer functionality.

Changing the SDK version to Build.VERSION_CODES.O is appropriate since timer notifications are only supported on Android Oreo and above, as mentioned in the production code logic.


581-581: LGTM: Mock updated to match new method signature.

The mock correctly includes the additional any() parameter to match the updated Utils.getTimerEnd(Bundle, long) method signature. This ensures the test continues to work with the refactored utility method.


628-629: LGTM: Test name and SDK version corrected for timer functionality.

The changes correctly update both the test name from "below_nougat" to "below_oreo" and the SDK version from VERSION_CODES.M to VERSION_CODES.N. This aligns with the fact that timer functionality requires Android Oreo (API level 26) or above, so testing "below Oreo" is the appropriate boundary.

clevertap-pushtemplates/src/main/java/com/clevertap/android/pushtemplates/Utils.java (2)

269-272:

✅ Verification successful

API breaking change - verify all callers are updated.

The method signature change from getTimeStamp(Context context) to getTimeStamp(Context context, long timeMillis) is a breaking change. The implementation correctly uses the provided timestamp parameter instead of obtaining the current time internally, which improves testability.


🏁 Script executed:

#!/bin/bash
# Description: Verify all callers of getTimeStamp have been updated to match the new signature
# Expected: All calls should pass two parameters (context and timeMillis)

ast-grep --pattern 'getTimeStamp($_, $_)'

Length of output: 43


🏁 Script executed:

#!/bin/bash
# List all occurrences of getTimeStamp calls to verify updated signatures
rg "getTimeStamp\(" -n .

Length of output: 775


getTimeStamp callers verified and up to date

All usages of Utils.getTimeStamp have been updated to pass both context and timeMillis:

• UtilsTest.kt:786
• ContentView.kt:26
• PushTemplateReceiver.java:716

No missing call sites found.


481-497:

✅ Verification successful

API breaking change with correct implementation.

The method signature change from getTimerEnd(Bundle extras) to getTimerEnd(Bundle extras, long currentTs) is a breaking change. The implementation correctly uses the provided currentTs parameter for the timer calculation instead of calling System.currentTimeMillis() internally.


🏁 Script executed:

#!/bin/bash
# Description: Verify all callers of getTimerEnd have been updated to match the new signature
# Expected: All calls should pass two parameters (extras and currentTs)

ast-grep --pattern 'getTimerEnd($_, $_)'

Length of output: 42


To ensure we catch all call sites (including any tests or dynamically referenced usages), let’s search the entire repo for getTimerEnd( and review each occurrence:


🏁 Script executed:

#!/bin/bash
# Search for every usage of getTimerEnd to verify correct signature updates
rg "getTimerEnd\(" -n .

Length of output: 2104


API Breaking Change Confirmed
The signature of Utils.getTimerEnd has been updated from

getTimerEnd(Bundle extras)

to

getTimerEnd(Bundle extras, long currentTs)

All internal call sites—including tests and TemplateRenderer.kt—have been updated to pass the second parameter.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Anush-Shand
Copy link
Contributor Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented May 28, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Anush-Shand Anush-Shand requested a review from vasct May 28, 2025 10:03
@Anush-Shand
Copy link
Contributor Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jun 4, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Anush-Shand Anush-Shand merged commit f7c09fb into task/SDK-1556/replace_multi_layouts_with_dimens Jun 5, 2025
4 checks passed
Anush-Shand added a commit that referenced this pull request Jun 5, 2025
* task(SDK-1556) - Deletes all v19 layouts since minSDKVersion is 21

* task(SDK-1556) - Deletes files in v22 and v23 that are same as v21

* task(SDK-1556) - Deletes files in v22 that are same as v21

* task(SDK-1556) - Deletes files in v31 that are same as default folder

* task(SDK-1556) - Fixes manual_carousel in default folder and deletes redundant file in v31

* task(SDK-4057) - Makes v21 layouts as the default layouts
Also removes redundant attributes like marginLeft which were needed for v17

* task(SDK-4057) - Replaces redundant layout files with different dimensions

* task(SDK-4057) - Replaces for five cta, redundant layout files with different dimensions

* task(SDK-4057) - Introduces pt_render_terminal to render the final notification

- Some refactoring
- Introduces key

* task(SDK-4536) - Fixes negative value for timer template

- Changes support for timer template to Android O and above
- Updates docs

* task(SDK-4465) - Adds prefix pt_ to res files of push-templates to avoid conflicts

- Also removes redundant attributes

* task(SDK-4465)

- Changes marginLeft to marginStart
- Changes marginRight to marginEnd

* Task/sdk 4595/replicate standard and basic (#788)

* task(SDK-4595) - Replicate Standard Android Notification with Basic Push Template

- Changes in dimens
- Removes redundant styles.xml for sw-400

* task(SDK-4595) - Fixes color

* task(SDK-1556) - Makes timer margin and padding same as other templates

* fix(SDK-1556) - fixes zero bezel on API 31 and above

* Task/sdk 4048/ctas pt (#786)

* POC for FG service based timer notif

* task(SDK-4048) - Adds CTAs in the remote view for push templates below API level 31

* task(SDK-4048) - Reverts rating view changes

* Rename .java to .kt

* task(SDK-4048) - Adds action buttons to remote view

- For API 31 and above StyleWithActionButtons is responsible
- For API 30 and below ActionButtonsContentView is responsible

* task(SDK-4048) - Resolves comments

- Makes classes internal
- Removes redundant colour attribute
- Adds pt_ prefix

* task(SDK-4048) - Resolves comments

- Removes return@forEach

* task(SDK-4048) - Resolves comments

- Adds extension function to increase readability

* task(SDK-4048) - Resolves comments

- Removes public access modifier

* task(SDK-4048) - Testing

- Adds UTs for TemplateRenderer

* task(SDK-4537) - Removes extra space from manual_carousel.xml (#794)

- Removes padding from shape and adds margin

* task(SDK-4048) - Removes dependency from core-sdk

* task(SDK-4040) - Adds CTA for manual carousel

* task(SDK-4040) - Adds CTA for auto carousel

* task(SDK-4048) - Compresses forward and backward arrows for manual carousel

* task(SDK-4048) - Separates PendingIntent from ActionButton.kt

* task(SDK-4048) - Uses composition instead of inheritance for action buttons

* task(SDK-4048) - Fixes image in rating template

* task(SDK-4048) - Fixes string resource name

* task(SDK-4048) - Fixes rating template padding

* task(SDK-4048) - Minor PR comments

* task(SDK-4655) - Dark mode for push templates (#795)

* task(SDK-4655) - Dark mode for push templates

- Adds dark mode support for push templates
- Removes bg as mandatory key
- Parses colour based on dark mode of phone

* task(SDK-4655) - Addresses few todos

* task(SDK-4655) - Makes product display action colour optional

* task(SDK-4655) - Addresses todos

* task(SDK-4655) -Fixes typo and deletes redundant files

* task(SDK-4655) - Color for CTA in clicked state

* task(SDK-4655) - Fixes default colour for title

* task(SDK-4655) - Fixes default colour for small icon

* task(SDK-4655) - Adds color for rating confirm button for light and dark mode

* task(SDK-4655) - Fixes default colour for product template buttons

* task(SDK-4655) - Extracts dimens

* task(SDK-4655) - Improves code reuse by refactoring setting of colours

* task(SDK-4655) - Improves code reuse by refactoring dark mode colors

* task(SDK-4834) - Makes image in notification configurable for scaletype (#808)

* task(SDK-4834) - Makes image in notification configurable for scaletype

* task(SDK-4834) - Improves code reuse by refactoring dark mode colors

* task(SDK-4834) - Minor PR comments

* task(SDK-1556) - Fixes tests

* Tests/sdk 1556/pt unit tests (#811)

* task(SDK-1556) - Adds test for getFlipInterval

* task(SDK-1556) - Adds test for getColour

* task(SDK-1556) - Adds test for createColourMap

* task(SDK-1556) - Adds test for getFallback, getTimerEnd, getApplicationName, getTimeStamp, loadImageRidIntoRemoteView

* task(SDK-1556) - Adds test for getImageListFromExtras, getCTAListFromExtras, getDeepLinkListFromExtras, getBigTextFromExtras, getSmallTextFromExtras, getPriceFromExtras

* task(SDK-1556) - Adds test for convertRatingBundleObjectToHashMap, getEventNameFromExtras

* task(SDK-1556) - Adds test for getEventPropertiesFromExtras

* task(SDK-1556) - Adds test

* task(SDK-1556) - Adds test for raiseNotificationClicked, getActionKeys

* task(SDK-1556) - Adds test for raiseNotificationClicked

* task(SDK-1556) - Adds test for deleteImageFromStorage

* task(SDK-1556) - Adds test for isNotificationChannelEnabled

* task(SDK-1556) - Adds test

* task(SDK-1556) - Adds test for getTimerThreshold

* task(SDK-1556) - Adds test for fromJson

* task(SDK-1556) - Adds test for loadImageUrLIntoRemoteView

* tests(SDK-1556) - Improves timer template test

* tests(SDK-1556) - Improves timer template test

* task(SDK-1556) - Improves tests and Utils function

* task(SDK-1556) - Moves mockkStatic inside a code-block

* task(SDK-1556) - Minor improvements around dot sep (#815)

* task(SDK-1556) - Minor improvements around dot sep

* task(SDK-1556) - Minor colour improvement

* task(SDK-1556) - Minor improvements around message summary for timer template

* task(SDK-1556) - Coderabbit pr comments

* task(SDK-1556) - Fixes flaky test

* docs(SDK-1556) - CHANGELOG and version upgrade for PT (#814)

* docs(SDK-1556) - CHANGELOG and version upgrade for PT

* task(SDK-1556) - Improves docs and updates dates

* task(SDK-1556) - copyTemplates

* docs(SDK-1556) - Improves changelog
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