-
Notifications
You must be signed in to change notification settings - Fork 136
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
Add unit test for sitepicker loading state #12614
Add unit test for sitepicker loading state #12614
Conversation
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
ab56206
to
a0a673d
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## trunk #12614 +/- ##
=========================================
Coverage 40.61% 40.62%
- Complexity 5680 5682 +2
=========================================
Files 1229 1229
Lines 69123 69123
Branches 9573 9573
=========================================
+ Hits 28074 28080 +6
+ Misses 38466 38462 -4
+ Partials 2583 2581 -2 ☔ 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.
Thanks for adding the test @irfano! LGTM. I've just shared my thoughts on removing unnecessary details from the test and it's definitely non-blocking for the merge.
val states = viewModel.sitePickerViewStateData.liveData.captureValues() | ||
|
||
// Make primary button visible after initialization. This may happen in low memory condition. | ||
viewModel.sitePickerViewState = viewModel.sitePickerViewState.copy(isPrimaryBtnVisible = true) |
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.
💡 Just sharing my thoughts here — This test doesn’t need to verify whether the primary button is visible after initialization or in low memory scenarios. The key concern is ensuring that the primary button is set to false when the screen is loading.
We can remove this line from the test and revert the changes in SitePickerViewModel
to make the test simpler and easier to understand without needing to dive into those details.
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 agree the test would be simper, but my goal was to add a unit test for this issue. If we remove these lines, we won't be able to catch the crash that occurs in low memory case. Have you already considered this?
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.
Thanks for elaborating. I'm sorry I didn't quite understand it. How does viewModel.sitePickerViewState = viewModel.sitePickerViewState.copy(isPrimaryBtnVisible = true)
helps us in catching the crash in case of low memory case?
AFAIU, The crash occurred because users could click the "Continue" button while the screen was still loading, which allowed them to proceed before the sites were fully fetched, causing a null site to be passed. To fix this, we hide the "Continue" button while the screen is loading, preventing users from interacting with it prematurely. On some devices, particularly in low-memory conditions, the button may appear before all sites are fetched, but the core issue is that we allowed the button to be clicked before data was ready, not directly related to low memory.
For unit testing this logic, the main focus is to ensure that the primary button is hidden while the screen is loading, which is the key aspect to test. Right?
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 may not have explained the issue well in the PR that I fixed it.
Normal Scenario
The "Continue" button is already hidden during the loading state. Once sites are loaded, if you put the app in the background and reopen it, you can still see the loaded sites.
Low Memory Scenario
The "Continue" button is hidden during the loading state when you first open the site picker. However, If you put the app in the background and reopen it, the screen goes into the loading state with isPrimaryBtnVisible = true
value.
I suggest you to verify it with these steps:
- Remove the line that fixes the issue
Line 148 in e5d1775
isPrimaryBtnVisible = false - Run
given initiated, when isPrimaryBtnVisible and loading state, then primary button view is not displayed
test. - It should fail.
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.
but the core issue is that we allowed the button to be clicked before data was ready, not directly related to low memory.
This is the part I couldn't make clear. The core issue is actually directly related to the low memory scenario. It works as expected in the normal case.
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.
Ah. I understand it now. Thanks for explaining it in detail. It makes sense now 👍
Closes: #
Description
This adds a unit test for the issue fixed in #12603.
SitePickerViewModel
could be initialized but with its previous view state. This might causeisPrimaryBtnVisible=true
after initialization. To mock this behavior, I set it totrue
manually after initialization.StandardTestDispatcher()
for this test.Steps to reproduce
Run
given initiated, when isPrimaryBtnVisible and loading state, then primary button view is not displayed
test.The tests that have been performed
given initiated, when isPrimaryBtnVisible and loading state, then primary button view is not displayed
RELEASE-NOTES.txt
if necessary. Use the "[Internal]" label for non-user-facing changes.Reviewer (or Author, in the case of optional code reviews):
Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement: