Skip to content

Commit

Permalink
Merge pull request #12608 from woocommerce/issue/12561-fix-renaming-a…
Browse files Browse the repository at this point in the history
…ttribute

[Product Variation Attributes] Do not use ignore case when renaming attributes
  • Loading branch information
toupper committed Sep 16, 2024
2 parents d1eb9ed + baa7dea commit 5eb3cd9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

20.5
-----
- [*] Fixes a bug that prevented users to rename the Product Variation Attributes to because of case insensitive checks [https://github.com/woocommerce/woocommerce-android/pull/12608]
- [*] Users can directly pick product images when creating Blaze ads [https://github.com/woocommerce/woocommerce-android/pull/12610]

20.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,7 @@ class ProductDetailViewModel @Inject constructor(
fun renameAttributeInDraft(attributeId: Long, oldAttributeName: String, newAttributeName: String): Boolean {
// first make sure an attribute with the new name doesn't already exist in the draft
productDraftAttributes.forEach {
if (it.name.equals(newAttributeName, ignoreCase = true)) {
if (it.name.equals(newAttributeName)) {
triggerEvent(ShowSnackbar(R.string.product_attribute_name_already_exists))
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.woocommerce.android.analytics.AnalyticsTrackerWrapper
import com.woocommerce.android.extensions.takeIfNotEqualTo
import com.woocommerce.android.media.MediaFilesRepository
import com.woocommerce.android.media.ProductImagesServiceWrapper
import com.woocommerce.android.model.ProductAttribute
import com.woocommerce.android.model.ProductVariation
import com.woocommerce.android.tools.NetworkStatus
import com.woocommerce.android.tools.SelectedSite
Expand Down Expand Up @@ -742,6 +743,37 @@ class ProductDetailViewModelTest : BaseUnitTest() {
Assertions.assertThat(draftTerms[1]).isEqualTo(firstTerm)
}

@Test
fun `Re-name attribute terms is saved correctly`() = testBlocking {
viewModel.productDetailViewStateData.observeForever { _, _ -> }
val attributeName = "name"
val newName = attributeName.replaceFirstChar { it.uppercase() }

val attributes = ArrayList<ProductAttribute>()
attributes.add(
ProductAttribute(
id = 1,
name = attributeName,
isVariation = true,
isVisible = true,
terms = ArrayList<String>().also {
it.add("one")
}
)
)

val storedProduct = product.copy(
attributes = attributes
)
doReturn(storedProduct).whenever(productRepository).getProductAsync(any())

viewModel.start()
viewModel.renameAttributeInDraft(1, attributeName, newName)

val draftAttribute = viewModel.productDraftAttributes[0]
Assertions.assertThat(draftAttribute.name).isEqualTo(newName)
}

/**
* Protection for a race condition bug in Variations.
*
Expand Down

0 comments on commit 5eb3cd9

Please sign in to comment.