From 1fc46a82ec78159f556a81673235619cb62fe66e Mon Sep 17 00:00:00 2001 From: samiuelson Date: Mon, 12 Aug 2024 18:57:56 +0200 Subject: [PATCH 1/4] Declare new origin:point-of-sale --- .../kotlin/com/woocommerce/android/support/help/HelpOrigin.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/support/help/HelpOrigin.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/support/help/HelpOrigin.kt index 506f8532014..fbe54286f0d 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/support/help/HelpOrigin.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/support/help/HelpOrigin.kt @@ -32,7 +32,8 @@ enum class HelpOrigin(private val stringValue: String) { ORDERS_LIST("origin:orders-list"), BLAZE_CAMPAIGN_CREATION("origin:blaze-native-campaign-creation"), CONNECTIVITY_TOOL("origin:connectivity-tool"), - APPLICATION_PASSWORD_TUTORIAL("origin:application-password-tutorial"); + APPLICATION_PASSWORD_TUTORIAL("origin:application-password-tutorial"), + POS("origin:point-of-sale"); override fun toString(): String { return stringValue From 8eafd928869bf2f4898a35bd55372a5f0a66c67f Mon Sep 17 00:00:00 2001 From: samiuelson Date: Mon, 12 Aug 2024 18:59:29 +0200 Subject: [PATCH 2/4] Open `SupportRequestFormActivity` on the menu item tap --- .../home/toolbar/WooPosToolbarViewModel.kt | 4 ++- .../android/ui/woopos/root/WooPosActivity.kt | 4 +++ .../woopos/support/WooPosGetSupportFacade.kt | 31 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/support/WooPosGetSupportFacade.kt diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModel.kt index cdd25daa5f2..ee20b33699c 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModel.kt @@ -14,6 +14,7 @@ import com.woocommerce.android.ui.woopos.home.toolbar.WooPosToolbarUIEvent.Conne import com.woocommerce.android.ui.woopos.home.toolbar.WooPosToolbarUIEvent.MenuItemClicked import com.woocommerce.android.ui.woopos.home.toolbar.WooPosToolbarUIEvent.OnOutsideOfToolbarMenuClicked import com.woocommerce.android.ui.woopos.home.toolbar.WooPosToolbarUIEvent.OnToolbarMenuClicked +import com.woocommerce.android.ui.woopos.support.WooPosGetSupportFacade import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Job import kotlinx.coroutines.delay @@ -26,6 +27,7 @@ import javax.inject.Inject class WooPosToolbarViewModel @Inject constructor( private val cardReaderFacade: WooPosCardReaderFacade, private val childrenToParentEventSender: WooPosChildrenToParentEventSender, + private val getSupportFacade: WooPosGetSupportFacade, ) : ViewModel() { private val _state = MutableStateFlow( WooPosToolbarState( @@ -75,7 +77,7 @@ class WooPosToolbarViewModel @Inject constructor( hideMenu() when (event.menuItem.title) { - R.string.woopos_get_support_title -> TODO() + R.string.woopos_get_support_title -> getSupportFacade.openSupportForm() R.string.woopos_exit_confirmation_title -> viewModelScope.launch { childrenToParentEventSender.sendToParent(ChildToParentEvent.ExitPosClicked) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/root/WooPosActivity.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/root/WooPosActivity.kt index 620d9a2e187..6a4909b20ed 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/root/WooPosActivity.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/root/WooPosActivity.kt @@ -17,6 +17,7 @@ import androidx.compose.ui.graphics.toArgb import androidx.core.view.WindowCompat import com.woocommerce.android.ui.woopos.cardreader.WooPosCardReaderFacade import com.woocommerce.android.ui.woopos.common.composeui.WooPosTheme +import com.woocommerce.android.ui.woopos.support.WooPosGetSupportFacade import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject @@ -24,6 +25,8 @@ import javax.inject.Inject class WooPosActivity : AppCompatActivity() { @Inject lateinit var wooPosCardReaderFacade: WooPosCardReaderFacade + @Inject + lateinit var wooPosGetSupportFacade: WooPosGetSupportFacade override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -31,6 +34,7 @@ class WooPosActivity : AppCompatActivity() { requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE lifecycle.addObserver(wooPosCardReaderFacade) + lifecycle.addObserver(wooPosGetSupportFacade) setContent { WooPosTheme { diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/support/WooPosGetSupportFacade.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/support/WooPosGetSupportFacade.kt new file mode 100644 index 00000000000..06f91120d43 --- /dev/null +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/support/WooPosGetSupportFacade.kt @@ -0,0 +1,31 @@ +package com.woocommerce.android.ui.woopos.support + +import androidx.appcompat.app.AppCompatActivity +import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.LifecycleOwner +import com.woocommerce.android.support.help.HelpOrigin +import com.woocommerce.android.support.requests.SupportRequestFormActivity +import dagger.hilt.android.scopes.ActivityRetainedScoped +import javax.inject.Inject + +@ActivityRetainedScoped +class WooPosGetSupportFacade @Inject constructor(): DefaultLifecycleObserver { + private var activity: AppCompatActivity? = null + + override fun onCreate(owner: LifecycleOwner) { + this.activity = owner as AppCompatActivity + } + + override fun onDestroy(owner: LifecycleOwner) { + this.activity = null + } + + fun openSupportForm() { + val intent = SupportRequestFormActivity.createIntent( + context = activity!!, + origin = HelpOrigin.POS, + extraTags = ArrayList() + ) + activity!!.startActivity(intent) + } +} \ No newline at end of file From bd78fd0830f5e52e2192f1adb3469599d856fb53 Mon Sep 17 00:00:00 2001 From: samiuelson Date: Mon, 12 Aug 2024 19:06:02 +0200 Subject: [PATCH 3/4] Implement unit test --- .../home/toolbar/WooPosToolbarViewModelTest.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt index 2942c4cbad9..cfca68429d2 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt @@ -5,6 +5,7 @@ import com.woocommerce.android.cardreader.connection.CardReaderStatus import com.woocommerce.android.ui.woopos.cardreader.WooPosCardReaderFacade import com.woocommerce.android.ui.woopos.home.ChildToParentEvent import com.woocommerce.android.ui.woopos.home.WooPosChildrenToParentEventSender +import com.woocommerce.android.ui.woopos.support.WooPosGetSupportFacade import com.woocommerce.android.ui.woopos.util.WooPosCoroutineTestRule import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.flowOf @@ -26,6 +27,7 @@ class WooPosToolbarViewModelTest { private val cardReaderFacade: WooPosCardReaderFacade = mock { onBlocking { readerStatus }.thenReturn(flowOf(CardReaderStatus.NotConnected())) } + private val getSupportFacade: WooPosGetSupportFacade = mock() private val childrenToParentEventSender: WooPosChildrenToParentEventSender = mock() @Test @@ -165,8 +167,21 @@ class WooPosToolbarViewModelTest { verify(cardReaderFacade, times(3)).connectToReader() } + @Test + fun `when get support clicked, then should open support form`() { + val viewModel = createViewModel() + + viewModel.onUiEvent(WooPosToolbarUIEvent.MenuItemClicked(WooPosToolbarState.Menu.MenuItem( + title = R.string.woopos_get_support_title, + icon = R.drawable.woopos_ic_get_support, + ))) + + verify(getSupportFacade).openSupportForm() + } + private fun createViewModel() = WooPosToolbarViewModel( cardReaderFacade, - childrenToParentEventSender + childrenToParentEventSender, + getSupportFacade, ) } From bdae47039cfba887871209fe90058bd4bf0f5d06 Mon Sep 17 00:00:00 2001 From: samiuelson Date: Mon, 12 Aug 2024 19:08:47 +0200 Subject: [PATCH 4/4] Satisfy detekt's complaints --- .../android/ui/woopos/root/WooPosActivity.kt | 1 + .../ui/woopos/support/WooPosGetSupportFacade.kt | 4 ++-- .../home/toolbar/WooPosToolbarViewModelTest.kt | 12 ++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/root/WooPosActivity.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/root/WooPosActivity.kt index 6a4909b20ed..21255f0eb2c 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/root/WooPosActivity.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/root/WooPosActivity.kt @@ -25,6 +25,7 @@ import javax.inject.Inject class WooPosActivity : AppCompatActivity() { @Inject lateinit var wooPosCardReaderFacade: WooPosCardReaderFacade + @Inject lateinit var wooPosGetSupportFacade: WooPosGetSupportFacade diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/support/WooPosGetSupportFacade.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/support/WooPosGetSupportFacade.kt index 06f91120d43..7e6e641f479 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/support/WooPosGetSupportFacade.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/support/WooPosGetSupportFacade.kt @@ -9,7 +9,7 @@ import dagger.hilt.android.scopes.ActivityRetainedScoped import javax.inject.Inject @ActivityRetainedScoped -class WooPosGetSupportFacade @Inject constructor(): DefaultLifecycleObserver { +class WooPosGetSupportFacade @Inject constructor() : DefaultLifecycleObserver { private var activity: AppCompatActivity? = null override fun onCreate(owner: LifecycleOwner) { @@ -28,4 +28,4 @@ class WooPosGetSupportFacade @Inject constructor(): DefaultLifecycleObserver { ) activity!!.startActivity(intent) } -} \ No newline at end of file +} diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt index cfca68429d2..26e947b1fa8 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt @@ -171,10 +171,14 @@ class WooPosToolbarViewModelTest { fun `when get support clicked, then should open support form`() { val viewModel = createViewModel() - viewModel.onUiEvent(WooPosToolbarUIEvent.MenuItemClicked(WooPosToolbarState.Menu.MenuItem( - title = R.string.woopos_get_support_title, - icon = R.drawable.woopos_ic_get_support, - ))) + viewModel.onUiEvent( + WooPosToolbarUIEvent.MenuItemClicked( + WooPosToolbarState.Menu.MenuItem( + title = R.string.woopos_get_support_title, + icon = R.drawable.woopos_ic_get_support, + ) + ) + ) verify(getSupportFacade).openSupportForm() }