diff --git a/WooCommerce/src/androidTest/kotlin/com/woocommerce/android/WooPosExitPosDialogTest.kt b/WooCommerce/src/androidTest/kotlin/com/woocommerce/android/WooPosExitPosDialogTest.kt new file mode 100644 index 00000000000..1205880816e --- /dev/null +++ b/WooCommerce/src/androidTest/kotlin/com/woocommerce/android/WooPosExitPosDialogTest.kt @@ -0,0 +1,277 @@ +@file:Suppress("DEPRECATION") + +package com.woocommerce.android + +import androidx.activity.ComponentActivity +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.assertIsNotDisplayed +import androidx.compose.ui.test.junit4.createAndroidComposeRule +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import androidx.datastore.core.DataStore +import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.core.edit +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.rule.ActivityTestRule +import com.woocommerce.android.e2e.helpers.InitializationRule +import com.woocommerce.android.e2e.helpers.TestBase +import com.woocommerce.android.e2e.rules.RetryTestRule +import com.woocommerce.android.e2e.screens.TabNavComponent +import com.woocommerce.android.e2e.screens.login.WelcomeScreen +import com.woocommerce.android.ui.login.LoginActivity +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest +import kotlinx.coroutines.test.runTest +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import javax.inject.Inject + +@HiltAndroidTest +@RunWith(AndroidJUnit4::class) +class WooPosExitPosDialogTest : TestBase() { + @get:Rule(order = 1) + val rule = HiltAndroidRule(this) + + @get:Rule(order = 2) + val composeTestRule = createAndroidComposeRule() + + @get:Rule(order = 3) + val initRule = InitializationRule() + + @get:Rule(order = 4) + var activityRule = ActivityTestRule(LoginActivity::class.java) + + @get:Rule(order = 5) + var retryTestRule = RetryTestRule() + + @Inject + lateinit var dataStore: DataStore + + @Before + fun setUp() = runTest { + rule.inject() + dataStore.edit { it.clear() } + WelcomeScreen + .skipCarouselIfNeeded() + .selectLogin() + .proceedWith(BuildConfig.SCREENSHOTS_URL) + .proceedWith(BuildConfig.SCREENSHOTS_USERNAME) + .proceedWith(BuildConfig.SCREENSHOTS_PASSWORD) + + TabNavComponent() + .gotoMoreMenuScreen() + .openPOSScreen(composeTestRule) + } + + @Test + fun testExitPOSConfirmationDialogIsDisplayedWhenExitButtonClicked() = runTest { + composeTestRule.waitUntil(5000) { + try { + composeTestRule.onNodeWithTag("product_list") + .assertExists() + .assertIsDisplayed() + true + } catch (e: AssertionError) { + e.printStackTrace() + false + } + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithTag( + "woo_pos_menu_button" + ).performClick() + true + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithTag( + "woo_pos_popup_menu_${R.string.woopos_exit_confirmation_title}", + useUnmergedTree = true + ).performClick() + true + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithTag("woo_pos_exit_confirmation_dialog") + .assertExists() + .assertIsDisplayed() + true + } + } + + @Test + fun testExitPOSConfirmationDialogIsDisplayedWithProperLabels() = runTest { + composeTestRule.waitUntil(5000) { + try { + composeTestRule.onNodeWithTag("product_list") + .assertExists() + .assertIsDisplayed() + true + } catch (e: AssertionError) { + e.printStackTrace() + false + } + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithTag( + "woo_pos_menu_button" + ).performClick() + true + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithTag( + "woo_pos_popup_menu_${R.string.woopos_exit_confirmation_title}", + useUnmergedTree = true + ).performClick() + true + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithText( + composeTestRule.activity.getString(R.string.woopos_exit_dialog_confirmation_title) + ).assertIsDisplayed() + true + } + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithText( + composeTestRule.activity.getString(R.string.woopos_exit_dialog_confirmation_message) + ).assertIsDisplayed() + true + } + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithText( + composeTestRule.activity.getString(R.string.woopos_exit_dialog_confirmation_confirm_button) + ).assertIsDisplayed() + true + } + } + + @Test + fun testExitPOSConfirmationDialogIsDismissedWhenCloseButtonClicked() = runTest { + composeTestRule.waitUntil(5000) { + try { + composeTestRule.onNodeWithTag("product_list") + .assertExists() + .assertIsDisplayed() + true + } catch (e: AssertionError) { + e.printStackTrace() + false + } + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithTag( + "woo_pos_menu_button" + ).performClick() + true + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithTag( + "woo_pos_popup_menu_${R.string.woopos_exit_confirmation_title}", + useUnmergedTree = true + ).performClick() + true + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithTag("woo_pos_exit_confirmation_dialog_close").performClick() + true + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithTag("woo_pos_exit_confirmation_dialog") + .assertIsNotDisplayed() + true + } + } + + @Test + fun testExitPOSConfirmationDialogIsDismissedWhenExitButtonClicked() = runTest { + composeTestRule.waitUntil(5000) { + try { + composeTestRule.onNodeWithTag("product_list") + .assertExists() + .assertIsDisplayed() + true + } catch (e: AssertionError) { + e.printStackTrace() + false + } + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithTag( + "woo_pos_menu_button" + ).performClick() + true + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithTag( + "woo_pos_popup_menu_${R.string.woopos_exit_confirmation_title}", + useUnmergedTree = true + ).performClick() + true + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithTag("woo_pos_exit_confirmation_dialog_exit").performClick() + true + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithTag("woo_pos_exit_confirmation_dialog") + .assertIsNotDisplayed() + true + } + } + + @Test + fun testWoPosHomeScreenIsDismissedWhenExitButtonClicked() = runTest { + composeTestRule.waitUntil(5000) { + try { + composeTestRule.onNodeWithTag("product_list") + .assertExists() + .assertIsDisplayed() + true + } catch (e: AssertionError) { + e.printStackTrace() + false + } + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithTag( + "woo_pos_menu_button" + ).performClick() + true + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithTag( + "woo_pos_popup_menu_${R.string.woopos_exit_confirmation_title}", + useUnmergedTree = true + ).performClick() + true + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithTag("woo_pos_exit_confirmation_dialog_exit").performClick() + true + } + + composeTestRule.waitUntil(5000) { + composeTestRule.onNodeWithTag("woo_pos_home_screen") + .assertIsNotDisplayed() + true + } + } +} diff --git a/WooCommerce/src/androidTest/kotlin/com/woocommerce/android/WooPosHomeProductInfoDialogTest.kt b/WooCommerce/src/androidTest/kotlin/com/woocommerce/android/WooPosHomeProductInfoDialogTest.kt index 0f0020307c4..cd8d62c9391 100644 --- a/WooCommerce/src/androidTest/kotlin/com/woocommerce/android/WooPosHomeProductInfoDialogTest.kt +++ b/WooCommerce/src/androidTest/kotlin/com/woocommerce/android/WooPosHomeProductInfoDialogTest.kt @@ -76,6 +76,7 @@ class WooPosHomeProductInfoDialogTest : TestBase() { .assertIsDisplayed() true } catch (e: AssertionError) { + e.printStackTrace() false } } @@ -94,8 +95,7 @@ class WooPosHomeProductInfoDialogTest : TestBase() { } @Test - fun testProductInfoDialogIsDisplayedOnIconClick() = runTest { - + fun testProductInfoDialogIsDisplayedOnIconClick() = runTest { composeTestRule.waitUntil(5000) { try { composeTestRule.onNodeWithTag("product_list") @@ -103,6 +103,7 @@ class WooPosHomeProductInfoDialogTest : TestBase() { .assertIsDisplayed() true } catch (e: AssertionError) { + e.printStackTrace() false } } @@ -134,16 +135,17 @@ class WooPosHomeProductInfoDialogTest : TestBase() { .assertIsDisplayed() true } catch (e: AssertionError) { + e.printStackTrace() false } } - composeTestRule.onNodeWithContentDescription( - composeTestRule.activity.getString(R.string.woopos_banner_simple_products_close_content_description) + composeTestRule.onNodeWithTag( + "woo_pos_simple_products_dialog_info_close_icon" ).performClick() composeTestRule.waitUntil(5000) { - composeTestRule.onNodeWithContentDescription( - composeTestRule.activity.getString(R.string.woopos_banner_simple_products_info_content_description) + composeTestRule.onNodeWithTag( + "woo_pos_simple_products_banner_icon" ).performClick() true } @@ -171,8 +173,7 @@ class WooPosHomeProductInfoDialogTest : TestBase() { } @Test - fun testProductInfoDialogIsDismissedWhenCloseClick() = runTest { - + fun testProductInfoDialogIsDismissedWhenCloseClick() = runTest { composeTestRule.waitUntil(5000) { try { composeTestRule.onNodeWithTag("product_list") @@ -180,6 +181,7 @@ class WooPosHomeProductInfoDialogTest : TestBase() { .assertIsDisplayed() true } catch (e: AssertionError) { + e.printStackTrace() false } } @@ -194,8 +196,8 @@ class WooPosHomeProductInfoDialogTest : TestBase() { true } - composeTestRule.onNodeWithContentDescription( - composeTestRule.activity.getString(R.string.woopos_banner_simple_products_close_content_description) + composeTestRule.onNodeWithTag( + "woo_pos_simple_products_dialog_info_close_icon" ).performClick() composeTestRule.waitUntil(5000) { @@ -207,8 +209,7 @@ class WooPosHomeProductInfoDialogTest : TestBase() { } @Test - fun testProductInfoDialogIsDismissedWhenPrimaryButtonClicked() = runTest { - + fun testProductInfoDialogIsDismissedWhenPrimaryButtonClicked() = runTest { composeTestRule.waitUntil(5000) { try { composeTestRule.onNodeWithTag("product_list") @@ -216,6 +217,7 @@ class WooPosHomeProductInfoDialogTest : TestBase() { .assertIsDisplayed() true } catch (e: AssertionError) { + e.printStackTrace() false } } @@ -226,7 +228,7 @@ class WooPosHomeProductInfoDialogTest : TestBase() { composeTestRule.waitUntil(5000) { composeTestRule.onNodeWithContentDescription( composeTestRule.activity.getString(R.string.woopos_banner_simple_products_info_content_description) - ) + ) .assertExists() true } @@ -235,10 +237,8 @@ class WooPosHomeProductInfoDialogTest : TestBase() { composeTestRule.activity.getString(R.string.woopos_banner_simple_products_info_content_description) ).performClick() - composeTestRule.onNodeWithContentDescription( - composeTestRule.activity.getString( - R.string.woopos_banner_simple_products_dialog_primary_button_content_description - ) + composeTestRule.onNodeWithTag( + "woo_pos_simple_product_info_dialog_primary_button" ).performClick() composeTestRule.waitUntil(5000) { @@ -247,41 +247,4 @@ class WooPosHomeProductInfoDialogTest : TestBase() { true } } - - @Test - fun testProductInfoDialogIsDismissedWhenOutsideDialogClicked() = runTest { - - composeTestRule.waitUntil(5000) { - try { - composeTestRule.onNodeWithTag("product_list") - .assertExists() - .assertIsDisplayed() - true - } catch (e: AssertionError) { - false - } - } - composeTestRule.onNodeWithContentDescription( - composeTestRule.activity.getString(R.string.woopos_banner_simple_products_close_content_description) - ).performClick() - - composeTestRule.waitUntil(5000) { - composeTestRule.onNodeWithContentDescription( - composeTestRule.activity.getString(R.string.woopos_banner_simple_products_info_content_description) - ).performClick() - true - } - - composeTestRule.waitUntil(5000) { - composeTestRule.onNodeWithTag("woo_pos_product_info_dialog_background") - .performClick() - true - } - - composeTestRule.waitUntil(5000) { - composeTestRule.onNodeWithTag("woo_pos_product_info_dialog") - .assertIsNotDisplayed() - true - } - } } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/common/composeui/component/WooPosExitConfirmationDialog.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/common/composeui/component/WooPosExitConfirmationDialog.kt index 5a56c937e25..366a96afa7f 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/common/composeui/component/WooPosExitConfirmationDialog.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/common/composeui/component/WooPosExitConfirmationDialog.kt @@ -16,6 +16,7 @@ import androidx.compose.material.icons.filled.Close import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp @@ -45,7 +46,9 @@ fun WooPosExitConfirmationDialog( onDismissRequest = onDismissRequest, ) { Box( - modifier = modifier.padding(40.dp.toAdaptivePadding()) + modifier = modifier + .padding(40.dp.toAdaptivePadding()) + .testTag("woo_pos_exit_confirmation_dialog") ) { Column(horizontalAlignment = Alignment.CenterHorizontally) { Spacer(modifier = modifier.height(48.dp.toAdaptivePadding())) @@ -64,7 +67,8 @@ fun WooPosExitConfirmationDialog( Spacer(modifier = modifier.height(56.dp.toAdaptivePadding())) WooPosButton( modifier = modifier - .fillMaxWidth(), + .fillMaxWidth() + .testTag("woo_pos_exit_confirmation_dialog_exit"), onClick = { onExit() }, @@ -76,6 +80,7 @@ fun WooPosExitConfirmationDialog( onClick = { onDismissRequest() }, modifier = modifier .align(Alignment.TopEnd) + .testTag("woo_pos_exit_confirmation_dialog_close") ) { Icon( Icons.Default.Close, diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeProductInfoDialog.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeProductInfoDialog.kt index 30bdaba935c..386aa89a26e 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeProductInfoDialog.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeProductInfoDialog.kt @@ -95,6 +95,7 @@ fun WooPosProductInfoDialog( end.linkTo(parent.end) } .focusable(enabled = false) + .testTag("woo_pos_simple_products_dialog_info_close_icon") ) { Icon( modifier = Modifier @@ -154,7 +155,8 @@ fun WooPosProductInfoDialog( .fillMaxWidth() .semantics { contentDescription = primaryButtonContentDescription - }, + } + .testTag("woo_pos_simple_product_info_dialog_primary_button"), border = BorderStroke(2.dp, MaterialTheme.colors.primary), shape = RoundedCornerShape(8.dp), ) { diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeScreen.kt index 7a36caa040a..f8921fdddc7 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeScreen.kt @@ -22,6 +22,7 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalConfiguration +import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp @@ -127,6 +128,7 @@ private fun WooPosHomeScreen( modifier = Modifier .fillMaxSize() .background(MaterialTheme.colors.background) + .testTag("woo_pos_home_screen") ) { Row( modifier = Modifier diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/products/WooPosProductsScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/products/WooPosProductsScreen.kt index 5ffff112188..5b38c0660d0 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/products/WooPosProductsScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/products/WooPosProductsScreen.kt @@ -193,7 +193,9 @@ private fun ProductsToolbar( is WooPosProductsViewState.Content -> { if (productViewState.bannerState.isBannerHiddenByUser) { IconButton( - modifier = Modifier.size(40.dp), + modifier = Modifier + .size(40.dp) + .testTag("woo_pos_simple_products_banner_icon"), onClick = { onToolbarInfoIconClicked() } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbar.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbar.kt index 6c552ae23cb..9d2e2c9f7e3 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbar.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbar.kt @@ -35,6 +35,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.vectorResource import androidx.compose.ui.semantics.contentDescription @@ -202,7 +203,9 @@ private fun MenuButtonWithPopUpMenu( shape = RoundedCornerShape(8.dp), ) { TextButton( - modifier = Modifier.semantics { contentDescription = menuContentDescription }, + modifier = Modifier + .semantics { contentDescription = menuContentDescription } + .testTag("woo_pos_menu_button"), onClick = onClick, contentPadding = PaddingValues(0.dp), colors = ButtonDefaults.textButtonColors( @@ -262,10 +265,12 @@ private fun PopUpMenuItem( modifier = Modifier.size(24.dp) ) Spacer(modifier = Modifier.width(16.dp.toAdaptivePadding())) + println("popupmenuid: woo_pos_popup_menu_${menuItem.title}") Text( modifier = Modifier .padding(vertical = 8.dp.toAdaptivePadding()) - .weight(1f), + .weight(1f) + .testTag("woo_pos_popup_menu_${menuItem.title}"), text = stringResource(id = menuItem.title), color = MaterialTheme.colors.onSurface, style = MaterialTheme.typography.body1,