Skip to content

[Dynamic Dashboard] Unit tests for the coupons card #11618

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

Merged
merged 2 commits into from
May 29, 2024

Conversation

hichamboushaba
Copy link
Member

Part of: #11613

Description

This PR adds unit tests for the coupons card ViewModel.

Testing instructions

Just green CI.

  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

Otherwise the dates don't equal, and we get issues when they are used as Map keys
@hichamboushaba hichamboushaba added category: unit tests Related to unit testing. feature: dashboard Related to home screen project labels May 29, 2024
@hichamboushaba hichamboushaba added this to the 18.9 milestone May 29, 2024
@@ -77,6 +77,7 @@ private fun Calendar.setToDayFirstSecond() {
}

private fun Calendar.setToDayLastSecond() {
clear(Calendar.MILLISECOND)
Copy link
Member Author

Choose a reason for hiding this comment

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

We use the StatsRange as key for the cache in the ViewModel, the unit test revealed that the cache was not used sometimes, and the cause was a difference in the value of the millisecond between the end dates, and this was the cause, we weren't setting the millisecond value, it was inherited from the device's date.

@dangermattic
Copy link
Collaborator

1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

Comment on lines +72 to +76
val prefFlow = MutableStateFlow(SelectionType.TODAY.name)

on { getActiveCouponsTab() } doAnswer { prefFlow.value }
on { setActiveCouponsTab(any()) } doAnswer { prefFlow.value = it.arguments[0] as String }
on { observePrefs() } doAnswer { prefFlow.map { Unit } }
Copy link
Member Author

Choose a reason for hiding this comment

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

I tried following an approach more fake than mock here, and I think it allowed for better testing below that tests the behavior instead of relying a lot on verify calls.

Comment on lines +91 to +93
val rangeFlow = MutableStateFlow<StatsTimeRange?>(null)
on { dateRange } doReturn rangeFlow
onBlocking { updateDateRange(any()) } doAnswer { rangeFlow.value = it.arguments[0] as StatsTimeRange }
Copy link
Member Author

Choose a reason for hiding this comment

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

Same as above.

@wpmobilebot
Copy link
Collaborator

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
FlavorJalapeno
Build TypeDebug
Commita766c69
Direct Downloadwoocommerce-prototype-build-pr11618-a766c69.apk

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 40.25%. Comparing base (7ac53ef) to head (a766c69).
Report is 16 commits behind head on trunk.

Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #11618      +/-   ##
============================================
+ Coverage     40.10%   40.25%   +0.14%     
- Complexity     5206     5219      +13     
============================================
  Files          1090     1090              
  Lines         63698    63699       +1     
  Branches       8749     8749              
============================================
+ Hits          25549    25642      +93     
+ Misses        35842    35735     -107     
- Partials       2307     2322      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hichamboushaba hichamboushaba marked this pull request as ready for review May 29, 2024 17:20
Copy link
Contributor

@0nko 0nko left a comment

Choose a reason for hiding this comment

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

:shipit:

@0nko 0nko merged commit 598bff3 into trunk May 29, 2024
17 checks passed
@0nko 0nko deleted the issue/11613-dynamic-dashboard-coupons-unit-tests branch May 29, 2024 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: unit tests Related to unit testing. feature: dashboard Related to home screen project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants