Blaze: Fix a crash when no ad suggestions
This PR fixes a crash when there are no ad suggestions in the ad-edit screen.
To test:
Online
- Start a campaign creation
- Tap on the Edit ad button
- Notice that 3 suggestions are loaded
- Edit something and tap save
- Notice the ad details are updated
- Tap on the Edit ad button again
- Notice the correct details are loaded
- Tap on the arrows and notice the other 3 suggestions are available
Offline
- Turn on the flight mode
- Start a campaign creation
- Tap on the Edit ad button
- Notice the AI suggestions row is not displayed
- Add suggestion details and save
- Notice the details are updated
- Tap on the Edit ad button again
- Notice the correct details are loaded
📲 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 | |
| Flavor | Jalapeno | |
| Build Type | Debug | |
| Commit | 752fe032dc2c3067b4395d4ae40247fce122dc77 | |
| Direct Download | woocommerce-prototype-build-pr10853-752fe03.apk |
Hey @0nko I think I fixed this already as part of this PR:https://github.com/woocommerce/woocommerce-android/pull/10820
Specifically in this commit: https://github.com/woocommerce/woocommerce-android/pull/10820/commits/c726565a6458a988c0eaab9f7a41191c23d66feb, where AI suggestions are passed as navArgs from CampaignPreviewFragment to EditAdFragment. The reason for this where to avoid doing unnecessary requests.
So, I'm unsure this is needed. I tested following the steps shared in the description and the app doesn't crash with this PR's code https://github.com/woocommerce/woocommerce-android/pull/10820
Let me know if I missed something and I can address it :)
@JorgeMucientes did you test the offline case, because I'm not sure your changes will fix this case though, as the passed suggestions will still be empty when we get an error. But TBH, I didn't review the whole code yet, just wondering.
Codecov Report
Attention: Patch coverage is 0% with 15 lines in your changes are missing coverage. Please review.
Project coverage is 40.89%. Comparing base (
bd1eab8) to head (c79edd3).
:exclamation: Current head c79edd3 differs from pull request most recent head 752fe03. Consider uploading reports for the commit 752fe03 to get more accurate results
| Files | Patch % | Lines |
|---|---|---|
| ...reation/ad/BlazeCampaignCreationEditAdViewModel.kt | 0.00% | 15 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## trunk #10853 +/- ##
============================================
- Coverage 41.44% 40.89% -0.56%
+ Complexity 5114 5017 -97
============================================
Files 1036 1026 -10
Lines 59885 59211 -674
Branches 8051 7913 -138
============================================
- Hits 24821 24215 -606
- Misses 32848 32850 +2
+ Partials 2216 2146 -70
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Hey @hichamboushaba resuming this discussion :)
did you test the offline case, because I'm not sure your changes will fix this case though, as the passed suggestions will still be empty when we get an error. But TBH, I didn't review the whole code yet, just wondering.
Yes, the changes added there fix the crash. It's not really about passing the suggestions from the preview screen to the edit ad screen; that fixed the problem. It was a small refactor done on how the suggestion list is processed that fixed it.
The following screencast was recorded from this PR: #10926
https://github.com/woocommerce/woocommerce-android/assets/2663464/62e2894d-ff08-4101-ba36-583d5d73fd9f
@0nko I think we can discard the changes added to BlazeCampaignCreationEditAdViewModel and keep only the changes applied to the screen UI code to hide the suggestions row if the ai suggestion list is empty.
| 1 Warning | |
|---|---|
| :warning: | This PR is assigned to the milestone 17.6. This milestone is due in less than 2 days. Please make sure to get it merged by then or assign it to a milestone with a later deadline. |
Generated by :no_entry_sign: Danger
@JorgeMucientes I've updated the code, ready for a review.
The code looks great, and everything works as expected! Thanks @0nko 👍🏼