Skip to content

Commit

Permalink
Merge pull request #10546 from woocommerce/10500-tablet-orders-simula…
Browse files Browse the repository at this point in the history
…te-gift-section-behavior-for-editcreation-mode-the-same-as-on-trunk

[Tablet Orders] Mimic gift section behavior for edit/creation mode the same as on trunk
  • Loading branch information
kidinov authored Jan 18, 2024
2 parents ca24896 + e9f1ee5 commit d6dfbc4
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 19 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
17.2
-----
- [*] [Internal] Tracking of "country" and "currency" properties for entry and exit of the payments flows [https://github.com/woocommerce/woocommerce-android/pull/10528]
- [*] Fixed bug when gift card was not displayed in the "totals" sections on the order creation/editing screens [https://github.com/woocommerce/woocommerce-android/pull/10546]

17.1
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ data class Order(
paymentUrl = "",
isEditable = true,
selectedGiftCard = "",
giftCardDiscountedAmount = BigDecimal(0)
giftCardDiscountedAmount = null
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ import com.woocommerce.android.ui.payments.customamounts.CustomAmountsViewModel.
import com.woocommerce.android.ui.products.selector.ProductSelectorFragment
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.SelectedItem
import com.woocommerce.android.util.CurrencyFormatter
import com.woocommerce.android.util.FeatureFlag
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event.Exit
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event.ShowDialog
Expand Down Expand Up @@ -585,7 +584,6 @@ class OrderCreateEditFormFragment :
private fun OrderCreationAdditionalInfoCollectionSectionBinding.bindGiftCardForOrderCreation(
newOrderData: Order
) {
if (FeatureFlag.ORDER_GIFT_CARD.isEnabled().not()) return
if (newOrderData.selectedGiftCard.isNullOrEmpty()) {
addGiftCardButton.isVisible = viewModel.isGiftCardExtensionEnabled
addGiftCardButton.setOnClickListener { viewModel.onAddGiftCardButtonClicked() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.Sel
import com.woocommerce.android.ui.products.selector.variationIds
import com.woocommerce.android.util.CoroutineDispatchers
import com.woocommerce.android.util.DateUtils
import com.woocommerce.android.util.FeatureFlag
import com.woocommerce.android.viewmodel.LiveDataDelegate
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event.Exit
Expand Down Expand Up @@ -240,7 +239,7 @@ class OrderCreateEditViewModel @Inject constructor(
.combine(_selectedGiftCard) { order, giftCard ->
order.copy(
selectedGiftCard = giftCard,
giftCardDiscountedAmount = -(args.giftCardAmount ?: BigDecimal.ZERO)
giftCardDiscountedAmount = args.giftCardAmount
)
}.asLiveData()

Expand All @@ -254,14 +253,20 @@ class OrderCreateEditViewModel @Inject constructor(
}.asLiveData()

val totalsData: LiveData<TotalsSectionsState> =
viewStateData.liveData.combineWith(_orderDraft.asLiveData()) { viewState, order ->
viewStateData.liveData.combineWith(
_orderDraft.asLiveData(),
_selectedGiftCard.asLiveData()
) { viewState, order, selectedGiftCard ->
totalsHelper.mapToPaymentTotalsState(
order = order!!,
order = order!!.copy(
selectedGiftCard = selectedGiftCard,
giftCardDiscountedAmount = args.giftCardAmount
),
mode = mode,
viewState = viewState!!,
onShippingClicked = { onShippingButtonClicked() },
onCouponsClicked = { onCouponButtonClicked() },
onGiftClicked = { onEditGiftCardButtonClicked(order.selectedGiftCard) },
onGiftClicked = { onEditGiftCardButtonClicked(selectedGiftCard) },
onTaxesLearnMore = { onTaxHelpButtonClicked() },
onMainButtonClicked = { onTotalsSectionPrimaryButtonClicked() },
onExpandCollapseClicked = { onExpandCollapseTotalsClicked(it) }
Expand Down Expand Up @@ -699,8 +704,7 @@ class OrderCreateEditViewModel @Inject constructor(
viewState = viewState.copy(
isAddGiftCardButtonEnabled = order.hasProducts() &&
order.isEditable &&
_selectedGiftCard.value.isEmpty() &&
FeatureFlag.ORDER_GIFT_CARD.isEnabled()
_selectedGiftCard.value.isEmpty()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class OrderCreateEditTotalsHelper @Inject constructor(
if (!selectedGiftCard.isNullOrEmpty()) {
TotalsSectionsState.Line.Button(
text = resourceProvider.getString(R.string.order_gift_card),
value = bigDecimalFormatter(giftCardDiscountedAmount ?: BigDecimal.ZERO),
value = giftCardDiscountedAmount?.let { "-" + bigDecimalFormatter(it) } ?: "",
extraValue = selectedGiftCard,
enabled = enabled,
onClick = onClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class OrderDetailPaymentInfoView @JvmOverloads constructor(
private fun showPaymentSubDetails() {
binding.paymentInfoProductsTotalSection.show()
binding.paymentInfoDiscountSection.show()
binding.paymentInfoGiftCardSection.show()
binding.paymentInfoFeesSection.show()
binding.paymentInfoShippingSection.show()
binding.paymentInfoTaxesSection.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ enum class FeatureFlag {
IAP_FOR_STORE_CREATION,
BETTER_CUSTOMER_SEARCH_M2,
ORDER_CREATION_AUTO_TAX_RATE,
ORDER_GIFT_CARD,
BLAZE_I3;

fun isEnabled(context: Context? = null): Boolean {
Expand All @@ -21,8 +20,6 @@ enum class FeatureFlag {
PackageUtils.isDebugBuild() || context != null && PackageUtils.isBetaBuild(context)
}

ORDER_GIFT_CARD -> true

MORE_MENU_INBOX,
WC_SHIPPING_BANNER,
BETTER_CUSTOMER_SEARCH_M2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class OrderCreateEditTotalsHelperTest {

@Test
@Suppress("LongMethod")
fun `given ff enabled and items not empty, when mapToPaymentTotalsState, then full returned`() {
fun `given items not empty, when mapToPaymentTotalsState, then full returned`() {
// GIVEN
val item = mock<Order.Item> {
on { total }.thenReturn(BigDecimal(11))
Expand Down Expand Up @@ -171,7 +171,7 @@ class OrderCreateEditTotalsHelperTest {
assertThat((actual.lines[3] as TotalsSectionsState.Line.Button).onClick == onCouponsClicked).isTrue()

assertThat((actual.lines[4] as TotalsSectionsState.Line.Button).text).isEqualTo("Gift Cards")
assertThat((actual.lines[4] as TotalsSectionsState.Line.Button).value).isEqualTo("15.00$")
assertThat((actual.lines[4] as TotalsSectionsState.Line.Button).value).isEqualTo("-15.00$")
assertThat((actual.lines[4] as TotalsSectionsState.Line.Button).enabled).isFalse()
assertThat((actual.lines[4] as TotalsSectionsState.Line.Button).extraValue).isEqualTo("21OFF")
assertThat((actual.lines[4] as TotalsSectionsState.Line.Button).onClick == onGiftClicked).isTrue()
Expand All @@ -189,7 +189,7 @@ class OrderCreateEditTotalsHelperTest {
}

@Test
fun `given ff enabled and fee lines not empty, when mapToPaymentTotalsState, then full returned`() {
fun `given fee lines not empty, when mapToPaymentTotalsState, then full returned`() {
// GIVEN
whenever(resourceProvider.getString(R.string.order_creation_collect_payment_button)).thenReturn(
"Collect Payment"
Expand Down Expand Up @@ -221,7 +221,7 @@ class OrderCreateEditTotalsHelperTest {
}

@Test
fun `given ff enabled and items and fee lines empty, when mapToPaymentTotalsState, then minimised returned`() {
fun `given items and fee lines empty, when mapToPaymentTotalsState, then minimised returned`() {
// GIVEN
val localOrder = order.copy(
items = emptyList(),
Expand Down Expand Up @@ -252,4 +252,42 @@ class OrderCreateEditTotalsHelperTest {
assertThat((actual as TotalsSectionsState.Minimised).orderTotal.label).isEqualTo("Order Total")
assertThat(actual.orderTotal.value).isEqualTo("10.00$")
}

@Test
fun `given items not empty and gift amount is null, when mapToPaymentTotalsState, then gift value is empty`() {
// GIVEN
val item = mock<Order.Item> {
on { total }.thenReturn(BigDecimal(11))
}
val localOrder = order.copy(
items = listOf(item),
selectedGiftCard = "21OFF",
giftCardDiscountedAmount = null,
)

whenever(resourceProvider.getString(R.string.order_gift_card)).thenReturn(
"Gift Cards"
)

// WHEN
val actual = helper.mapToPaymentTotalsState(
localOrder,
OrderCreateEditViewModel.Mode.Creation,
OrderCreateEditViewModel.ViewState(),
{},
{},
{},
{},
{},
{},
)

// THEN
actual as TotalsSectionsState.Full

assertThat((actual.lines[1] as TotalsSectionsState.Line.Button).text).isEqualTo("Gift Cards")
assertThat((actual.lines[1] as TotalsSectionsState.Line.Button).value).isEqualTo("")
assertThat((actual.lines[1] as TotalsSectionsState.Line.Button).enabled).isFalse()
assertThat((actual.lines[1] as TotalsSectionsState.Line.Button).extraValue).isEqualTo("21OFF")
}
}

0 comments on commit d6dfbc4

Please sign in to comment.