-
Notifications
You must be signed in to change notification settings - Fork 132
[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
Conversation
Otherwise the dates don't equal, and we get issues when they are used as Map keys
@@ -77,6 +77,7 @@ private fun Calendar.setToDayFirstSecond() { | |||
} | |||
|
|||
private fun Calendar.setToDayLastSecond() { | |||
clear(Calendar.MILLISECOND) |
There was a problem hiding this comment.
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.
Generated by 🚫 Danger |
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 } } |
There was a problem hiding this comment.
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.
val rangeFlow = MutableStateFlow<StatsTimeRange?>(null) | ||
on { dateRange } doReturn rangeFlow | ||
onBlocking { updateDateRange(any()) } doAnswer { rangeFlow.value = it.arguments[0] as StatsTimeRange } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of: #11613
Description
This PR adds unit tests for the coupons card ViewModel.
Testing instructions
Just green CI.
RELEASE-NOTES.txt
if necessary. Use the "[Internal]" label for non-user-facing changes.