Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Product Variation Attributes] Do not use ignore case when renaming attributes #12608

Merged
merged 5 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading