From d31d4247c76d354aa5c98ee4bd4b71f52207c280 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 27 Nov 2024 20:23:54 -0300 Subject: [PATCH 01/41] Update WooShippingLabelPackageRepository models --- .../datasource/WooShippingLabelPackageRepository.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepository.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepository.kt index 9f236b7ebd1..de63b1ef0f3 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepository.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepository.kt @@ -24,7 +24,7 @@ class WooShippingLabelPackageRepository @Inject constructor( data class StorePackages( val savedPackages: List, - val carrierPackages: List + val carrierPackages: List ) data class Package( @@ -33,7 +33,11 @@ class WooShippingLabelPackageRepository @Inject constructor( val dimensions: String ) - data class CarrierGroup( + data class Carrier( + val packageGroup: List + ) + + data class CarrierPackageGroup( val description: String, val packages: List ) From b6fc1978776b411d6a69e622c6e4f62361ca3959 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 27 Nov 2024 20:26:43 -0300 Subject: [PATCH 02/41] Update Mapper to account for Carrier DAO --- .../datasource/WooShippingLabelPackageMapper.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt index 0ac9296fe11..71c5d4043fa 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt @@ -1,6 +1,7 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.WooShippingLabelPackageRepository.CarrierGroup +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.WooShippingLabelPackageRepository.Carrier +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.WooShippingLabelPackageRepository.CarrierPackageGroup import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.WooShippingLabelPackageRepository.Package import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.WooShippingLabelPackageRepository.StorePackages import com.woocommerce.android.ui.orders.wooshippinglabels.packages.networking.CarrierPackageGroupDTO @@ -29,21 +30,26 @@ class WooShippingLabelPackageMapper @Inject constructor() { } } - private fun mapCarrierPackages(carrierPackagesResponse: CarrierPredefinedPackagesDTO?): List { - return mutableListOf().apply { + private fun mapCarrierPackages(carrierPackagesResponse: CarrierPredefinedPackagesDTO?): List { + val usps = mutableListOf().apply { carrierPackagesResponse?.usps?.let { usps -> usps.flatBoxes?.toCarrierGroup()?.let { add(it) } usps.boxes?.toCarrierGroup()?.let { add(it) } usps.expressBoxes?.toCarrierGroup()?.let { add(it) } usps.envelopes?.toCarrierGroup()?.let { add(it) } } + }.let { Carrier(it) } + + val dhl = mutableListOf().apply { carrierPackagesResponse?.dhlExpress?.let { dhl -> dhl.domesticAndInternationalPackages?.toCarrierGroup()?.let { add(it) } } - } + }.let { Carrier(it) } + + return listOf(usps, dhl) } - private fun CarrierPackageGroupDTO.toCarrierGroup() = CarrierGroup( + private fun CarrierPackageGroupDTO.toCarrierGroup() = CarrierPackageGroup( description = title.orEmpty(), packages = definitions?.map { Package( From c8e291ce85510a69d8753e3389b9c66d327fe001 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 27 Nov 2024 20:35:46 -0300 Subject: [PATCH 03/41] Adopt de DAO nomenclature for the Package Repository objects --- .../WooShippingLabelPackageMapper.kt | 30 +++++++++---------- .../WooShippingLabelPackageRepository.kt | 16 +++++----- .../WooShippingLabelPackageRepositoryTest.kt | 6 ++-- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt index 71c5d4043fa..0f4a444e461 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt @@ -1,9 +1,9 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.WooShippingLabelPackageRepository.Carrier -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.WooShippingLabelPackageRepository.CarrierPackageGroup -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.WooShippingLabelPackageRepository.Package -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.WooShippingLabelPackageRepository.StorePackages +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.WooShippingLabelPackageRepository.CarrierDAO +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.WooShippingLabelPackageRepository.CarrierPackageGroupDAO +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.WooShippingLabelPackageRepository.PackageDAO +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.WooShippingLabelPackageRepository.StorePackagesDAO import com.woocommerce.android.ui.orders.wooshippinglabels.packages.networking.CarrierPackageGroupDTO import com.woocommerce.android.ui.orders.wooshippinglabels.packages.networking.CarrierPredefinedPackagesDTO import com.woocommerce.android.ui.orders.wooshippinglabels.packages.networking.PackageResponse @@ -11,18 +11,18 @@ import com.woocommerce.android.ui.orders.wooshippinglabels.packages.networking.P import javax.inject.Inject class WooShippingLabelPackageMapper @Inject constructor() { - operator fun invoke(response: PackageResponse): StorePackages { + operator fun invoke(response: PackageResponse): StorePackagesDAO { val savedPackagesResponse = response.packages?.saved?.predefined ?: emptyList() - return StorePackages( + return StorePackagesDAO( savedPackages = mapSavedPackages(savedPackagesResponse), carrierPackages = mapCarrierPackages(response.packages?.predefined) ) } - private fun mapSavedPackages(savedResponse: List): List { + private fun mapSavedPackages(savedResponse: List): List { return savedResponse.map { - Package( + PackageDAO( id = it.id.orEmpty(), name = it.name.orEmpty(), dimensions = it.dimensions.orEmpty() @@ -30,29 +30,29 @@ class WooShippingLabelPackageMapper @Inject constructor() { } } - private fun mapCarrierPackages(carrierPackagesResponse: CarrierPredefinedPackagesDTO?): List { - val usps = mutableListOf().apply { + private fun mapCarrierPackages(carrierPackagesResponse: CarrierPredefinedPackagesDTO?): List { + val usps = mutableListOf().apply { carrierPackagesResponse?.usps?.let { usps -> usps.flatBoxes?.toCarrierGroup()?.let { add(it) } usps.boxes?.toCarrierGroup()?.let { add(it) } usps.expressBoxes?.toCarrierGroup()?.let { add(it) } usps.envelopes?.toCarrierGroup()?.let { add(it) } } - }.let { Carrier(it) } + }.let { CarrierDAO(it) } - val dhl = mutableListOf().apply { + val dhl = mutableListOf().apply { carrierPackagesResponse?.dhlExpress?.let { dhl -> dhl.domesticAndInternationalPackages?.toCarrierGroup()?.let { add(it) } } - }.let { Carrier(it) } + }.let { CarrierDAO(it) } return listOf(usps, dhl) } - private fun CarrierPackageGroupDTO.toCarrierGroup() = CarrierPackageGroup( + private fun CarrierPackageGroupDTO.toCarrierGroup() = CarrierPackageGroupDAO( description = title.orEmpty(), packages = definitions?.map { - Package( + PackageDAO( id = it.id.orEmpty(), name = it.name.orEmpty(), dimensions = it.dimensions.orEmpty() diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepository.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepository.kt index de63b1ef0f3..216bfb0ea0f 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepository.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepository.kt @@ -22,23 +22,23 @@ class WooShippingLabelPackageRepository @Inject constructor( ?: WooResult(error) } - data class StorePackages( - val savedPackages: List, - val carrierPackages: List + data class StorePackagesDAO( + val savedPackages: List, + val carrierPackages: List ) - data class Package( + data class PackageDAO( val id: String, val name: String, val dimensions: String ) - data class Carrier( - val packageGroup: List + data class CarrierDAO( + val packageGroup: List ) - data class CarrierPackageGroup( + data class CarrierPackageGroupDAO( val description: String, - val packages: List + val packages: List ) } diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepositoryTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepositoryTest.kt index 3bd5e3424a0..50929068a20 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepositoryTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepositoryTest.kt @@ -33,18 +33,18 @@ class WooShippingLabelPackageRepositoryTest : BaseUnitTest() { @Test fun `fetchAllStorePackages returns WooResult with result`() = testBlocking { - val storePackages = WooShippingLabelPackageRepository.StorePackages( + val storePackagesDAO = WooShippingLabelPackageRepository.StorePackagesDAO( savedPackages = listOf(), carrierPackages = listOf() ) val packageResponse = mock() whenever(packageRestClient.fetchShippingLabelPackages(siteModel)).thenReturn(WooPayload(packageResponse)) - whenever(packageMapper(packageResponse)).thenReturn(storePackages) + whenever(packageMapper(packageResponse)).thenReturn(storePackagesDAO) val result = repository.fetchAllStorePackages() assertThat(result.isError).isFalse - assertThat(storePackages).isEqualTo(result.model) + assertThat(storePackagesDAO).isEqualTo(result.model) } @Test From b44811206d9cd86e39d9e470a6ebb57b1ffdb100 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 27 Nov 2024 20:37:19 -0300 Subject: [PATCH 04/41] Define PackageDAOs.kt file and remove DAOs declaration from WooShippingLabelPackageRepository --- .../packages/datasource/PackageDAOs.kt | 21 +++++++++++++++++++ .../WooShippingLabelPackageMapper.kt | 4 ---- .../WooShippingLabelPackageRepository.kt | 20 ------------------ .../WooShippingLabelPackageRepositoryTest.kt | 2 +- 4 files changed, 22 insertions(+), 25 deletions(-) create mode 100644 WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt new file mode 100644 index 00000000000..e21546ba8c4 --- /dev/null +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt @@ -0,0 +1,21 @@ +package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource + +data class StorePackagesDAO( + val savedPackages: List, + val carrierPackages: List +) + +data class PackageDAO( + val id: String, + val name: String, + val dimensions: String +) + +data class CarrierDAO( + val packageGroup: List +) + +data class CarrierPackageGroupDAO( + val description: String, + val packages: List +) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt index 0f4a444e461..2aef5b1df1f 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt @@ -1,9 +1,5 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.WooShippingLabelPackageRepository.CarrierDAO -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.WooShippingLabelPackageRepository.CarrierPackageGroupDAO -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.WooShippingLabelPackageRepository.PackageDAO -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.WooShippingLabelPackageRepository.StorePackagesDAO import com.woocommerce.android.ui.orders.wooshippinglabels.packages.networking.CarrierPackageGroupDTO import com.woocommerce.android.ui.orders.wooshippinglabels.packages.networking.CarrierPredefinedPackagesDTO import com.woocommerce.android.ui.orders.wooshippinglabels.packages.networking.PackageResponse diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepository.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepository.kt index 216bfb0ea0f..ad844dfafa8 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepository.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepository.kt @@ -21,24 +21,4 @@ class WooShippingLabelPackageRepository @Inject constructor( ?.let { WooResult(it) } ?: WooResult(error) } - - data class StorePackagesDAO( - val savedPackages: List, - val carrierPackages: List - ) - - data class PackageDAO( - val id: String, - val name: String, - val dimensions: String - ) - - data class CarrierDAO( - val packageGroup: List - ) - - data class CarrierPackageGroupDAO( - val description: String, - val packages: List - ) } diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepositoryTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepositoryTest.kt index 50929068a20..9806ec4d1d7 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepositoryTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepositoryTest.kt @@ -33,7 +33,7 @@ class WooShippingLabelPackageRepositoryTest : BaseUnitTest() { @Test fun `fetchAllStorePackages returns WooResult with result`() = testBlocking { - val storePackagesDAO = WooShippingLabelPackageRepository.StorePackagesDAO( + val storePackagesDAO = StorePackagesDAO( savedPackages = listOf(), carrierPackages = listOf() ) From 6f563a332a0fdd6a153895afe70875333e380349 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 15:41:04 -0300 Subject: [PATCH 05/41] Introduce Carrier types to correct map the Carriers data --- .../wooshippinglabels/packages/datasource/PackageDAOs.kt | 6 ++++++ .../packages/datasource/WooShippingLabelPackageMapper.kt | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt index e21546ba8c4..e3c8cc50d06 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt @@ -12,6 +12,7 @@ data class PackageDAO( ) data class CarrierDAO( + val type: CarrierType, val packageGroup: List ) @@ -19,3 +20,8 @@ data class CarrierPackageGroupDAO( val description: String, val packages: List ) + +enum class CarrierType { + USPS, + DHL +} diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt index 2aef5b1df1f..5eb83a3551a 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt @@ -1,5 +1,7 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.CarrierType.DHL +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.CarrierType.USPS import com.woocommerce.android.ui.orders.wooshippinglabels.packages.networking.CarrierPackageGroupDTO import com.woocommerce.android.ui.orders.wooshippinglabels.packages.networking.CarrierPredefinedPackagesDTO import com.woocommerce.android.ui.orders.wooshippinglabels.packages.networking.PackageResponse @@ -34,13 +36,13 @@ class WooShippingLabelPackageMapper @Inject constructor() { usps.expressBoxes?.toCarrierGroup()?.let { add(it) } usps.envelopes?.toCarrierGroup()?.let { add(it) } } - }.let { CarrierDAO(it) } + }.let { CarrierDAO(USPS, it) } val dhl = mutableListOf().apply { carrierPackagesResponse?.dhlExpress?.let { dhl -> dhl.domesticAndInternationalPackages?.toCarrierGroup()?.let { add(it) } } - }.let { CarrierDAO(it) } + }.let { CarrierDAO(DHL, it) } return listOf(usps, dhl) } From 7231bb89c3c289fe70af3bd84b7099b1a09c532e Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 15:49:03 -0300 Subject: [PATCH 06/41] Modify the Carrier data to be parsed as a map instead of a list --- .../packages/datasource/PackageDAOs.kt | 3 +-- .../datasource/WooShippingLabelPackageMapper.kt | 17 +++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt index e3c8cc50d06..767c95687a0 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt @@ -2,7 +2,7 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource data class StorePackagesDAO( val savedPackages: List, - val carrierPackages: List + val carrierPackages: Map ) data class PackageDAO( @@ -12,7 +12,6 @@ data class PackageDAO( ) data class CarrierDAO( - val type: CarrierType, val packageGroup: List ) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt index 5eb83a3551a..8d4a6a0c291 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt @@ -28,23 +28,28 @@ class WooShippingLabelPackageMapper @Inject constructor() { } } - private fun mapCarrierPackages(carrierPackagesResponse: CarrierPredefinedPackagesDTO?): List { - val usps = mutableListOf().apply { + private fun mapCarrierPackages( + carrierPackagesResponse: CarrierPredefinedPackagesDTO? + ): Map { + val uspsPackages = mutableListOf().apply { carrierPackagesResponse?.usps?.let { usps -> usps.flatBoxes?.toCarrierGroup()?.let { add(it) } usps.boxes?.toCarrierGroup()?.let { add(it) } usps.expressBoxes?.toCarrierGroup()?.let { add(it) } usps.envelopes?.toCarrierGroup()?.let { add(it) } } - }.let { CarrierDAO(USPS, it) } + }.let { CarrierDAO(it) } - val dhl = mutableListOf().apply { + val dhlPackages = mutableListOf().apply { carrierPackagesResponse?.dhlExpress?.let { dhl -> dhl.domesticAndInternationalPackages?.toCarrierGroup()?.let { add(it) } } - }.let { CarrierDAO(DHL, it) } + }.let { CarrierDAO(it) } - return listOf(usps, dhl) + return mapOf( + USPS to uspsPackages, + DHL to dhlPackages + ) } private fun CarrierPackageGroupDTO.toCarrierGroup() = CarrierPackageGroupDAO( From 83e01f4fd63dc03684ca290fcd45891d1bb502c8 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 16:17:50 -0300 Subject: [PATCH 07/41] Introduce initial mapping for Carrier data --- .../FetchCarrierPackagesFromStore.kt | 143 ++++++++---------- 1 file changed, 60 insertions(+), 83 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt index 2ee95f8bfad..1fb99fdf735 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt @@ -7,93 +7,70 @@ import com.woocommerce.android.ui.orders.wooshippinglabels.packages.PackageData import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import javax.inject.Inject -class FetchCarrierPackagesFromStore @Inject constructor() { +class FetchCarrierPackagesFromStore @Inject constructor( + private val packageRepository: WooShippingLabelPackageRepository +) { @Suppress("LongMethod") - operator fun invoke(): Map> { - // This is a mocked response. - // When fully implemented, this will be sorted from the Shipping plugin API. - return mapOf( - Carrier( - id = "dhl", - name = "DHL Express", - logoRes = R.drawable.dhl_logo - ) to listOf( - CarrierPackageGroup( - groupName = "Group 1", - packages = listOf( - PackageData( - type = PackageType.BOX, - name = "Package 1 - Carrier 1", - description = "Description 1", - length = "10", - width = "10", - height = "10", - isSelected = false - ), - PackageData( - type = PackageType.BOX, - name = "Package 2 - Carrier 1", - description = "Description 2", - length = "20", - width = "20", - height = "20", - isSelected = false + suspend operator fun invoke(): Map> { + return packageRepository.fetchAllStorePackages() + .takeIf { it.isError.not() } + ?.model + ?.let { response -> + val map = mutableMapOf>() + val uspsPackages = response.carrierPackages[CarrierType.USPS]?.let { + it.packageGroup.map { group -> + CarrierPackageGroup( + groupName = group.description, + packages = group.packages.map { packageItem -> + PackageData( + type = PackageType.BOX, + name = packageItem.name, + description = "", + length = "", + width = "", + height = "", + isSelected = false + ) + } ) + } + }.let { + Pair( + Carrier( + id = "usps", + name = "USPS", + logoRes = R.drawable.usps_logo + ), it ?: emptyList() ) - ), - CarrierPackageGroup( - groupName = "Group 2", - packages = listOf( - PackageData( - type = PackageType.BOX, - name = "Package 3 - Carrier 1", - description = "Description 3", - length = "30", - width = "30", - height = "30", - isSelected = false - ), - PackageData( - type = PackageType.BOX, - name = "Package 4 - Carrier 1", - description = "Description 4", - length = "40", - width = "40", - height = "40", - isSelected = false + } + val dhlPackages = response.carrierPackages[CarrierType.DHL]?.let { + it.packageGroup.map { group -> + CarrierPackageGroup( + groupName = group.description, + packages = group.packages.map { packageItem -> + PackageData( + type = PackageType.BOX, + name = packageItem.name, + description = "", + length = "", + width = "", + height = "", + isSelected = false + ) + } ) + } + }.let { + Pair( + Carrier( + id = "dhl", + name = "DHL Express", + logoRes = R.drawable.dhl_logo + ), it ?: emptyList() ) - ) - ), - Carrier( - id = "usps", - name = "USPS", - logoRes = R.drawable.usps_logo - ) to listOf( - CarrierPackageGroup( - groupName = "Group 2", - packages = listOf( - PackageData( - type = PackageType.BOX, - name = "Package 1 - Carrier 2", - description = "Description 1", - length = "10", - width = "10", - height = "10", - isSelected = false - ), - PackageData( - type = PackageType.BOX, - name = "Package 2 Carrier - 2", - description = "Description 2", - length = "20", - width = "20", - height = "20", - isSelected = false - ) - ) - ) - ) - ) + } + + mapOf(uspsPackages, dhlPackages) + } ?: emptyMap() } } From a807a5f8ab99c2b805f63bd806c465cc8cf57650 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 16:21:48 -0300 Subject: [PATCH 08/41] Refactor carrier package data parsing --- .../FetchCarrierPackagesFromStore.kt | 91 +++++++++---------- 1 file changed, 42 insertions(+), 49 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt index 1fb99fdf735..864a70e276b 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt @@ -16,61 +16,54 @@ class FetchCarrierPackagesFromStore @Inject constructor( .takeIf { it.isError.not() } ?.model ?.let { response -> - val map = mutableMapOf>() - val uspsPackages = response.carrierPackages[CarrierType.USPS]?.let { - it.packageGroup.map { group -> - CarrierPackageGroup( - groupName = group.description, - packages = group.packages.map { packageItem -> - PackageData( - type = PackageType.BOX, - name = packageItem.name, - description = "", - length = "", - width = "", - height = "", - isSelected = false - ) - } + val uspsPackages = response.carrierPackages + .parseCarrierData(CarrierType.USPS) + .let { + Pair( + Carrier( + id = "usps", + name = "USPS", + logoRes = R.drawable.usps_logo + ), it ) } - }.let { - Pair( - Carrier( - id = "usps", - name = "USPS", - logoRes = R.drawable.usps_logo - ), it ?: emptyList() - ) - } - val dhlPackages = response.carrierPackages[CarrierType.DHL]?.let { - it.packageGroup.map { group -> - CarrierPackageGroup( - groupName = group.description, - packages = group.packages.map { packageItem -> - PackageData( - type = PackageType.BOX, - name = packageItem.name, - description = "", - length = "", - width = "", - height = "", - isSelected = false - ) - } + + val dhlPackages = response.carrierPackages + .parseCarrierData(CarrierType.DHL) + .let { + Pair( + Carrier( + id = "dhl", + name = "DHL Express", + logoRes = R.drawable.dhl_logo + ), it ) - } - }.let { - Pair( - Carrier( - id = "dhl", - name = "DHL Express", - logoRes = R.drawable.dhl_logo - ), it ?: emptyList() - ) } mapOf(uspsPackages, dhlPackages) } ?: emptyMap() } + + private fun Map.parseCarrierData( + carrierType: CarrierType + ) : List { + return this[carrierType]?.let { + return it.packageGroup.map { group -> + CarrierPackageGroup( + groupName = group.description, + packages = group.packages.map { packageItem -> + PackageData( + type = PackageType.BOX, + name = packageItem.name, + description = "", + length = "", + width = "", + height = "", + isSelected = false + ) + } + ) + } + } ?: emptyList() + } } From 8b3d46eadd74bb910eeb06eedbbb18dc2647ea02 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 16:29:37 -0300 Subject: [PATCH 09/41] Launch data fetching use cases from a coroutines --- .../WooShippingLabelPackageCreationViewModel.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index 5b90808d7e3..cf68db4a059 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -15,6 +15,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.update import kotlinx.parcelize.Parcelize import javax.inject.Inject +import kotlinx.coroutines.launch @HiltViewModel class WooShippingLabelPackageCreationViewModel @Inject constructor( @@ -47,11 +48,13 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( ) init { - _viewState.update { viewState -> - viewState.copy( - savedPackageSelection = SavedPackageSelection(fetchSavedPackages()), - carrierPackageSection = CarrierPackageSelection(fetchCarrierPackages()) - ) + launch { + _viewState.update { viewState -> + viewState.copy( + savedPackageSelection = SavedPackageSelection(fetchSavedPackages()), + carrierPackageSection = CarrierPackageSelection(fetchCarrierPackages()) + ) + } } } From f2e88789d3862e912909802122ef702044bb80f7 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 16:34:12 -0300 Subject: [PATCH 10/41] Extract Carrier data and refactor Pair declarations --- .../FetchCarrierPackagesFromStore.kt | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt index 864a70e276b..8b04a7652a4 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt @@ -16,31 +16,15 @@ class FetchCarrierPackagesFromStore @Inject constructor( .takeIf { it.isError.not() } ?.model ?.let { response -> - val uspsPackages = response.carrierPackages - .parseCarrierData(CarrierType.USPS) - .let { - Pair( - Carrier( - id = "usps", - name = "USPS", - logoRes = R.drawable.usps_logo - ), it - ) - } - - val dhlPackages = response.carrierPackages - .parseCarrierData(CarrierType.DHL) - .let { - Pair( - Carrier( - id = "dhl", - name = "DHL Express", - logoRes = R.drawable.dhl_logo - ), it - ) - } + mapOf( + response.carrierPackages + .parseCarrierData(CarrierType.USPS) + .let { uspsCarrier to it }, - mapOf(uspsPackages, dhlPackages) + response.carrierPackages + .parseCarrierData(CarrierType.DHL) + .let { dhlCarrier to it } + ) } ?: emptyMap() } @@ -66,4 +50,18 @@ class FetchCarrierPackagesFromStore @Inject constructor( } } ?: emptyList() } + + companion object { + private val uspsCarrier = Carrier( + id = "usps", + name = "USPS", + logoRes = R.drawable.usps_logo + ) + + private val dhlCarrier = Carrier( + id = "dhl", + name = "DHL Express", + logoRes = R.drawable.dhl_logo + ) + } } From 94c304ebfd20700230ac1d9164e2ddc89dc32ec6 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 16:36:03 -0300 Subject: [PATCH 11/41] Finish Refactor on FetchCarrierPackagesFromStore --- .../FetchCarrierPackagesFromStore.kt | 61 +++++++++---------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt index 8b04a7652a4..85f1b097ae9 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt @@ -15,41 +15,40 @@ class FetchCarrierPackagesFromStore @Inject constructor( return packageRepository.fetchAllStorePackages() .takeIf { it.isError.not() } ?.model - ?.let { response -> - mapOf( - response.carrierPackages - .parseCarrierData(CarrierType.USPS) - .let { uspsCarrier to it }, - - response.carrierPackages - .parseCarrierData(CarrierType.DHL) - .let { dhlCarrier to it } - ) - } ?: emptyMap() + ?.filterCarrierData() + ?: emptyMap() } + private fun StorePackagesDAO.filterCarrierData() = mapOf( + carrierPackages + .parseCarrierData(CarrierType.USPS) + .let { uspsCarrier to it }, + + carrierPackages + .parseCarrierData(CarrierType.DHL) + .let { dhlCarrier to it } + ) + private fun Map.parseCarrierData( carrierType: CarrierType - ) : List { - return this[carrierType]?.let { - return it.packageGroup.map { group -> - CarrierPackageGroup( - groupName = group.description, - packages = group.packages.map { packageItem -> - PackageData( - type = PackageType.BOX, - name = packageItem.name, - description = "", - length = "", - width = "", - height = "", - isSelected = false - ) - } - ) - } - } ?: emptyList() - } + ) = get(carrierType)?.let { + it.packageGroup.map { group -> + CarrierPackageGroup( + groupName = group.description, + packages = group.packages.map { packageItem -> + PackageData( + type = PackageType.BOX, + name = packageItem.name, + description = "", + length = "", + width = "", + height = "", + isSelected = false + ) + } + ) + } + } ?: emptyList() companion object { private val uspsCarrier = Carrier( From f4cafd680d5eced1f5e5cff24de483c93a5fa396 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 16:50:17 -0300 Subject: [PATCH 12/41] Centralize Carrier UI data --- .../wooshippinglabels/packages/Models.kt | 17 ++++++++++++++-- .../FetchCarrierPackagesFromStore.kt | 20 ++----------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/Models.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/Models.kt index 0e6336662b6..e2d82d90b0e 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/Models.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/Models.kt @@ -1,6 +1,7 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages import android.os.Parcelable +import com.woocommerce.android.R import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import kotlinx.parcelize.Parcelize @@ -26,11 +27,23 @@ data class CarrierPackageGroup( ) : Parcelable @Parcelize -data class Carrier( +sealed class Carrier( val id: String, val name: String, val logoRes: Int? = null, -) : Parcelable +) : Parcelable { + data object USPS : Carrier( + id = "usps", + name = "USPS", + logoRes = R.drawable.usps_logo + ) + + data object DHL : Carrier( + id = "dhl", + name = "DHL", + logoRes = R.drawable.dhl_logo + ) +} @Parcelize data class CarrierPackageSelection( diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt index 85f1b097ae9..b9da1644e0d 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt @@ -1,6 +1,5 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource -import com.woocommerce.android.R import com.woocommerce.android.ui.orders.wooshippinglabels.packages.Carrier import com.woocommerce.android.ui.orders.wooshippinglabels.packages.CarrierPackageGroup import com.woocommerce.android.ui.orders.wooshippinglabels.packages.PackageData @@ -10,7 +9,6 @@ import javax.inject.Inject class FetchCarrierPackagesFromStore @Inject constructor( private val packageRepository: WooShippingLabelPackageRepository ) { - @Suppress("LongMethod") suspend operator fun invoke(): Map> { return packageRepository.fetchAllStorePackages() .takeIf { it.isError.not() } @@ -22,11 +20,11 @@ class FetchCarrierPackagesFromStore @Inject constructor( private fun StorePackagesDAO.filterCarrierData() = mapOf( carrierPackages .parseCarrierData(CarrierType.USPS) - .let { uspsCarrier to it }, + .let { Carrier.USPS to it }, carrierPackages .parseCarrierData(CarrierType.DHL) - .let { dhlCarrier to it } + .let { Carrier.DHL to it } ) private fun Map.parseCarrierData( @@ -49,18 +47,4 @@ class FetchCarrierPackagesFromStore @Inject constructor( ) } } ?: emptyList() - - companion object { - private val uspsCarrier = Carrier( - id = "usps", - name = "USPS", - logoRes = R.drawable.usps_logo - ) - - private val dhlCarrier = Carrier( - id = "dhl", - name = "DHL Express", - logoRes = R.drawable.dhl_logo - ) - } } From 0e58c2b30bfc2dc75bfb9c310e506295e0665315 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 16:51:10 -0300 Subject: [PATCH 13/41] Reorganize folder structure for Packages classes --- .../packages/WooShippingLabelPackageCreationFragment.kt | 1 + .../packages/WooShippingLabelPackageCreationScreen.kt | 7 ++++--- .../packages/WooShippingLabelPackageCreationViewModel.kt | 6 ++++++ .../packages/components/WooShippingPackageListItem.kt | 2 +- .../packages/datasource/FetchCarrierPackagesFromStore.kt | 6 +++--- .../packages/datasource/FetchSavedPackagesFromStore.kt | 2 +- .../packages/{Models.kt => ui/UIModels.kt} | 2 +- .../{forms => ui}/WooShippingCarrierPackageScreen.kt | 5 +---- .../{forms => ui}/WooShippingCustomPackageScreen.kt | 2 +- .../{forms => ui}/WooShippingSavedPackageScreen.kt | 3 +-- .../WooShippingLabelPackageCreationViewModelTest.kt | 4 ++++ 11 files changed, 24 insertions(+), 16 deletions(-) rename WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/{Models.kt => ui/UIModels.kt} (99%) rename WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/{forms => ui}/WooShippingCarrierPackageScreen.kt (97%) rename WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/{forms => ui}/WooShippingCustomPackageScreen.kt (99%) rename WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/{forms => ui}/WooShippingSavedPackageScreen.kt (97%) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationFragment.kt index 8f6391eab0c..790675534ab 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationFragment.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationFragment.kt @@ -17,6 +17,7 @@ import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageSelected import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.ShowPackageTypeDialog +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt index 24c9826facc..edf667dd05f 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt @@ -26,9 +26,10 @@ import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingL import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PageType.CARRIER import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PageType.CUSTOM import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PageType.SAVED -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.forms.WooShippingCarrierPackageScreen -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.forms.WooShippingCustomPackageCreationScreen -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.forms.WooShippingSavedPackageScreen +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.WooShippingCarrierPackageScreen +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.WooShippingCustomPackageCreationScreen +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.WooShippingSavedPackageScreen @Composable fun WooShippingLabelPackageCreationScreen( diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index cf68db4a059..2d7be8bfbc0 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -7,6 +7,12 @@ import androidx.lifecycle.viewModelScope import com.woocommerce.android.R import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.FetchCarrierPackagesFromStore import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.FetchSavedPackagesFromStore +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.Carrier +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageGroup +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageSelection +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CustomPackageCreationData +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.SavedPackageSelection import com.woocommerce.android.viewmodel.MultiLiveEvent import com.woocommerce.android.viewmodel.ResourceProvider import com.woocommerce.android.viewmodel.ScopedViewModel diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/components/WooShippingPackageListItem.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/components/WooShippingPackageListItem.kt index 8cc58273b7f..cab8856f742 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/components/WooShippingPackageListItem.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/components/WooShippingPackageListItem.kt @@ -15,7 +15,7 @@ import androidx.compose.ui.res.colorResource import androidx.compose.ui.unit.dp import com.woocommerce.android.R import com.woocommerce.android.ui.compose.component.SelectionCheck -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.PackageData +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData @Composable fun WooSavedPackageListItem( diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt index b9da1644e0d..50cc74867ee 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt @@ -1,8 +1,8 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.Carrier -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.CarrierPackageGroup -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.PackageData +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.Carrier +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageGroup +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import javax.inject.Inject diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchSavedPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchSavedPackagesFromStore.kt index e229047f956..19033fb36ca 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchSavedPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchSavedPackagesFromStore.kt @@ -1,6 +1,6 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.PackageData +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import javax.inject.Inject diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/Models.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt similarity index 99% rename from WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/Models.kt rename to WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt index e2d82d90b0e..71cb87731be 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/Models.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt @@ -1,4 +1,4 @@ -package com.woocommerce.android.ui.orders.wooshippinglabels.packages +package com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui import android.os.Parcelable import com.woocommerce.android.R diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingCarrierPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt similarity index 97% rename from WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingCarrierPackageScreen.kt rename to WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt index 35fdb3027a8..793842d3e54 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingCarrierPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt @@ -1,4 +1,4 @@ -package com.woocommerce.android.ui.orders.wooshippinglabels.packages.forms +package com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui import androidx.annotation.DrawableRes import androidx.compose.foundation.ExperimentalFoundationApi @@ -39,9 +39,6 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.woocommerce.android.R import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.Carrier -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.CarrierPackageGroup -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.PackageData import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import com.woocommerce.android.ui.orders.wooshippinglabels.packages.components.WooSavedPackageListItem diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingCustomPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCustomPackageScreen.kt similarity index 99% rename from WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingCustomPackageScreen.kt rename to WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCustomPackageScreen.kt index 83bcb39f439..92b66513eb1 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingCustomPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCustomPackageScreen.kt @@ -1,4 +1,4 @@ -package com.woocommerce.android.ui.orders.wooshippinglabels.packages.forms +package com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt similarity index 97% rename from WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt rename to WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt index 54e3517c551..5f225660179 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt @@ -1,4 +1,4 @@ -package com.woocommerce.android.ui.orders.wooshippinglabels.packages.forms +package com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize @@ -17,7 +17,6 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.woocommerce.android.R import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.PackageData import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import com.woocommerce.android.ui.orders.wooshippinglabels.packages.components.WooSavedPackageListItem diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt index 8784cef1117..e7ce5a82109 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt @@ -8,6 +8,10 @@ import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingL import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.ViewState import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.FetchCarrierPackagesFromStore import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.FetchSavedPackagesFromStore +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.Carrier +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageGroup +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CustomPackageCreationData +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData import com.woocommerce.android.viewmodel.BaseUnitTest import com.woocommerce.android.viewmodel.MultiLiveEvent import com.woocommerce.android.viewmodel.ResourceProvider From 8885860e552a5ceb0b75ba5e90462d10f4d27dd5 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 17:06:42 -0300 Subject: [PATCH 14/41] Fix Package UI previews --- .../packages/ui/WooShippingCarrierPackageScreen.kt | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt index 793842d3e54..1a5c89cc89e 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt @@ -226,11 +226,7 @@ fun WooShippingCarrierPackageScreenPreview() { WooThemeWithBackground { WooShippingCarrierPackageScreen( carrierPackages = mapOf( - Carrier( - id = "dhl", - name = "DHL Express", - logoRes = R.drawable.dhl_logo - ) to listOf( + Carrier.DHL to listOf( CarrierPackageGroup( groupName = "Group 1", packages = listOf( @@ -278,11 +274,7 @@ fun WooShippingCarrierPackageScreenPreview() { ) ) ), - Carrier( - id = "usps", - name = "USPS", - logoRes = R.drawable.usps_logo - ) to listOf( + Carrier.USPS to listOf( CarrierPackageGroup( groupName = "Group 2", packages = listOf( From d1938c866a7c36dd54c041442280cd8277203ea4 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 17:06:52 -0300 Subject: [PATCH 15/41] Remove dedicated SavedPackage use case --- .../datasource/FetchSavedPackagesFromStore.kt | 41 ------------------- 1 file changed, 41 deletions(-) delete mode 100644 WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchSavedPackagesFromStore.kt diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchSavedPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchSavedPackagesFromStore.kt deleted file mode 100644 index 19033fb36ca..00000000000 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchSavedPackagesFromStore.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource - -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType -import javax.inject.Inject - -class FetchSavedPackagesFromStore @Inject constructor() { - operator fun invoke(): List { - // This is a mocked response. - // When fully implemented, this will be sorted from the Shipping plugin API. - return listOf( - PackageData( - type = PackageType.ENVELOPE, - name = "Small Flat Rate Box", - description = "USPS Priority Mail Flat Rate Boxes", - length = "10", - width = "10", - height = "10", - isSelected = true - ), - PackageData( - type = PackageType.BOX, - name = "Small Flat Rate Box", - description = "Custom package", - length = "20", - width = "20", - height = "20", - isSelected = false - ), - PackageData( - type = PackageType.BOX, - name = "Small Flat Rate Box", - description = "DHL Express", - length = "30", - width = "30", - height = "30", - isSelected = false - ) - ) - } -} From f3d4c3f2770b4b322eca57137330a033ec726be2 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 17:07:24 -0300 Subject: [PATCH 16/41] Rename Carrier fetching use case to Predefined packages fetching --- .../packages/WooShippingLabelPackageCreationViewModel.kt | 4 ++-- ...ckagesFromStore.kt => FetchPredefinedPackagesFromStore.kt} | 2 +- .../packages/WooShippingLabelPackageCreationViewModelTest.kt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/{FetchCarrierPackagesFromStore.kt => FetchPredefinedPackagesFromStore.kt} (96%) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index 2d7be8bfbc0..a062b521840 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -5,7 +5,7 @@ import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.asLiveData import androidx.lifecycle.viewModelScope import com.woocommerce.android.R -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.FetchCarrierPackagesFromStore +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.FetchPredefinedPackagesFromStore import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.FetchSavedPackagesFromStore import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.Carrier import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageGroup @@ -28,7 +28,7 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( savedState: SavedStateHandle, private val resourceProvider: ResourceProvider, private val fetchSavedPackages: FetchSavedPackagesFromStore, - private val fetchCarrierPackages: FetchCarrierPackagesFromStore + private val fetchCarrierPackages: FetchPredefinedPackagesFromStore ) : ScopedViewModel(savedState) { private val _viewState = savedState.getStateFlow( diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt similarity index 96% rename from WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt rename to WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt index 50cc74867ee..2566fc875d3 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt @@ -6,7 +6,7 @@ import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageDa import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import javax.inject.Inject -class FetchCarrierPackagesFromStore @Inject constructor( +class FetchPredefinedPackagesFromStore @Inject constructor( private val packageRepository: WooShippingLabelPackageRepository ) { suspend operator fun invoke(): Map> { diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt index e7ce5a82109..aada1c14217 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt @@ -6,7 +6,7 @@ import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingL import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.ShowPackageTypeDialog import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.ViewState -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.FetchCarrierPackagesFromStore +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.FetchPredefinedPackagesFromStore import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.FetchSavedPackagesFromStore import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.Carrier import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageGroup @@ -28,7 +28,7 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { private lateinit var sut: WooShippingLabelPackageCreationViewModel private val resourceProvider: ResourceProvider = mock() private val fetchSavedPackages: FetchSavedPackagesFromStore = mock() - private val fetchCarrierPackages: FetchCarrierPackagesFromStore = mock() + private val fetchCarrierPackages: FetchPredefinedPackagesFromStore = mock() @Before fun setUp() { From af6f03512ba0f14d17cb86447f35061cf23841b7 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 17:16:16 -0300 Subject: [PATCH 17/41] Introduce StorePredefinedPackages model --- .../ui/orders/wooshippinglabels/packages/ui/UIModels.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt index 71cb87731be..4a90d90a2b3 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt @@ -45,6 +45,12 @@ sealed class Carrier( ) } +@Parcelize +data class StorePredefinedPackages( + val carrierPackageSelection: CarrierPackageSelection, + val savedPackageSelection: SavedPackageSelection +) : Parcelable + @Parcelize data class CarrierPackageSelection( val carrierPackages: Map> From a0b5617bd34553c1e5196c3b7aeb394fba3f5103 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 17:19:32 -0300 Subject: [PATCH 18/41] Adjust WooShippingLabelPackageCreationViewModel to conform with new Package response from use case --- ...ooShippingLabelPackageCreationViewModel.kt | 10 +++---- .../FetchPredefinedPackagesFromStore.kt | 30 +++++++++++++++++-- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index a062b521840..246172b916b 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -6,7 +6,6 @@ import androidx.lifecycle.asLiveData import androidx.lifecycle.viewModelScope import com.woocommerce.android.R import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.FetchPredefinedPackagesFromStore -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.FetchSavedPackagesFromStore import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.Carrier import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageGroup import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageSelection @@ -27,8 +26,7 @@ import kotlinx.coroutines.launch class WooShippingLabelPackageCreationViewModel @Inject constructor( savedState: SavedStateHandle, private val resourceProvider: ResourceProvider, - private val fetchSavedPackages: FetchSavedPackagesFromStore, - private val fetchCarrierPackages: FetchPredefinedPackagesFromStore + private val fetchPredefinedPackages: FetchPredefinedPackagesFromStore ) : ScopedViewModel(savedState) { private val _viewState = savedState.getStateFlow( @@ -56,9 +54,11 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( init { launch { _viewState.update { viewState -> + val predefinedPackages = fetchPredefinedPackages() + viewState.copy( - savedPackageSelection = SavedPackageSelection(fetchSavedPackages()), - carrierPackageSection = CarrierPackageSelection(fetchCarrierPackages()) + savedPackageSelection = predefinedPackages.savedPackageSelection, + carrierPackageSection = predefinedPackages.carrierPackageSelection ) } } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt index 2566fc875d3..94b21ff80ad 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt @@ -4,17 +4,43 @@ import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.Carrier import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageGroup import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageSelection +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.SavedPackageSelection +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.StorePredefinedPackages import javax.inject.Inject class FetchPredefinedPackagesFromStore @Inject constructor( private val packageRepository: WooShippingLabelPackageRepository ) { - suspend operator fun invoke(): Map> { - return packageRepository.fetchAllStorePackages() + suspend operator fun invoke(): StorePredefinedPackages { + val storePackages = packageRepository.fetchAllStorePackages() + + val carrierPackages = storePackages .takeIf { it.isError.not() } ?.model ?.filterCarrierData() ?: emptyMap() + + val savedPackages = storePackages + .takeIf { it.isError.not() } + ?.model + ?.savedPackages + ?.map { packageDAO -> + PackageData( + type = PackageType.BOX, + name = packageDAO.name, + description = "", + length = "", + width = "", + height = "", + isSelected = false + ) + } ?: emptyList() + + return StorePredefinedPackages( + carrierPackageSelection = CarrierPackageSelection(carrierPackages), + savedPackageSelection = SavedPackageSelection(savedPackages) + ) } private fun StorePackagesDAO.filterCarrierData() = mapOf( From 258f8b88f14bd3e934f321cb902bd75e89c342ae Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 17:19:49 -0300 Subject: [PATCH 19/41] Fix package related unit tests --- ...ippingLabelPackageCreationViewModelTest.kt | 53 ++++++++++++------- .../WooShippingLabelPackageRepositoryTest.kt | 2 +- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt index aada1c14217..f3585c13bdd 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt @@ -7,11 +7,13 @@ import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingL import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.ShowPackageTypeDialog import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.ViewState import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.FetchPredefinedPackagesFromStore -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.FetchSavedPackagesFromStore import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.Carrier import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageGroup +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageSelection import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CustomPackageCreationData import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.SavedPackageSelection +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.StorePredefinedPackages import com.woocommerce.android.viewmodel.BaseUnitTest import com.woocommerce.android.viewmodel.MultiLiveEvent import com.woocommerce.android.viewmodel.ResourceProvider @@ -27,8 +29,7 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { private lateinit var sut: WooShippingLabelPackageCreationViewModel private val resourceProvider: ResourceProvider = mock() - private val fetchSavedPackages: FetchSavedPackagesFromStore = mock() - private val fetchCarrierPackages: FetchPredefinedPackagesFromStore = mock() + private val fetchPredefinedPackages: FetchPredefinedPackagesFromStore = mock() @Before fun setUp() { @@ -42,12 +43,10 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { resourceProvider.getString(R.string.woo_shipping_labels_package_creation_tab_saved) ).thenReturn("Saved") - whenever(fetchSavedPackages()).thenReturn(emptyList()) sut = WooShippingLabelPackageCreationViewModel( SavedStateHandle(), resourceProvider, - fetchSavedPackages, - fetchCarrierPackages + fetchPredefinedPackages ) } @@ -159,13 +158,19 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { height = "20", isSelected = false ) - whenever(fetchSavedPackages()).thenReturn(listOf(package1, package2)) + whenever(fetchPredefinedPackages()).thenReturn( + StorePredefinedPackages( + carrierPackageSelection = CarrierPackageSelection(emptyMap()), + savedPackageSelection = SavedPackageSelection( + listOf(package1, package2) + ) + ) + ) sut = WooShippingLabelPackageCreationViewModel( SavedStateHandle(), resourceProvider, - fetchSavedPackages, - fetchCarrierPackages + fetchPredefinedPackages ) sut.viewState.observeForever { lastViewState = it } sut.onSavedPackageSelected(package1, true) @@ -179,7 +184,7 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { @Test fun `onCarrierPackageSelected selects only one package at a time`() = testBlocking { var lastViewState: ViewState? = null - val carrier = Carrier(id = "dhl", name = "DHL Express", logoRes = R.drawable.dhl_logo) + val carrier: Carrier = Carrier.DHL val package1 = PackageData( type = PackageType.BOX, name = "Package 1", @@ -206,13 +211,19 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { ) ) ) - whenever(fetchCarrierPackages()).thenReturn(carrierPackages) + whenever(fetchPredefinedPackages()).thenReturn( + StorePredefinedPackages( + carrierPackageSelection = CarrierPackageSelection(carrierPackages), + savedPackageSelection = SavedPackageSelection( + emptyList() + ) + ) + ) sut = WooShippingLabelPackageCreationViewModel( SavedStateHandle(), resourceProvider, - fetchSavedPackages, - fetchCarrierPackages + fetchPredefinedPackages ) sut.viewState.observeForever { lastViewState = it } sut.onCarrierPackageSelected(package1, true) @@ -229,8 +240,8 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { @Suppress("LongMethod") fun `onCarrierPackageSelected selects only one package at a time with multiple carriers`() = testBlocking { var lastViewState: ViewState? = null - val carrier1 = Carrier(id = "dhl", name = "DHL Express", logoRes = R.drawable.dhl_logo) - val carrier2 = Carrier(id = "usps", name = "USPS", logoRes = R.drawable.usps_logo) + val carrier1: Carrier = Carrier.DHL + val carrier2: Carrier = Carrier.USPS val package1 = PackageData( type = PackageType.BOX, name = "Package 1 - Carrier 1", @@ -281,13 +292,19 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { ) ) ) - whenever(fetchCarrierPackages()).thenReturn(carrierPackages) + whenever(fetchPredefinedPackages()).thenReturn( + StorePredefinedPackages( + carrierPackageSelection = CarrierPackageSelection(carrierPackages), + savedPackageSelection = SavedPackageSelection( + emptyList() + ) + ) + ) sut = WooShippingLabelPackageCreationViewModel( SavedStateHandle(), resourceProvider, - fetchSavedPackages, - fetchCarrierPackages + fetchPredefinedPackages ) sut.viewState.observeForever { lastViewState = it } sut.onCarrierPackageSelected(package1, true) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepositoryTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepositoryTest.kt index 9806ec4d1d7..be057e3fc93 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepositoryTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageRepositoryTest.kt @@ -35,7 +35,7 @@ class WooShippingLabelPackageRepositoryTest : BaseUnitTest() { fun `fetchAllStorePackages returns WooResult with result`() = testBlocking { val storePackagesDAO = StorePackagesDAO( savedPackages = listOf(), - carrierPackages = listOf() + carrierPackages = mapOf() ) val packageResponse = mock() whenever(packageRestClient.fetchShippingLabelPackages(siteModel)).thenReturn(WooPayload(packageResponse)) From 2a952f883eb86bb862ebf6dc3f9cfd0f66e9854c Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 17:30:50 -0300 Subject: [PATCH 20/41] Fix lint issues --- .../packages/WooShippingLabelPackageCreationViewModel.kt | 2 +- .../packages/datasource/FetchPredefinedPackagesFromStore.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index 246172b916b..cfb7317d9ff 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -18,9 +18,9 @@ import com.woocommerce.android.viewmodel.ScopedViewModel import com.woocommerce.android.viewmodel.getStateFlow import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.update +import kotlinx.coroutines.launch import kotlinx.parcelize.Parcelize import javax.inject.Inject -import kotlinx.coroutines.launch @HiltViewModel class WooShippingLabelPackageCreationViewModel @Inject constructor( diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt index 94b21ff80ad..68bc0e2e0a8 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt @@ -1,10 +1,10 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.Carrier import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageGroup -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageSelection +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.SavedPackageSelection import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.StorePredefinedPackages import javax.inject.Inject From 64545002c904e0d4dc07037b3c9d85fb15ecffce Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 17:36:48 -0300 Subject: [PATCH 21/41] Introduce FetchPredefinedPackagesFromStoreTest --- .../FetchPredefinedPackagesFromStoreTest.kt | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt new file mode 100644 index 00000000000..28d7af3946f --- /dev/null +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt @@ -0,0 +1,106 @@ +package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource + +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType +import com.woocommerce.android.viewmodel.BaseUnitTest +import org.mockito.kotlin.whenever +import org.wordpress.android.fluxc.network.BaseRequest +import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooError +import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooErrorType +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.* +import kotlinx.coroutines.ExperimentalCoroutinesApi +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test +import org.mockito.Mockito.* +import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooResult + +@OptIn(ExperimentalCoroutinesApi::class) +class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { + + private val packageRepository: WooShippingLabelPackageRepository = mock(WooShippingLabelPackageRepository::class.java) + private val fetchPredefinedPackagesFromStore = FetchPredefinedPackagesFromStore(packageRepository) + + @Test + fun `invoke should return StorePredefinedPackages with carrier and saved packages`() = testBlocking { + val storePackages = StorePackagesDAO( + savedPackages = listOf( + PackageDAO( + id = "1", + name = "Saved Package 1", + dimensions = "dimensions" + ), + PackageDAO( + id = "2", + name = "Saved Package 2", + dimensions = "dimensions" + ) + ), + carrierPackages = mapOf( + CarrierType.USPS to CarrierDAO( + packageGroup = listOf( + CarrierPackageGroupDAO( + description = "Group 1", + packages = listOf( + PackageDAO( + id = "1", + name = "Carrier Package 1", + dimensions = "dimensions" + ) + ) + ) + ) + ) + ) + ) + whenever(packageRepository.fetchAllStorePackages()).thenReturn(WooResult(storePackages)) + + val result = fetchPredefinedPackagesFromStore() + + assertThat(result.savedPackageSelection.packages).containsExactly( + PackageData( + type = PackageType.BOX, + name = "Saved Package 1", + description = "", + length = "", + width = "", + height = "", + isSelected = false + ), + PackageData( + type = PackageType.BOX, + name = "Saved Package 2", + description = "", + length = "", + width = "", + height = "", + isSelected = false + ) + ) + assertThat(result.carrierPackageSelection.carrierPackages[Carrier.USPS]).containsExactly( + CarrierPackageGroup( + groupName = "Group 1", + packages = listOf( + PackageData( + type = PackageType.BOX, + name = "Carrier Package 1", + description = "", + length = "", + width = "", + height = "", + isSelected = false + ) + ) + ) + ) + } + + @Test + fun `invoke should return empty StorePredefinedPackages when fetchAllStorePackages returns error`() = testBlocking { + val error = WooError(WooErrorType.GENERIC_ERROR, BaseRequest.GenericErrorType.UNKNOWN) + whenever(packageRepository.fetchAllStorePackages()).thenReturn(WooResult(error)) + + val result = fetchPredefinedPackagesFromStore() + + assertThat(result.savedPackageSelection.packages).isEmpty() + assertThat(result.carrierPackageSelection.carrierPackages).isEmpty() + } +} From ef6c32ebada96e154f3d725cc4261a532c79bae7 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 17:49:07 -0300 Subject: [PATCH 22/41] Introduce selectedSite injection into FetchPredefinedPackagesFromStore --- .../WooShippingLabelPackageCreationViewModel.kt | 14 +++++++------- .../datasource/FetchPredefinedPackagesFromStore.kt | 7 +++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index cfb7317d9ff..aec3425fa69 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -53,13 +53,13 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( init { launch { - _viewState.update { viewState -> - val predefinedPackages = fetchPredefinedPackages() - - viewState.copy( - savedPackageSelection = predefinedPackages.savedPackageSelection, - carrierPackageSection = predefinedPackages.carrierPackageSelection - ) + fetchPredefinedPackages()?.let { + _viewState.update { viewState -> + viewState.copy( + savedPackageSelection = it.savedPackageSelection, + carrierPackageSection = it.carrierPackageSelection + ) + } } } } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt index 68bc0e2e0a8..d9c09bf4a22 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt @@ -1,5 +1,6 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource +import com.woocommerce.android.tools.SelectedSite import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.Carrier import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageGroup @@ -10,10 +11,12 @@ import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.StorePred import javax.inject.Inject class FetchPredefinedPackagesFromStore @Inject constructor( + private val selectedSite: SelectedSite, private val packageRepository: WooShippingLabelPackageRepository ) { - suspend operator fun invoke(): StorePredefinedPackages { - val storePackages = packageRepository.fetchAllStorePackages() + suspend operator fun invoke(): StorePredefinedPackages? { + val site = selectedSite.getOrNull() ?: return null + val storePackages = packageRepository.fetchAllStorePackages(site) val carrierPackages = storePackages .takeIf { it.isError.not() } From 3f92ea6926bdcceab4e3b4ac2b8e1b4f68c0f2ca Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 17:49:14 -0300 Subject: [PATCH 23/41] Adjust FetchPredefinedPackagesFromStoreTest to go green --- .../FetchPredefinedPackagesFromStoreTest.kt | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt index 28d7af3946f..bff2b1f0f9d 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt @@ -1,5 +1,6 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource +import com.woocommerce.android.tools.SelectedSite import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import com.woocommerce.android.viewmodel.BaseUnitTest import org.mockito.kotlin.whenever @@ -10,14 +11,19 @@ import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.* import kotlinx.coroutines.ExperimentalCoroutinesApi import org.assertj.core.api.Assertions.assertThat import org.junit.Test -import org.mockito.Mockito.* +import org.mockito.kotlin.mock +import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooResult @OptIn(ExperimentalCoroutinesApi::class) class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { - private val packageRepository: WooShippingLabelPackageRepository = mock(WooShippingLabelPackageRepository::class.java) - private val fetchPredefinedPackagesFromStore = FetchPredefinedPackagesFromStore(packageRepository) + private val packageRepository: WooShippingLabelPackageRepository = mock() + private val selectedSite: SelectedSite = mock() + private val fetchPredefinedPackagesFromStore = FetchPredefinedPackagesFromStore( + selectedSite, + packageRepository + ) @Test fun `invoke should return StorePredefinedPackages with carrier and saved packages`() = testBlocking { @@ -51,9 +57,11 @@ class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { ) ) ) - whenever(packageRepository.fetchAllStorePackages()).thenReturn(WooResult(storePackages)) + val site = SiteModel().apply { id = 1 } + whenever(selectedSite.getOrNull()).thenReturn(site) + whenever(packageRepository.fetchAllStorePackages(site)).thenReturn(WooResult(storePackages)) - val result = fetchPredefinedPackagesFromStore() + val result = fetchPredefinedPackagesFromStore()!! assertThat(result.savedPackageSelection.packages).containsExactly( PackageData( @@ -96,9 +104,11 @@ class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { @Test fun `invoke should return empty StorePredefinedPackages when fetchAllStorePackages returns error`() = testBlocking { val error = WooError(WooErrorType.GENERIC_ERROR, BaseRequest.GenericErrorType.UNKNOWN) - whenever(packageRepository.fetchAllStorePackages()).thenReturn(WooResult(error)) + val site = SiteModel().apply { id = 1 } + whenever(selectedSite.getOrNull()).thenReturn(site) + whenever(packageRepository.fetchAllStorePackages(site)).thenReturn(WooResult(error)) - val result = fetchPredefinedPackagesFromStore() + val result = fetchPredefinedPackagesFromStore()!! assertThat(result.savedPackageSelection.packages).isEmpty() assertThat(result.carrierPackageSelection.carrierPackages).isEmpty() From f95322e5120ef6d779dd128cead530b0d1054f12 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 17:51:58 -0300 Subject: [PATCH 24/41] Fix lint issues --- .../FetchPredefinedPackagesFromStoreTest.kt | 74 ++++++++++--------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt index bff2b1f0f9d..3c724ba1545 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt @@ -2,17 +2,19 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource import com.woocommerce.android.tools.SelectedSite import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.Carrier +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageGroup +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData import com.woocommerce.android.viewmodel.BaseUnitTest -import org.mockito.kotlin.whenever -import org.wordpress.android.fluxc.network.BaseRequest -import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooError -import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooErrorType -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.* import kotlinx.coroutines.ExperimentalCoroutinesApi import org.assertj.core.api.Assertions.assertThat import org.junit.Test import org.mockito.kotlin.mock +import org.mockito.kotlin.whenever import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.fluxc.network.BaseRequest +import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooError +import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooErrorType import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooResult @OptIn(ExperimentalCoroutinesApi::class) @@ -27,36 +29,7 @@ class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { @Test fun `invoke should return StorePredefinedPackages with carrier and saved packages`() = testBlocking { - val storePackages = StorePackagesDAO( - savedPackages = listOf( - PackageDAO( - id = "1", - name = "Saved Package 1", - dimensions = "dimensions" - ), - PackageDAO( - id = "2", - name = "Saved Package 2", - dimensions = "dimensions" - ) - ), - carrierPackages = mapOf( - CarrierType.USPS to CarrierDAO( - packageGroup = listOf( - CarrierPackageGroupDAO( - description = "Group 1", - packages = listOf( - PackageDAO( - id = "1", - name = "Carrier Package 1", - dimensions = "dimensions" - ) - ) - ) - ) - ) - ) - ) + val storePackages = generatePackagesData() val site = SiteModel().apply { id = 1 } whenever(selectedSite.getOrNull()).thenReturn(site) whenever(packageRepository.fetchAllStorePackages(site)).thenReturn(WooResult(storePackages)) @@ -113,4 +86,35 @@ class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { assertThat(result.savedPackageSelection.packages).isEmpty() assertThat(result.carrierPackageSelection.carrierPackages).isEmpty() } + + private fun generatePackagesData() = StorePackagesDAO( + savedPackages = listOf( + PackageDAO( + id = "1", + name = "Saved Package 1", + dimensions = "dimensions" + ), + PackageDAO( + id = "2", + name = "Saved Package 2", + dimensions = "dimensions" + ) + ), + carrierPackages = mapOf( + CarrierType.USPS to CarrierDAO( + packageGroup = listOf( + CarrierPackageGroupDAO( + description = "Group 1", + packages = listOf( + PackageDAO( + id = "1", + name = "Carrier Package 1", + dimensions = "dimensions" + ) + ) + ) + ) + ) + ) + ) } From 033d7e845d597a47cc395f19b3c5b7bf768fc6b5 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 17:52:52 -0300 Subject: [PATCH 25/41] Refactor FetchPredefinedPackagesFromStore --- .../FetchPredefinedPackagesFromStore.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt index d9c09bf4a22..b345725fe89 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt @@ -17,18 +17,16 @@ class FetchPredefinedPackagesFromStore @Inject constructor( suspend operator fun invoke(): StorePredefinedPackages? { val site = selectedSite.getOrNull() ?: return null val storePackages = packageRepository.fetchAllStorePackages(site) - - val carrierPackages = storePackages .takeIf { it.isError.not() } ?.model - ?.filterCarrierData() - ?: emptyMap() + ?: return null + + val carrierPackages = storePackages + .filterCarrierData() val savedPackages = storePackages - .takeIf { it.isError.not() } - ?.model - ?.savedPackages - ?.map { packageDAO -> + .savedPackages + .map { packageDAO -> PackageData( type = PackageType.BOX, name = packageDAO.name, @@ -38,7 +36,7 @@ class FetchPredefinedPackagesFromStore @Inject constructor( height = "", isSelected = false ) - } ?: emptyList() + } return StorePredefinedPackages( carrierPackageSelection = CarrierPackageSelection(carrierPackages), From 3467d30fc41d7644c3b33266777f0d54ddd04a16 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 17:56:04 -0300 Subject: [PATCH 26/41] Further refactor FetchPredefinedPackagesFromStore --- .../FetchPredefinedPackagesFromStore.kt | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt index b345725fe89..9f137bed655 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt @@ -15,35 +15,35 @@ class FetchPredefinedPackagesFromStore @Inject constructor( private val packageRepository: WooShippingLabelPackageRepository ) { suspend operator fun invoke(): StorePredefinedPackages? { - val site = selectedSite.getOrNull() ?: return null - val storePackages = packageRepository.fetchAllStorePackages(site) - .takeIf { it.isError.not() } + val storePackages = selectedSite.getOrNull() + ?.let { packageRepository.fetchAllStorePackages(it) } + ?.takeIf { it.isError.not() } ?.model ?: return null - val carrierPackages = storePackages - .filterCarrierData() - - val savedPackages = storePackages - .savedPackages - .map { packageDAO -> - PackageData( - type = PackageType.BOX, - name = packageDAO.name, - description = "", - length = "", - width = "", - height = "", - isSelected = false - ) - } - return StorePredefinedPackages( - carrierPackageSelection = CarrierPackageSelection(carrierPackages), - savedPackageSelection = SavedPackageSelection(savedPackages) + savedPackageSelection = storePackages + .filterSavedData() + .let { SavedPackageSelection(it) }, + carrierPackageSelection = storePackages + .filterCarrierData() + .let { CarrierPackageSelection(it) } ) } + private fun StorePackagesDAO.filterSavedData() = + savedPackages.map { packageDAO -> + PackageData( + type = PackageType.BOX, + name = packageDAO.name, + description = "", + length = "", + width = "", + height = "", + isSelected = false + ) + } + private fun StorePackagesDAO.filterCarrierData() = mapOf( carrierPackages .parseCarrierData(CarrierType.USPS) From 0a67acd6e3d0b445d6f08b8420b69f357d084610 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 21:06:32 -0300 Subject: [PATCH 27/41] Update FetchPredefinedPackagesFromStoreTest to account for the null response during errors --- .../datasource/FetchPredefinedPackagesFromStoreTest.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt index 3c724ba1545..9dacce9ebdc 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt @@ -81,10 +81,9 @@ class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { whenever(selectedSite.getOrNull()).thenReturn(site) whenever(packageRepository.fetchAllStorePackages(site)).thenReturn(WooResult(error)) - val result = fetchPredefinedPackagesFromStore()!! + val result = fetchPredefinedPackagesFromStore() - assertThat(result.savedPackageSelection.packages).isEmpty() - assertThat(result.carrierPackageSelection.carrierPackages).isEmpty() + assertThat(result).isNull() } private fun generatePackagesData() = StorePackagesDAO( From 4c18c793755cb5273c28ad8ad4c26fa91d6704b2 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 28 Nov 2024 21:11:20 -0300 Subject: [PATCH 28/41] Add site nullability handling to FetchPredefinedPackagesFromStoreTest --- .../FetchPredefinedPackagesFromStoreTest.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt index 9dacce9ebdc..0f859a508ac 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt @@ -9,6 +9,7 @@ import com.woocommerce.android.viewmodel.BaseUnitTest import kotlinx.coroutines.ExperimentalCoroutinesApi import org.assertj.core.api.Assertions.assertThat import org.junit.Test +import org.mockito.kotlin.any import org.mockito.kotlin.mock import org.mockito.kotlin.whenever import org.wordpress.android.fluxc.model.SiteModel @@ -75,7 +76,7 @@ class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { } @Test - fun `invoke should return empty StorePredefinedPackages when fetchAllStorePackages returns error`() = testBlocking { + fun `invoke should return null StorePredefinedPackages when fetchAllStorePackages returns error`() = testBlocking { val error = WooError(WooErrorType.GENERIC_ERROR, BaseRequest.GenericErrorType.UNKNOWN) val site = SiteModel().apply { id = 1 } whenever(selectedSite.getOrNull()).thenReturn(site) @@ -86,6 +87,15 @@ class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { assertThat(result).isNull() } + @Test + fun `invoke should return null StorePredefinedPackages when site is not available`() = testBlocking { + whenever(selectedSite.getOrNull()).thenReturn(null) + + val result = fetchPredefinedPackagesFromStore() + + assertThat(result).isNull() + } + private fun generatePackagesData() = StorePackagesDAO( savedPackages = listOf( PackageDAO( From fc6e14287d127b2f4cb5422bb524e665a50ef50d Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Fri, 29 Nov 2024 12:31:38 -0300 Subject: [PATCH 29/41] Fix lint issues --- .../packages/datasource/FetchPredefinedPackagesFromStoreTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt index 0f859a508ac..e4c06c858f8 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt @@ -9,7 +9,6 @@ import com.woocommerce.android.viewmodel.BaseUnitTest import kotlinx.coroutines.ExperimentalCoroutinesApi import org.assertj.core.api.Assertions.assertThat import org.junit.Test -import org.mockito.kotlin.any import org.mockito.kotlin.mock import org.mockito.kotlin.whenever import org.wordpress.android.fluxc.model.SiteModel From a72320fe8301585c25a45a2b507e0d1278f0d6b3 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Fri, 29 Nov 2024 14:59:43 -0300 Subject: [PATCH 30/41] Introduce Predefined Package model and remove specific dimensions from PackageData --- .../wooshippinglabels/packages/ui/UIModels.kt | 78 ++++++++++--------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt index 4a90d90a2b3..f5f2479d6f5 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt @@ -10,14 +10,51 @@ data class PackageData( val type: PackageType, val name: String, val description: String, + val dimensions: String, + val isSelected: Boolean, +) : Parcelable + +@Parcelize +data class PredefinedPackage( + val boxWeight: Double, + val isFlatRate: Boolean, + val id: String, + val name: String, + val dimensions: String, + val maxWeight: Double, + val isLetter: Boolean, + val groupId: String, + val canShipInternational: Boolean +) : Parcelable + +@Parcelize +data class CustomPackageCreationData( + val type: PackageType, val length: String, val width: String, val height: String, - val isSelected: Boolean, - val dimensionUnit: String = "cm" + val saveAsTemplate: Boolean ) : Parcelable { - val dimensionsForDisplay: String - get() = "$length x $width x $height $dimensionUnit" + val isValid: Boolean + get() = height.isNotEmpty() && length.isNotEmpty() && width.isNotEmpty() + + fun toPackageData(dimensionUnit: String = "cm") = PackageData( + type = type, + name = "", + description = "", + dimensions = "$length x $width x $height $dimensionUnit", + isSelected = true + ) + + companion object { + val EMPTY = CustomPackageCreationData( + type = PackageType.BOX, + length = "", + width = "", + height = "", + saveAsTemplate = false + ) + } } @Parcelize @@ -68,36 +105,3 @@ data class SavedPackageSelection( val hasSelection: Boolean get() = packages.find { it.isSelected } != null } - -@Parcelize -data class CustomPackageCreationData( - val type: PackageType, - val length: String, - val width: String, - val height: String, - val saveAsTemplate: Boolean -) : Parcelable { - val isValid: Boolean - get() = height.isNotEmpty() && length.isNotEmpty() && width.isNotEmpty() - - val asPackageData: PackageData - get() = PackageData( - type = type, - name = "", - description = "", - length = length, - width = width, - height = height, - isSelected = true - ) - - companion object { - val EMPTY = CustomPackageCreationData( - type = PackageType.BOX, - length = "", - width = "", - height = "", - saveAsTemplate = false - ) - } -} From e3a8c4daab88c2a630df8cd207014061f6da04a5 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Fri, 29 Nov 2024 15:00:02 -0300 Subject: [PATCH 31/41] Fix UI binding and Preview data --- .../WooShippingLabelPackageCreationScreen.kt | 12 +++------- .../components/WooShippingPackageListItem.kt | 2 +- .../ui/WooShippingCarrierPackageScreen.kt | 24 +++++-------------- .../ui/WooShippingSavedPackageScreen.kt | 12 +++------- 4 files changed, 13 insertions(+), 37 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt index edf667dd05f..6b5b2969bc8 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt @@ -130,27 +130,21 @@ fun WooShippingLabelsPackageCreationScreenPreview() { type = PackageType.ENVELOPE, name = "Small Flat Rate Box", description = "USPS Priority Mail Flat Rate Boxes", - length = "10", - width = "10", - height = "10", + dimensions = "10 x 10 x 10 cm", isSelected = true ), PackageData( type = PackageType.BOX, name = "Small Flat Rate Box", description = "Custom package", - length = "20", - width = "20", - height = "20", + dimensions = "20 x 20 x 20 cm", isSelected = false ), PackageData( type = PackageType.BOX, name = "Small Flat Rate Box", description = "DHL Express", - length = "30", - width = "30", - height = "30", + dimensions = "30 x 30 x 30 cm", isSelected = false ) ), diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/components/WooShippingPackageListItem.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/components/WooShippingPackageListItem.kt index cab8856f742..df9bd254e87 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/components/WooShippingPackageListItem.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/components/WooShippingPackageListItem.kt @@ -48,7 +48,7 @@ fun WooSavedPackageListItem( style = MaterialTheme.typography.body1 ) Text( - text = packageData.dimensionsForDisplay, + text = packageData.dimensions, style = MaterialTheme.typography.body2 ) } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt index 1a5c89cc89e..796f3b8e1ce 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt @@ -234,18 +234,14 @@ fun WooShippingCarrierPackageScreenPreview() { type = PackageType.BOX, name = "Package 1 - Carrier 1", description = "Description 1", - length = "10", - width = "10", - height = "10", + dimensions = "10 x 10 x 10 cm", isSelected = false ), PackageData( type = PackageType.BOX, name = "Package 2 - Carrier 1", description = "Description 2", - length = "20", - width = "20", - height = "20", + dimensions = "20 x 20 x 20 cm", isSelected = false ) ) @@ -257,18 +253,14 @@ fun WooShippingCarrierPackageScreenPreview() { type = PackageType.BOX, name = "Package 3 - Carrier 1", description = "Description 3", - length = "30", - width = "30", - height = "30", + dimensions = "30 x 30 x 30 cm", isSelected = false ), PackageData( type = PackageType.BOX, name = "Package 4 - Carrier 1", description = "Description 4", - length = "40", - width = "40", - height = "40", + dimensions = "40 x 40 x 40 cm", isSelected = false ) ) @@ -282,18 +274,14 @@ fun WooShippingCarrierPackageScreenPreview() { type = PackageType.BOX, name = "Package 1 - Carrier 2", description = "Description 1", - length = "10", - width = "10", - height = "10", + dimensions = "10 x 10 x 10 cm", isSelected = false ), PackageData( type = PackageType.BOX, name = "Package 2 Carrier - 2", description = "Description 2", - length = "20", - width = "20", - height = "20", + dimensions = "20 x 20 x 20 cm", isSelected = false ) ) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt index 5f225660179..f4e6a1038d3 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt @@ -84,27 +84,21 @@ fun WooShippingSavedPackageScreenPreview() { type = PackageType.ENVELOPE, name = "Small Flat Rate Box", description = "USPS Priority Mail Flat Rate Boxes", - length = "10", - width = "10", - height = "10", + dimensions = "10 x 10 x 10 cm", isSelected = true ), PackageData( type = PackageType.BOX, name = "Small Flat Rate Box", description = "Custom package", - length = "20", - width = "20", - height = "20", + dimensions = "20 x 20 x 20 cm", isSelected = false ), PackageData( type = PackageType.BOX, name = "Small Flat Rate Box", description = "DHL Express", - length = "30", - width = "30", - height = "30", + dimensions = "30 x 30 x 30 cm", isSelected = false ) ), From 61081e6724ae44913b5ec2476cc61635eafec350 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Fri, 29 Nov 2024 15:02:12 -0300 Subject: [PATCH 32/41] Correctly map the dimensions data into the PackageData model --- .../datasource/FetchPredefinedPackagesFromStore.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt index 9f137bed655..7f448bef9c3 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt @@ -37,9 +37,7 @@ class FetchPredefinedPackagesFromStore @Inject constructor( type = PackageType.BOX, name = packageDAO.name, description = "", - length = "", - width = "", - height = "", + dimensions = packageDAO.dimensions, isSelected = false ) } @@ -65,9 +63,7 @@ class FetchPredefinedPackagesFromStore @Inject constructor( type = PackageType.BOX, name = packageItem.name, description = "", - length = "", - width = "", - height = "", + dimensions = packageItem.dimensions, isSelected = false ) } From 67ebadb02347407369ebc09ce0228d9238b476fc Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Fri, 29 Nov 2024 15:02:22 -0300 Subject: [PATCH 33/41] Fix build error when using the PackageData parsing --- .../packages/WooShippingLabelPackageCreationViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index aec3425fa69..46df8e85ff4 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -99,7 +99,7 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( fun onAddCustomPackageClick() { _viewState.value.customPackageCreationData - .asPackageData + .toPackageData() .let { triggerEvent(PackageSelected(it)) } } From 1f8277293cc526da22906e9bf58d45fbb2ad5097 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Fri, 29 Nov 2024 15:11:57 -0300 Subject: [PATCH 34/41] Add isLetter field mapping to PackageDAOs.kt --- .../wooshippinglabels/packages/datasource/PackageDAOs.kt | 3 ++- .../packages/datasource/WooShippingLabelPackageMapper.kt | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt index 767c95687a0..1e37f06efd5 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt @@ -8,7 +8,8 @@ data class StorePackagesDAO( data class PackageDAO( val id: String, val name: String, - val dimensions: String + val dimensions: String, + val isLetter: Boolean ) data class CarrierDAO( diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt index 8d4a6a0c291..3ea362d7fea 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt @@ -23,7 +23,8 @@ class WooShippingLabelPackageMapper @Inject constructor() { PackageDAO( id = it.id.orEmpty(), name = it.name.orEmpty(), - dimensions = it.dimensions.orEmpty() + dimensions = it.dimensions.orEmpty(), + isLetter = it.isLetter ?: false ) } } @@ -58,7 +59,8 @@ class WooShippingLabelPackageMapper @Inject constructor() { PackageDAO( id = it.id.orEmpty(), name = it.name.orEmpty(), - dimensions = it.dimensions.orEmpty() + dimensions = it.dimensions.orEmpty(), + isLetter = it.isLetter ?: false ) } ?: emptyList() ) From 260b048b84554bb6986d8311672bae8672723781 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Fri, 29 Nov 2024 15:12:18 -0300 Subject: [PATCH 35/41] Remove PackageType from PackageData and leave it an exclusive field to Custom packages --- .../ui/orders/wooshippinglabels/packages/ui/UIModels.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt index f5f2479d6f5..550e59c4bb1 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt @@ -7,11 +7,11 @@ import kotlinx.parcelize.Parcelize @Parcelize data class PackageData( - val type: PackageType, val name: String, val description: String, val dimensions: String, val isSelected: Boolean, + val isLetter: Boolean ) : Parcelable @Parcelize @@ -39,11 +39,11 @@ data class CustomPackageCreationData( get() = height.isNotEmpty() && length.isNotEmpty() && width.isNotEmpty() fun toPackageData(dimensionUnit: String = "cm") = PackageData( - type = type, name = "", description = "", dimensions = "$length x $width x $height $dimensionUnit", - isSelected = true + isSelected = true, + isLetter = type == PackageType.ENVELOPE ) companion object { From 91876280679bbdcb2e44de25a737d7ef15b36310 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Fri, 29 Nov 2024 15:12:38 -0300 Subject: [PATCH 36/41] Map isLetter field from DAOs into the PackageData --- .../datasource/FetchPredefinedPackagesFromStore.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt index 7f448bef9c3..f8c72c70449 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt @@ -34,11 +34,11 @@ class FetchPredefinedPackagesFromStore @Inject constructor( private fun StorePackagesDAO.filterSavedData() = savedPackages.map { packageDAO -> PackageData( - type = PackageType.BOX, name = packageDAO.name, description = "", dimensions = packageDAO.dimensions, - isSelected = false + isSelected = false, + isLetter = packageDAO.isLetter ) } @@ -60,11 +60,11 @@ class FetchPredefinedPackagesFromStore @Inject constructor( groupName = group.description, packages = group.packages.map { packageItem -> PackageData( - type = PackageType.BOX, name = packageItem.name, description = "", dimensions = packageItem.dimensions, - isSelected = false + isSelected = false, + isLetter = packageItem.isLetter ) } ) From f16543114e413d4b296c9f7534ef0cfb65f95411 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Fri, 29 Nov 2024 15:12:51 -0300 Subject: [PATCH 37/41] Fix UI Previews using direct PackageType --- .../WooShippingLabelPackageCreationScreen.kt | 12 +++++----- .../ui/WooShippingCarrierPackageScreen.kt | 24 +++++++++---------- .../ui/WooShippingSavedPackageScreen.kt | 12 +++++----- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt index 6b5b2969bc8..7379cf2ce6b 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt @@ -127,25 +127,25 @@ fun WooShippingLabelsPackageCreationScreenPreview() { WooShippingSavedPackageScreen( savedPackages = listOf( PackageData( - type = PackageType.ENVELOPE, name = "Small Flat Rate Box", description = "USPS Priority Mail Flat Rate Boxes", dimensions = "10 x 10 x 10 cm", - isSelected = true + isSelected = true, + isLetter = true ), PackageData( - type = PackageType.BOX, name = "Small Flat Rate Box", description = "Custom package", dimensions = "20 x 20 x 20 cm", - isSelected = false + isSelected = false, + isLetter = false ), PackageData( - type = PackageType.BOX, name = "Small Flat Rate Box", description = "DHL Express", dimensions = "30 x 30 x 30 cm", - isSelected = false + isSelected = false, + isLetter = false ) ), isAddPackageEnabled = true, diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt index 796f3b8e1ce..5f1a0f3eaec 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt @@ -231,18 +231,18 @@ fun WooShippingCarrierPackageScreenPreview() { groupName = "Group 1", packages = listOf( PackageData( - type = PackageType.BOX, name = "Package 1 - Carrier 1", description = "Description 1", dimensions = "10 x 10 x 10 cm", - isSelected = false + isSelected = false, + isLetter = false ), PackageData( - type = PackageType.BOX, name = "Package 2 - Carrier 1", description = "Description 2", dimensions = "20 x 20 x 20 cm", - isSelected = false + isSelected = false, + isLetter = false ) ) ), @@ -250,18 +250,18 @@ fun WooShippingCarrierPackageScreenPreview() { groupName = "Group 2", packages = listOf( PackageData( - type = PackageType.BOX, name = "Package 3 - Carrier 1", description = "Description 3", dimensions = "30 x 30 x 30 cm", - isSelected = false + isSelected = false, + isLetter = false ), PackageData( - type = PackageType.BOX, name = "Package 4 - Carrier 1", description = "Description 4", dimensions = "40 x 40 x 40 cm", - isSelected = false + isSelected = false, + isLetter = false ) ) ) @@ -271,18 +271,18 @@ fun WooShippingCarrierPackageScreenPreview() { groupName = "Group 2", packages = listOf( PackageData( - type = PackageType.BOX, name = "Package 1 - Carrier 2", description = "Description 1", dimensions = "10 x 10 x 10 cm", - isSelected = false + isSelected = false, + isLetter = false ), PackageData( - type = PackageType.BOX, name = "Package 2 Carrier - 2", description = "Description 2", dimensions = "20 x 20 x 20 cm", - isSelected = false + isSelected = false, + isLetter = false ) ) ) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt index f4e6a1038d3..785ba569161 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt @@ -81,25 +81,25 @@ fun WooShippingSavedPackageScreenPreview() { WooShippingSavedPackageScreen( savedPackages = listOf( PackageData( - type = PackageType.ENVELOPE, name = "Small Flat Rate Box", description = "USPS Priority Mail Flat Rate Boxes", dimensions = "10 x 10 x 10 cm", - isSelected = true + isSelected = true, + isLetter = true ), PackageData( - type = PackageType.BOX, name = "Small Flat Rate Box", description = "Custom package", dimensions = "20 x 20 x 20 cm", - isSelected = false + isSelected = false, + isLetter = false ), PackageData( - type = PackageType.BOX, name = "Small Flat Rate Box", description = "DHL Express", dimensions = "30 x 30 x 30 cm", - isSelected = false + isSelected = false, + isLetter = false ) ), isAddPackageEnabled = true, From 7d51913e601672a4e87168ec40799ec7cf4875a2 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Fri, 29 Nov 2024 15:15:16 -0300 Subject: [PATCH 38/41] Fix lint issues --- .../packages/WooShippingLabelPackageCreationScreen.kt | 1 - .../packages/datasource/FetchPredefinedPackagesFromStore.kt | 1 - .../packages/ui/WooShippingCarrierPackageScreen.kt | 1 - .../packages/ui/WooShippingSavedPackageScreen.kt | 1 - 4 files changed, 4 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt index 7379cf2ce6b..5595a785508 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt @@ -21,7 +21,6 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PageTab import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PageType.CARRIER import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PageType.CUSTOM diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt index f8c72c70449..d8cbce97be7 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt @@ -1,7 +1,6 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource import com.woocommerce.android.tools.SelectedSite -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.Carrier import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageGroup import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageSelection diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt index 5f1a0f3eaec..b58e6d2f4dd 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt @@ -40,7 +40,6 @@ import androidx.compose.ui.unit.dp import com.woocommerce.android.R import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import com.woocommerce.android.ui.orders.wooshippinglabels.packages.components.WooSavedPackageListItem import kotlinx.coroutines.launch diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt index 785ba569161..ef078e9b305 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt @@ -18,7 +18,6 @@ import androidx.compose.ui.unit.dp import com.woocommerce.android.R import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import com.woocommerce.android.ui.orders.wooshippinglabels.packages.components.WooSavedPackageListItem @Composable From ea0312c872660b7ce1557064acd1aca982affe92 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Fri, 29 Nov 2024 15:21:24 -0300 Subject: [PATCH 39/41] Fix packages unit test build errors --- ...ippingLabelPackageCreationViewModelTest.kt | 66 +++++++------------ .../FetchPredefinedPackagesFromStoreTest.kt | 34 +++++----- 2 files changed, 40 insertions(+), 60 deletions(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt index f3585c13bdd..f83174b1a76 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt @@ -71,7 +71,7 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { sut.onAddCustomPackageClick() - assertThat(lastEvent).isEqualTo(PackageSelected(customPackageData.asPackageData)) + assertThat(lastEvent).isEqualTo(PackageSelected(customPackageData.toPackageData())) } @Test @@ -141,22 +141,18 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { fun `onSavedPackageSelected selects only one package at a time`() = testBlocking { var lastViewState: ViewState? = null val package1 = PackageData( - type = PackageType.BOX, name = "Package 1", description = "Description 1", - length = "10", - width = "10", - height = "10", - isSelected = false + dimensions = "10 x 10 x 10 cm", + isSelected = false, + isLetter = false ) val package2 = PackageData( - type = PackageType.ENVELOPE, name = "Package 2", description = "Description 2", - length = "20", - width = "20", - height = "20", - isSelected = false + dimensions = "20 x 20 x 20 cm", + isSelected = false, + isLetter = true ) whenever(fetchPredefinedPackages()).thenReturn( StorePredefinedPackages( @@ -186,22 +182,18 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { var lastViewState: ViewState? = null val carrier: Carrier = Carrier.DHL val package1 = PackageData( - type = PackageType.BOX, name = "Package 1", description = "Description 1", - length = "10", - width = "10", - height = "10", - isSelected = false + dimensions = "10 x 10 x 10 cm", + isSelected = false, + isLetter = false ) val package2 = PackageData( - type = PackageType.ENVELOPE, name = "Package 2", description = "Description 2", - length = "20", - width = "20", - height = "20", - isSelected = false + dimensions = "20 x 20 x 20 cm", + isSelected = false, + isLetter = true ) val carrierPackages = mapOf( carrier to listOf( @@ -243,40 +235,32 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { val carrier1: Carrier = Carrier.DHL val carrier2: Carrier = Carrier.USPS val package1 = PackageData( - type = PackageType.BOX, name = "Package 1 - Carrier 1", description = "Description 1", - length = "10", - width = "10", - height = "10", - isSelected = false + dimensions = "10 x 10 x 10 cm", + isSelected = false, + isLetter = false ) val package2 = PackageData( - type = PackageType.ENVELOPE, name = "Package 2 - Carrier 1", description = "Description 2", - length = "20", - width = "20", - height = "20", - isSelected = false + dimensions = "20 x 20 x 20 cm", + isSelected = false, + isLetter = true ) val package3 = PackageData( - type = PackageType.BOX, name = "Package 1 - Carrier 2", description = "Description 3", - length = "30", - width = "30", - height = "30", - isSelected = false + dimensions = "30 x 30 x 30 cm", + isSelected = false, + isLetter = false ) val package4 = PackageData( - type = PackageType.ENVELOPE, name = "Package 2 - Carrier 2", description = "Description 4", - length = "40", - width = "40", - height = "40", - isSelected = false + dimensions = "40 x 40 x 40 cm", + isSelected = false, + isLetter = true ) val carrierPackages = mapOf( carrier1 to listOf( diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt index e4c06c858f8..0860f18a18e 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt @@ -1,7 +1,6 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource import com.woocommerce.android.tools.SelectedSite -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.Carrier import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageGroup import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData @@ -38,22 +37,18 @@ class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { assertThat(result.savedPackageSelection.packages).containsExactly( PackageData( - type = PackageType.BOX, name = "Saved Package 1", description = "", - length = "", - width = "", - height = "", - isSelected = false + dimensions = "", + isSelected = false, + isLetter = false ), PackageData( - type = PackageType.BOX, name = "Saved Package 2", description = "", - length = "", - width = "", - height = "", - isSelected = false + dimensions = "", + isSelected = false, + isLetter = false ) ) assertThat(result.carrierPackageSelection.carrierPackages[Carrier.USPS]).containsExactly( @@ -61,13 +56,11 @@ class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { groupName = "Group 1", packages = listOf( PackageData( - type = PackageType.BOX, name = "Carrier Package 1", description = "", - length = "", - width = "", - height = "", - isSelected = false + dimensions = "", + isSelected = false, + isLetter = false ) ) ) @@ -100,12 +93,14 @@ class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { PackageDAO( id = "1", name = "Saved Package 1", - dimensions = "dimensions" + dimensions = "dimensions", + isLetter = false ), PackageDAO( id = "2", name = "Saved Package 2", - dimensions = "dimensions" + dimensions = "dimensions", + isLetter = false ) ), carrierPackages = mapOf( @@ -117,7 +112,8 @@ class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { PackageDAO( id = "1", name = "Carrier Package 1", - dimensions = "dimensions" + dimensions = "dimensions", + isLetter = false ) ) ) From 391447fa12f0683b210a3c32ea9c2bd228accb01 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Fri, 29 Nov 2024 15:22:17 -0300 Subject: [PATCH 40/41] Fix incorrect FetchPredefinedPackagesFromStoreTest mock data --- .../datasource/FetchPredefinedPackagesFromStoreTest.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt index 0860f18a18e..16dafc6d8ed 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt @@ -39,14 +39,14 @@ class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { PackageData( name = "Saved Package 1", description = "", - dimensions = "", + dimensions = "dimensions", isSelected = false, isLetter = false ), PackageData( name = "Saved Package 2", description = "", - dimensions = "", + dimensions = "dimensions", isSelected = false, isLetter = false ) @@ -58,7 +58,7 @@ class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { PackageData( name = "Carrier Package 1", description = "", - dimensions = "", + dimensions = "dimensions", isSelected = false, isLetter = false ) From 4d99c069df592e7c5a7a7ef35fb9b8e2dd4034b6 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Fri, 29 Nov 2024 15:40:17 -0300 Subject: [PATCH 41/41] Remove description field from PackageData --- .../packages/WooShippingLabelPackageCreationScreen.kt | 3 --- .../packages/components/WooShippingPackageListItem.kt | 3 ++- .../datasource/FetchPredefinedPackagesFromStore.kt | 2 -- .../orders/wooshippinglabels/packages/ui/UIModels.kt | 10 +++++++--- .../packages/ui/WooShippingCarrierPackageScreen.kt | 6 ------ .../packages/ui/WooShippingSavedPackageScreen.kt | 3 --- .../WooShippingLabelPackageCreationViewModelTest.kt | 8 -------- .../datasource/FetchPredefinedPackagesFromStoreTest.kt | 3 --- 8 files changed, 9 insertions(+), 29 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt index 5595a785508..be2d715990a 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt @@ -127,21 +127,18 @@ fun WooShippingLabelsPackageCreationScreenPreview() { savedPackages = listOf( PackageData( name = "Small Flat Rate Box", - description = "USPS Priority Mail Flat Rate Boxes", dimensions = "10 x 10 x 10 cm", isSelected = true, isLetter = true ), PackageData( name = "Small Flat Rate Box", - description = "Custom package", dimensions = "20 x 20 x 20 cm", isSelected = false, isLetter = false ), PackageData( name = "Small Flat Rate Box", - description = "DHL Express", dimensions = "30 x 30 x 30 cm", isSelected = false, isLetter = false diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/components/WooShippingPackageListItem.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/components/WooShippingPackageListItem.kt index df9bd254e87..a14de381e29 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/components/WooShippingPackageListItem.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/components/WooShippingPackageListItem.kt @@ -12,6 +12,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.colorResource +import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.woocommerce.android.R import com.woocommerce.android.ui.compose.component.SelectionCheck @@ -39,7 +40,7 @@ fun WooSavedPackageListItem( ) Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { Text( - text = packageData.description, + text = stringResource(id = packageData.descriptionResId), style = MaterialTheme.typography.caption, color = colorResource(id = R.color.color_on_surface_disabled) ) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt index d8cbce97be7..42155986aec 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt @@ -34,7 +34,6 @@ class FetchPredefinedPackagesFromStore @Inject constructor( savedPackages.map { packageDAO -> PackageData( name = packageDAO.name, - description = "", dimensions = packageDAO.dimensions, isSelected = false, isLetter = packageDAO.isLetter @@ -60,7 +59,6 @@ class FetchPredefinedPackagesFromStore @Inject constructor( packages = group.packages.map { packageItem -> PackageData( name = packageItem.name, - description = "", dimensions = packageItem.dimensions, isSelected = false, isLetter = packageItem.isLetter diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt index 550e59c4bb1..9971cbe781a 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt @@ -8,11 +8,16 @@ import kotlinx.parcelize.Parcelize @Parcelize data class PackageData( val name: String, - val description: String, val dimensions: String, val isSelected: Boolean, val isLetter: Boolean -) : Parcelable +) : Parcelable { + val descriptionResId: Int + get() = when (isLetter) { + true -> R.string.woo_shipping_labels_package_creation_envelope_type + false -> R.string.woo_shipping_labels_package_creation_box_type + } +} @Parcelize data class PredefinedPackage( @@ -40,7 +45,6 @@ data class CustomPackageCreationData( fun toPackageData(dimensionUnit: String = "cm") = PackageData( name = "", - description = "", dimensions = "$length x $width x $height $dimensionUnit", isSelected = true, isLetter = type == PackageType.ENVELOPE diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt index b58e6d2f4dd..e105d5f4c78 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt @@ -231,14 +231,12 @@ fun WooShippingCarrierPackageScreenPreview() { packages = listOf( PackageData( name = "Package 1 - Carrier 1", - description = "Description 1", dimensions = "10 x 10 x 10 cm", isSelected = false, isLetter = false ), PackageData( name = "Package 2 - Carrier 1", - description = "Description 2", dimensions = "20 x 20 x 20 cm", isSelected = false, isLetter = false @@ -250,14 +248,12 @@ fun WooShippingCarrierPackageScreenPreview() { packages = listOf( PackageData( name = "Package 3 - Carrier 1", - description = "Description 3", dimensions = "30 x 30 x 30 cm", isSelected = false, isLetter = false ), PackageData( name = "Package 4 - Carrier 1", - description = "Description 4", dimensions = "40 x 40 x 40 cm", isSelected = false, isLetter = false @@ -271,14 +267,12 @@ fun WooShippingCarrierPackageScreenPreview() { packages = listOf( PackageData( name = "Package 1 - Carrier 2", - description = "Description 1", dimensions = "10 x 10 x 10 cm", isSelected = false, isLetter = false ), PackageData( name = "Package 2 Carrier - 2", - description = "Description 2", dimensions = "20 x 20 x 20 cm", isSelected = false, isLetter = false diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt index ef078e9b305..29577581f72 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingSavedPackageScreen.kt @@ -81,21 +81,18 @@ fun WooShippingSavedPackageScreenPreview() { savedPackages = listOf( PackageData( name = "Small Flat Rate Box", - description = "USPS Priority Mail Flat Rate Boxes", dimensions = "10 x 10 x 10 cm", isSelected = true, isLetter = true ), PackageData( name = "Small Flat Rate Box", - description = "Custom package", dimensions = "20 x 20 x 20 cm", isSelected = false, isLetter = false ), PackageData( name = "Small Flat Rate Box", - description = "DHL Express", dimensions = "30 x 30 x 30 cm", isSelected = false, isLetter = false diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt index f83174b1a76..a5c3cd6ea21 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt @@ -142,14 +142,12 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { var lastViewState: ViewState? = null val package1 = PackageData( name = "Package 1", - description = "Description 1", dimensions = "10 x 10 x 10 cm", isSelected = false, isLetter = false ) val package2 = PackageData( name = "Package 2", - description = "Description 2", dimensions = "20 x 20 x 20 cm", isSelected = false, isLetter = true @@ -183,14 +181,12 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { val carrier: Carrier = Carrier.DHL val package1 = PackageData( name = "Package 1", - description = "Description 1", dimensions = "10 x 10 x 10 cm", isSelected = false, isLetter = false ) val package2 = PackageData( name = "Package 2", - description = "Description 2", dimensions = "20 x 20 x 20 cm", isSelected = false, isLetter = true @@ -236,28 +232,24 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { val carrier2: Carrier = Carrier.USPS val package1 = PackageData( name = "Package 1 - Carrier 1", - description = "Description 1", dimensions = "10 x 10 x 10 cm", isSelected = false, isLetter = false ) val package2 = PackageData( name = "Package 2 - Carrier 1", - description = "Description 2", dimensions = "20 x 20 x 20 cm", isSelected = false, isLetter = true ) val package3 = PackageData( name = "Package 1 - Carrier 2", - description = "Description 3", dimensions = "30 x 30 x 30 cm", isSelected = false, isLetter = false ) val package4 = PackageData( name = "Package 2 - Carrier 2", - description = "Description 4", dimensions = "40 x 40 x 40 cm", isSelected = false, isLetter = true diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt index 16dafc6d8ed..0a6bc832511 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt @@ -38,14 +38,12 @@ class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { assertThat(result.savedPackageSelection.packages).containsExactly( PackageData( name = "Saved Package 1", - description = "", dimensions = "dimensions", isSelected = false, isLetter = false ), PackageData( name = "Saved Package 2", - description = "", dimensions = "dimensions", isSelected = false, isLetter = false @@ -57,7 +55,6 @@ class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { packages = listOf( PackageData( name = "Carrier Package 1", - description = "", dimensions = "dimensions", isSelected = false, isLetter = false