From 2ccc66a554aa93f00e4629adcd6cedf0b26a4d8c Mon Sep 17 00:00:00 2001 From: Fabio Insolia Date: Wed, 26 Jun 2024 10:19:44 +0100 Subject: [PATCH 1/6] feature/PIMOB-2639_Fix_for_phone_numeber_on_RTL_languages --- .../utils/extensions/BillingAddressExtensions.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/frames/src/main/java/com/checkout/frames/utils/extensions/BillingAddressExtensions.kt b/frames/src/main/java/com/checkout/frames/utils/extensions/BillingAddressExtensions.kt index 8aff57f3..7f47a85a 100644 --- a/frames/src/main/java/com/checkout/frames/utils/extensions/BillingAddressExtensions.kt +++ b/frames/src/main/java/com/checkout/frames/utils/extensions/BillingAddressExtensions.kt @@ -1,5 +1,7 @@ package com.checkout.frames.utils.extensions +import android.text.BidiFormatter +import android.text.TextDirectionHeuristics import com.checkout.frames.screen.billingaddress.billingaddressdetails.models.BillingAddress import java.util.Locale @@ -23,13 +25,13 @@ internal fun BillingAddress.summary(): String { // Phone this.phone?.let { phone -> if (phone.number.isNotEmpty()) { - strBuilder.append( - if (phone.country?.dialingCode?.isNotEmpty() == true) { - "\n+${phone.country?.dialingCode} ${phone.number}" - } else { - "\n${phone.number}" - }, - ) + val bidiFormatter = BidiFormatter.getInstance() + val phoneText = if (phone.country?.dialingCode?.isNotEmpty() == true) { + bidiFormatter.unicodeWrap("+${phone.country?.dialingCode} ${phone.number}", TextDirectionHeuristics.LTR) + } else { + bidiFormatter.unicodeWrap(phone.number, TextDirectionHeuristics.LTR) + } + strBuilder.append("\n$phoneText") } } From b40c02e4d1135a32e8dc664621e2add37f13fffa Mon Sep 17 00:00:00 2001 From: Fabio Insolia Date: Wed, 26 Jun 2024 10:49:54 +0100 Subject: [PATCH 2/6] Fix for unit test --- .../utils/extensions/BillingAddressExtensions.kt | 3 +-- .../utils/extensions/BillingAddressExtensionsTest.kt | 10 +++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/frames/src/main/java/com/checkout/frames/utils/extensions/BillingAddressExtensions.kt b/frames/src/main/java/com/checkout/frames/utils/extensions/BillingAddressExtensions.kt index 7f47a85a..eb0e9a22 100644 --- a/frames/src/main/java/com/checkout/frames/utils/extensions/BillingAddressExtensions.kt +++ b/frames/src/main/java/com/checkout/frames/utils/extensions/BillingAddressExtensions.kt @@ -5,7 +5,7 @@ import android.text.TextDirectionHeuristics import com.checkout.frames.screen.billingaddress.billingaddressdetails.models.BillingAddress import java.util.Locale -internal fun BillingAddress.summary(): String { +internal fun BillingAddress.summary(bidiFormatter: BidiFormatter = BidiFormatter.getInstance()): String { val strBuilder = StringBuilder() // Full name @@ -25,7 +25,6 @@ internal fun BillingAddress.summary(): String { // Phone this.phone?.let { phone -> if (phone.number.isNotEmpty()) { - val bidiFormatter = BidiFormatter.getInstance() val phoneText = if (phone.country?.dialingCode?.isNotEmpty() == true) { bidiFormatter.unicodeWrap("+${phone.country?.dialingCode} ${phone.number}", TextDirectionHeuristics.LTR) } else { diff --git a/frames/src/test/java/com/checkout/frames/utils/extensions/BillingAddressExtensionsTest.kt b/frames/src/test/java/com/checkout/frames/utils/extensions/BillingAddressExtensionsTest.kt index 021697ba..a92c0e71 100644 --- a/frames/src/test/java/com/checkout/frames/utils/extensions/BillingAddressExtensionsTest.kt +++ b/frames/src/test/java/com/checkout/frames/utils/extensions/BillingAddressExtensionsTest.kt @@ -1,11 +1,16 @@ package com.checkout.frames.utils.extensions import android.annotation.SuppressLint +import android.text.BidiFormatter +import android.text.TextDirectionHeuristics import com.checkout.base.model.Country import com.checkout.frames.screen.billingaddress.billingaddressdetails.models.BillingAddress import com.checkout.tokenization.model.Address import com.checkout.tokenization.model.Phone +import io.mockk.every +import io.mockk.impl.annotations.MockK import io.mockk.junit5.MockKExtension +import io.mockk.mockk import org.amshove.kluent.internal.assertEquals import org.junit.jupiter.api.extension.ExtendWith import org.junit.jupiter.params.ParameterizedTest @@ -17,6 +22,8 @@ import java.util.stream.Stream @ExtendWith(MockKExtension::class) internal class BillingAddressExtensionsTest { + private val bidiFormatter: BidiFormatter = mockk() + @ParameterizedTest( name = "When summary of billing address {0} is requested then addressPreview {1} is provided", ) @@ -26,7 +33,8 @@ internal class BillingAddressExtensionsTest { expectedAddressPreview: String, ) { // When - val result = billingAddress.summary() + every { bidiFormatter.unicodeWrap(any(), TextDirectionHeuristics.LTR) } returns "+44 123" + val result = billingAddress.summary(bidiFormatter) // Then assertEquals(expectedAddressPreview, result) From 88b07cdb1f4edbfa3f627b5c4ea7b5a436b0d44c Mon Sep 17 00:00:00 2001 From: Fabio Insolia Date: Wed, 26 Jun 2024 12:22:47 +0100 Subject: [PATCH 3/6] Fix for unit test round 2 --- build.gradle.kts | 76 +++++++++---------- .../addresssummary/AddressSummaryViewModel.kt | 5 +- .../AddressSummaryViewModelTest.kt | 11 ++- 3 files changed, 50 insertions(+), 42 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 05efa267..0c084d9a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,4 @@ -import com.vanniktech.code.quality.tools.CodeQualityToolsPluginExtension +//import com.vanniktech.code.quality.tools.CodeQualityToolsPluginExtension import org.jetbrains.dokka.gradle.DokkaMultiModuleTask // Top-level build file where you can add configuration options common to all sub-projects/modules. @@ -12,7 +12,7 @@ buildscript { dependencies { classpath(ProjectDependencies.androidGradlePlugin) classpath(ProjectDependencies.kotlinGradlePlugin) - classpath(ProjectDependencies.codeQualityToolsPlugin) +// classpath(ProjectDependencies.codeQualityToolsPlugin) classpath(ProjectDependencies.dokkaPlugin) classpath(ProjectDependencies.dokkaKotlinPlugin) @@ -49,42 +49,42 @@ tasks.register("clean", Delete::class) { /* Code quality tools config */ -apply(plugin = ProjectDependencies.codeQualityTools) - -configure { - failEarly = true - xmlReports = false - htmlReports = true - textReports = false - ignoreProjects = listOf("buildSrc", "app") - - checkstyle { - enabled = false - } - pmd { - enabled = false - } - lint { - enabled = true - baselineFileName = "lint-baseline.xml" - } - ktlint { - enabled = true - toolVersion = Versions.ktlint - } - detekt { - enabled = true - toolVersion = Versions.detect - config = "code_quality_tools/detekt.yml" - failFast = true - } - cpd { - enabled = false - } - kotlin { - allWarningsAsErrors = true - } -} +//apply(plugin = ProjectDependencies.codeQualityTools) +// +//configure { +// failEarly = true +// xmlReports = false +// htmlReports = true +// textReports = false +// ignoreProjects = listOf("buildSrc", "app") +// +// checkstyle { +// enabled = false +// } +// pmd { +// enabled = false +// } +// lint { +// enabled = true +// baselineFileName = "lint-baseline.xml" +// } +// ktlint { +// enabled = true +// toolVersion = Versions.ktlint +// } +// detekt { +// enabled = true +// toolVersion = Versions.detect +// config = "code_quality_tools/detekt.yml" +// failFast = true +// } +// cpd { +// enabled = false +// } +// kotlin { +// allWarningsAsErrors = true +// } +//} /* Documentation config */ diff --git a/frames/src/main/java/com/checkout/frames/component/addresssummary/AddressSummaryViewModel.kt b/frames/src/main/java/com/checkout/frames/component/addresssummary/AddressSummaryViewModel.kt index 4ab187b2..6f5f3824 100644 --- a/frames/src/main/java/com/checkout/frames/component/addresssummary/AddressSummaryViewModel.kt +++ b/frames/src/main/java/com/checkout/frames/component/addresssummary/AddressSummaryViewModel.kt @@ -1,5 +1,6 @@ package com.checkout.frames.component.addresssummary +import android.text.BidiFormatter import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope @@ -26,13 +27,13 @@ internal class AddressSummaryViewModel @Inject constructor( val componentState = provideState(style) val componentStyle = provideViewStyle(style) - fun prepare() = viewModelScope.launch { + fun prepare(bidiFormatter: BidiFormatter = BidiFormatter.getInstance()) = viewModelScope.launch { paymentStateManager.billingAddress.collect { billingAddress -> componentState.addressPreviewState.text.value = if (paymentStateManager.billingAddress.value.isEdited() && paymentStateManager.isBillingAddressEnabled.value ) { - billingAddress.summary() + billingAddress.summary(bidiFormatter) } else { "" } diff --git a/frames/src/test/java/com/checkout/frames/component/addresssummary/AddressSummaryViewModelTest.kt b/frames/src/test/java/com/checkout/frames/component/addresssummary/AddressSummaryViewModelTest.kt index 3306dcd1..6cba87a0 100644 --- a/frames/src/test/java/com/checkout/frames/component/addresssummary/AddressSummaryViewModelTest.kt +++ b/frames/src/test/java/com/checkout/frames/component/addresssummary/AddressSummaryViewModelTest.kt @@ -1,6 +1,8 @@ package com.checkout.frames.component.addresssummary import android.annotation.SuppressLint +import android.text.BidiFormatter +import android.text.TextDirectionHeuristics import com.checkout.base.mapper.Mapper import com.checkout.base.model.Country import com.checkout.frames.mapper.BillingFormAddressToBillingAddressMapper @@ -25,8 +27,10 @@ import com.checkout.frames.style.view.InternalButtonViewStyle import com.checkout.frames.style.view.addresssummary.AddressSummaryComponentViewStyle import com.checkout.tokenization.model.Address import com.checkout.tokenization.model.Phone +import io.mockk.every import io.mockk.impl.annotations.SpyK import io.mockk.junit5.MockKExtension +import io.mockk.mockk import io.mockk.verify import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -46,6 +50,8 @@ import org.junit.jupiter.api.extension.ExtendWith @ExtendWith(MockKExtension::class) internal class AddressSummaryViewModelTest { + private val bidiFormatter: BidiFormatter = mockk() + @SpyK private lateinit var spyBillingFormAddressToBillingAddressMapper: Mapper @@ -125,11 +131,12 @@ internal class AddressSummaryViewModelTest { ), phone = Phone("123", country), ) + every { bidiFormatter.unicodeWrap(any(), TextDirectionHeuristics.LTR) } returns "+44 123" val expectedAddressPreview = "LINE 1\nLINE 2\nssdfsdf\nUnited Kingdom\n+44 123" spyPaymentStateManager.billingAddress.value = testAddress // When - viewModel.prepare() + viewModel.prepare(bidiFormatter) testScheduler.advanceUntilIdle() // Then @@ -145,7 +152,7 @@ internal class AddressSummaryViewModelTest { spyPaymentStateManager.isBillingAddressEnabled.value = false // When - viewModel.prepare() + viewModel.prepare(bidiFormatter) testScheduler.advanceUntilIdle() // Then From 7235bb1673b26e3dcea84627f4b29383bd8778e8 Mon Sep 17 00:00:00 2001 From: Fabio Insolia Date: Wed, 26 Jun 2024 12:24:20 +0100 Subject: [PATCH 4/6] Revert for vanniktech --- build.gradle.kts | 76 ++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 0c084d9a..05efa267 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,4 @@ -//import com.vanniktech.code.quality.tools.CodeQualityToolsPluginExtension +import com.vanniktech.code.quality.tools.CodeQualityToolsPluginExtension import org.jetbrains.dokka.gradle.DokkaMultiModuleTask // Top-level build file where you can add configuration options common to all sub-projects/modules. @@ -12,7 +12,7 @@ buildscript { dependencies { classpath(ProjectDependencies.androidGradlePlugin) classpath(ProjectDependencies.kotlinGradlePlugin) -// classpath(ProjectDependencies.codeQualityToolsPlugin) + classpath(ProjectDependencies.codeQualityToolsPlugin) classpath(ProjectDependencies.dokkaPlugin) classpath(ProjectDependencies.dokkaKotlinPlugin) @@ -49,42 +49,42 @@ tasks.register("clean", Delete::class) { /* Code quality tools config */ -//apply(plugin = ProjectDependencies.codeQualityTools) -// -//configure { -// failEarly = true -// xmlReports = false -// htmlReports = true -// textReports = false -// ignoreProjects = listOf("buildSrc", "app") -// -// checkstyle { -// enabled = false -// } -// pmd { -// enabled = false -// } -// lint { -// enabled = true -// baselineFileName = "lint-baseline.xml" -// } -// ktlint { -// enabled = true -// toolVersion = Versions.ktlint -// } -// detekt { -// enabled = true -// toolVersion = Versions.detect -// config = "code_quality_tools/detekt.yml" -// failFast = true -// } -// cpd { -// enabled = false -// } -// kotlin { -// allWarningsAsErrors = true -// } -//} +apply(plugin = ProjectDependencies.codeQualityTools) + +configure { + failEarly = true + xmlReports = false + htmlReports = true + textReports = false + ignoreProjects = listOf("buildSrc", "app") + + checkstyle { + enabled = false + } + pmd { + enabled = false + } + lint { + enabled = true + baselineFileName = "lint-baseline.xml" + } + ktlint { + enabled = true + toolVersion = Versions.ktlint + } + detekt { + enabled = true + toolVersion = Versions.detect + config = "code_quality_tools/detekt.yml" + failFast = true + } + cpd { + enabled = false + } + kotlin { + allWarningsAsErrors = true + } +} /* Documentation config */ From 8eb57aa588245666d32cb9b8e4e5e441282a2570 Mon Sep 17 00:00:00 2001 From: Fabio Insolia Date: Wed, 26 Jun 2024 12:27:30 +0100 Subject: [PATCH 5/6] Nit for bidiFormatter --- .../frames/utils/extensions/BillingAddressExtensions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frames/src/main/java/com/checkout/frames/utils/extensions/BillingAddressExtensions.kt b/frames/src/main/java/com/checkout/frames/utils/extensions/BillingAddressExtensions.kt index eb0e9a22..839ea387 100644 --- a/frames/src/main/java/com/checkout/frames/utils/extensions/BillingAddressExtensions.kt +++ b/frames/src/main/java/com/checkout/frames/utils/extensions/BillingAddressExtensions.kt @@ -5,7 +5,7 @@ import android.text.TextDirectionHeuristics import com.checkout.frames.screen.billingaddress.billingaddressdetails.models.BillingAddress import java.util.Locale -internal fun BillingAddress.summary(bidiFormatter: BidiFormatter = BidiFormatter.getInstance()): String { +internal fun BillingAddress.summary(bidiFormatter: BidiFormatter): String { val strBuilder = StringBuilder() // Full name From 44e4028796ec13cd26603dbf03cf5fe6964990d6 Mon Sep 17 00:00:00 2001 From: Fabio Insolia Date: Wed, 26 Jun 2024 12:39:25 +0100 Subject: [PATCH 6/6] Removing unused import --- .../frames/utils/extensions/BillingAddressExtensionsTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/frames/src/test/java/com/checkout/frames/utils/extensions/BillingAddressExtensionsTest.kt b/frames/src/test/java/com/checkout/frames/utils/extensions/BillingAddressExtensionsTest.kt index a92c0e71..44e1e17d 100644 --- a/frames/src/test/java/com/checkout/frames/utils/extensions/BillingAddressExtensionsTest.kt +++ b/frames/src/test/java/com/checkout/frames/utils/extensions/BillingAddressExtensionsTest.kt @@ -8,7 +8,6 @@ import com.checkout.frames.screen.billingaddress.billingaddressdetails.models.Bi import com.checkout.tokenization.model.Address import com.checkout.tokenization.model.Phone import io.mockk.every -import io.mockk.impl.annotations.MockK import io.mockk.junit5.MockKExtension import io.mockk.mockk import org.amshove.kluent.internal.assertEquals