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

[WOO POS] UI tests for product info dialog on the products screen #12711

Draft
wants to merge 10 commits into
base: issue/12377-ui-tests-for-simple-products-banner
Choose a base branch
from
Draft
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
@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.onNodeWithContentDescription
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 WooPosHomeProductInfoDialogTest : TestBase() {
@get:Rule(order = 1)
val rule = HiltAndroidRule(this)

@get:Rule(order = 2)
val composeTestRule = createAndroidComposeRule<ComponentActivity>()

@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<Preferences>

@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 testProductInfoDialogIconIsDisplayedOnProductsScreenIfSimpleProductsBannerIsNotVisible() = runTest {
composeTestRule.waitUntil(5000) {
try {
composeTestRule.onNodeWithTag("product_list")
.assertExists()
.assertIsDisplayed()
true
} catch (e: AssertionError) {
e.printStackTrace()
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)
)
.assertIsDisplayed()
true
}
}

@Test
fun testProductInfoDialogIsDisplayedOnIconClick() = runTest {
composeTestRule.waitUntil(5000) {
try {
composeTestRule.onNodeWithTag("product_list")
.assertExists()
.assertIsDisplayed()
true
} catch (e: AssertionError) {
e.printStackTrace()
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")
.assertIsDisplayed()
true
}
}

@Test
fun testProductInfoDialogIsDisplayedWithProperLabels() = runTest {
composeTestRule.waitUntil(5000) {
try {
composeTestRule.onNodeWithTag("product_list")
.assertExists()
.assertIsDisplayed()
true
} catch (e: AssertionError) {
e.printStackTrace()
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.onNodeWithText(
composeTestRule.activity.getString(R.string.woopos_dialog_products_info_heading)
)
.assertIsDisplayed()
true
}

composeTestRule.onNodeWithText(
composeTestRule.activity.getString(R.string.woopos_dialog_products_info_primary_message)
)
.assertIsDisplayed()
composeTestRule.onNodeWithText(
composeTestRule.activity.getString(R.string.woopos_dialog_products_info_secondary_message)
)
.assertIsDisplayed()
composeTestRule.onNodeWithText(
composeTestRule.activity.getString(R.string.woopos_dialog_products_info_button_label)
)
.assertIsDisplayed()
}

@Test
fun testProductInfoDialogIsDismissedWhenCloseClick() = runTest {
composeTestRule.waitUntil(5000) {
try {
composeTestRule.onNodeWithTag("product_list")
.assertExists()
.assertIsDisplayed()
true
} catch (e: AssertionError) {
e.printStackTrace()
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.onNodeWithContentDescription(
composeTestRule.activity.getString(R.string.woopos_banner_simple_products_close_content_description)
).performClick()

composeTestRule.waitUntil(5000) {
composeTestRule.onNodeWithTag(
"woo_pos_product_info_dialog"
).assertIsNotDisplayed()
true
}
}

@Test
fun testProductInfoDialogIsDismissedWhenPrimaryButtonClicked() = runTest {
composeTestRule.waitUntil(5000) {
try {
composeTestRule.onNodeWithTag("product_list")
.assertExists()
.assertIsDisplayed()
true
} catch (e: AssertionError) {
e.printStackTrace()
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)
)
.assertExists()
true
}

composeTestRule.onNodeWithContentDescription(
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
)
).performClick()

composeTestRule.waitUntil(5000) {
composeTestRule.onNodeWithTag("woo_pos_product_info_dialog")
.assertDoesNotExist()
true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag

@Composable
fun WooPosBackgroundOverlay(
Expand All @@ -22,7 +23,8 @@ fun WooPosBackgroundOverlay(
AnimatedVisibility(
visible = isVisible,
enter = fadeIn(initialAlpha = 0.3f),
exit = fadeOut(targetAlpha = 0.0f)
exit = fadeOut(targetAlpha = 0.0f),
modifier = modifier.testTag("woo_pos_product_info_dialog_background")
) {
Box(
modifier = modifier
Expand Down
Loading