Skip to content

Conversation

@atorresveiga
Copy link
Contributor

@atorresveiga atorresveiga commented Dec 11, 2024

Part of: #12998

Description

This PR connects shipping rates with the mock data returned from the GetShippingRates use case. Additionally, it adds logic for changing the sort order and refreshing the shipping rates.

Changes included here:

  • Display shipping rates from the GetShippingRates use case.
  • Sort shipping rates using the sort order selected
  • Refresh shipping rates (used in the error screen)
  • Added a loading state to indicate that the app is working while we are fetching shipping rates

Testing information

TC1

  • Open the app
  • Navigate to orders
  • Tap on an order eligible for creating a shipping label
  • Tap on create a shipping label
  • Check that the shipping rates are displayed
  • Change the shipping sort order
  • Check that shipping rates are refreshed

TC2
First apply this patch to force the get shipping labels use case to fail

Patch
Index: WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/GetShippingRates.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/GetShippingRates.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/GetShippingRates.kt
--- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/GetShippingRates.kt	(revision 063540b77d705976f703f59726e538865681c073)
+++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/GetShippingRates.kt	(date 1733926052842)
@@ -5,6 +5,7 @@
 import kotlinx.coroutines.delay
 import javax.inject.Inject
 import kotlin.random.Random
+
 @Suppress("MagicNumber")
 class GetShippingRates @Inject constructor() {
     private val cheapestComparator = Comparator<ShippingRateUI> { r1, r2 ->
@@ -62,13 +63,14 @@
             )
         }
 
-        return Result.success(
+        /*return Result.success(
             carriers.associateWith {
                 generateRates(
                     it.name,
                     Random(0).nextInt(from = 3, until = 10)
                 ).sortedWith(comparator)
             }
-        )
+        )*/
+        return Result.failure(Exception("Random exception"))
     }
 }

  • Open the app
  • Navigate to orders
  • Tap on an order eligible for creating a shipping label
  • Tap on create a shipping label
  • Check that an error is displayed
  • Tap on refresh
  • Check that shipping labels refresh (displaying the error again)

The tests that have been performed

  • Testing that the UI works as expected

Images/gif

Screen_recording_20241211_114452.mp4
  • 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.

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:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on big (tablet) and small (phone) in case of UI changes, and no regressions are added.

@dangermattic
Copy link
Collaborator

dangermattic commented Dec 11, 2024

1 Warning
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Dec 11, 2024

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App Name WooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commit023c863
Direct Downloadwoocommerce-wear-prototype-build-pr13105-023c863.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Dec 11, 2024

📲 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
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commit023c863
Direct Downloadwoocommerce-prototype-build-pr13105-023c863.apk

import kotlinx.coroutines.delay
import javax.inject.Inject
import kotlin.random.Random
@Suppress("MagicNumber")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This use case will be updated in the next PR to fetch real data, for now, I'm skipping unit testing it

)

data class ShippingRate(
data class ShippingRateUI(
Copy link
Contributor Author

@atorresveiga atorresveiga Dec 11, 2024

Choose a reason for hiding this comment

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

Renaming ShippingRate -> ShippingRateUI. The new model will be added in the next PR

}

@Composable
private fun WooShippingShippingRatesSection(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This new composable will be in charge of representing the shipping rate status

@codecov-commenter
Copy link

codecov-commenter commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 49.64029% with 70 lines in your changes missing coverage. Please review.

Project coverage is 40.43%. Comparing base (31ff1ad) to head (023c863).
Report is 125 commits behind head on trunk.

Files with missing lines Patch % Lines
...id/ui/orders/wooshippinglabels/GetShippingRates.kt 0.00% 38 Missing ⚠️
...i/orders/wooshippinglabels/ShippingRatesSection.kt 0.00% 27 Missing ⚠️
...hippinglabels/WooShippingLabelCreationViewModel.kt 93.24% 1 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              trunk   #13105    +/-   ##
==========================================
  Coverage     40.42%   40.43%            
- Complexity     6200     6203     +3     
==========================================
  Files          1294     1295     +1     
  Lines         74534    74637   +103     
  Branches      10197    10205     +8     
==========================================
+ Hits          30131    30177    +46     
- Misses        41790    41843    +53     
- Partials       2613     2617     +4     

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

originCountry = "US"
)

private val mockSelectedPackage = PackageDAO(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shipping rates need a package to be selected

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll adjust this through #13111.

@atorresveiga atorresveiga added type: task An internally driven task. feature: shipping labels Related to creating, ordering, or printing shipping labels. labels Dec 11, 2024
@atorresveiga atorresveiga added this to the 21.3 milestone Dec 11, 2024
@atorresveiga atorresveiga marked this pull request as ready for review December 11, 2024 14:46
@atorresveiga atorresveiga changed the title Issue/connecting shipping rates Connecting shipping rates Dec 11, 2024
@atorresveiga atorresveiga mentioned this pull request Dec 11, 2024
5 tasks
@ThomazFB ThomazFB self-assigned this Dec 11, 2024
Copy link
Contributor

@ThomazFB ThomazFB left a comment

Choose a reason for hiding this comment

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

Looks good, @atorresveiga! I focused on checking the UI and overall wiring between ViewModel and use case. Looks good and great work with the unit test coverage.

@atorresveiga atorresveiga merged commit bfc0203 into trunk Dec 12, 2024
18 checks passed
@atorresveiga atorresveiga deleted the issue/connecting-shipping-rates branch December 12, 2024 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: shipping labels Related to creating, ordering, or printing shipping labels. type: task An internally driven task. unit-tests-exemption

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants