Skip to content
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 Documentation/style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@ When `behavior.productCard.cardStyle` is `"productDetail"`, product recommendati
| `--product-card-title-font-weight` | `cssLayout.productCardTitleFontWeight` | `Int` | `700` | Title font weight |
| `--product-card-subtitle-font-size` | `cssLayout.productCardSubtitleFontSize` | `Double` | `12.0` | Subtitle font size (sp) |
| `--product-card-subtitle-font-weight` | `cssLayout.productCardSubtitleFontWeight` | `Int` | `400` | Subtitle font weight |
| `--product-card-description-max-lines` | `cssLayout.productCardDescriptionMaxLines` | `Int` | `2` | Maximum description lines before ellipsis. Positive integers set the limit; `none`, zero, negative, or invalid values are ignored and use the default of two lines. For longer descriptions, increase `--product-card-max-height` as needed. |
| `--product-card-price-font-size` | `cssLayout.productCardPriceFontSize` | `Double` | `14.0` | Price font size (sp) |
| `--product-card-price-font-weight` | `cssLayout.productCardPriceFontWeight` | `Int` | `400` | Price font weight |
| `--product-card-badge-font-size` | `cssLayout.productCardBadgeFontSize` | `Double` | `12.0` | Badge font size (sp) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,22 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asAndroidBitmap
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.SemanticsActions
import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.test.assertCountEquals
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.getBoundsInRoot
import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.hasClickAction
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performSemanticsAction
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.unit.dp
import com.adobe.marketing.mobile.concierge.network.MultimodalElement
import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeLayout
Expand Down Expand Up @@ -319,6 +327,128 @@ class ExtendedProductCardTest {
composeTestRule.onNodeWithText("Buy now").assertExists()
}

@Test
fun extendedProductCard_rendersConfiguredSixLineSubtitle_onTallCard() {
val description = listOf(
"Soft cushioning for long runs.",
"Support with every stride.",
"Breathable mesh feels cool.",
"Lightweight heel to toe.",
"Comfortable on any route.",
"Made with recycled fibers."
).joinToString("\n")
val element = MultimodalElement(
id = "six-line-description",
content = mapOf(
"productName" to "Trail Running Shoes",
"productDescription" to description,
"productPrice" to "$99.00"
)
)
val tallCardHeight = 468.dp
val tallCardTheme = ConciergeThemeData(
config = ConciergeThemeConfig(),
tokens = ConciergeThemeTokens(
cssLayout = ConciergeLayout(productCardDescriptionMaxLines = 6)
)
)

composeTestRule.setContent {
ConciergeTheme(theme = tallCardTheme) {
ExtendedProductCard(
element = element,
modifier = Modifier.height(tallCardHeight)
)
}
}

composeTestRule.waitForIdle()
val descriptionNode = composeTestRule.onNodeWithText(description, useUnmergedTree = true)
descriptionNode.assertIsDisplayed()
val descriptionBounds = descriptionNode.getBoundsInRoot()
val descriptionHeight = descriptionBounds.bottom - descriptionBounds.top
assertTrue(
"Expected the description to render all six lines, got $descriptionHeight",
descriptionHeight in 80.dp..90.dp
)
}

@Test
fun extendedProductCard_ellipsizesDescriptionBeyondConfiguredLineLimit() {
val description = (1..8).joinToString("\n") { "Description line $it for this product." }
val element = MultimodalElement(
id = "over-limit-description",
content = mapOf(
"productName" to "Everyday Running Shoes",
"productDescription" to description
)
)
val theme = ConciergeThemeData(
config = ConciergeThemeConfig(),
tokens = ConciergeThemeTokens(
cssLayout = ConciergeLayout(productCardDescriptionMaxLines = 6)
)
)
composeTestRule.setContent {
ConciergeTheme(theme = theme) {
ExtendedProductCard(
element = element,
modifier = Modifier.height(468.dp)
)
}
}

composeTestRule.waitForIdle()
val descriptionNode = composeTestRule.onNodeWithTag(PRODUCT_DESCRIPTION_TEST_TAG, useUnmergedTree = true)
descriptionNode.assertIsDisplayed()
val layoutResults = mutableListOf<TextLayoutResult>()
descriptionNode.performSemanticsAction(SemanticsActions.GetTextLayoutResult) { getTextLayoutResults ->
getTextLayoutResults(layoutResults)
}
val layoutResult = layoutResults.single()
assertTrue(
"Expected the description to render six lines, got ${layoutResult.lineCount}",
layoutResult.lineCount == 6
)
assertTrue(
"Expected the sixth line to be ellipsized",
layoutResult.isLineEllipsized(5)
)
}

@Test
fun extendedProductCard_usesDefaultForNonPositiveDescriptionMaxLines() {
val element = MultimodalElement(
id = "invalid-description-max-lines",
content = mapOf(
"productName" to "Running Shoes",
"productDescription" to "First description line.\nSecond description line.\nThird description line."
)
)
val theme = ConciergeThemeData(
config = ConciergeThemeConfig(),
tokens = ConciergeThemeTokens(
cssLayout = ConciergeLayout(productCardDescriptionMaxLines = 0)
)
)

composeTestRule.setContent {
ConciergeTheme(theme = theme) {
ExtendedProductCard(element = element)
}
}

val descriptionNode = composeTestRule.onNodeWithTag(PRODUCT_DESCRIPTION_TEST_TAG, useUnmergedTree = true)
descriptionNode.assertIsDisplayed()
val layoutResults = mutableListOf<TextLayoutResult>()
descriptionNode.performSemanticsAction(SemanticsActions.GetTextLayoutResult) { getTextLayoutResults ->
getTextLayoutResults(layoutResults)
}
val layoutResult = layoutResults.single()
assertEquals("Nonpositive line limits should use the two-line default", 2, layoutResult.lineCount)
assertTrue("Expected the second line to be ellipsized", layoutResult.isLineEllipsized(1))
}

@Test
fun extendedProductCard_invokesOnActionClick_withTappedButton() {
val element = MultimodalElement(
Expand Down Expand Up @@ -830,6 +960,137 @@ class ExtendedProductCardTest {
)
}

@Test
fun extendedProductCard_reservesCtaSlot_whenRequested() {
val withCta = MultimodalElement(
id = "with-cta",
content = mapOf(
"productName" to "Product with action",
"productPrice" to "$10.00",
"primaryText" to "Shop now",
"primaryUrl" to "https://example.com/product"
)
)
val withoutCta = MultimodalElement(
id = "without-cta",
content = mapOf(
"productName" to "Product without action",
"productPrice" to "$20.00"
)
)
val tallCardHeight = 480.dp
val theme = ConciergeThemeData(
config = ConciergeThemeConfig(),
tokens = ConciergeThemeTokens(
cssLayout = ConciergeLayout(productCardMaxHeight = tallCardHeight.value.toDouble())
)
)

composeTestRule.setContent {
ConciergeTheme(theme = theme) {
CompositionLocalProvider(LocalImageProvider provides DefaultImageProvider()) {
Row(modifier = Modifier.horizontalScroll(rememberScrollState())) {
ExtendedProductCard(
element = withCta,
modifier = Modifier.height(tallCardHeight),
reserveCtaSlot = true
)
ExtendedProductCard(
element = withoutCta,
modifier = Modifier.height(tallCardHeight),
reserveCtaSlot = true
)
}
}
}
}

composeTestRule.waitForIdle()
val withCtaPriceTop = composeTestRule.onNodeWithText("$10.00", useUnmergedTree = true)
.getBoundsInRoot().top
val withoutCtaPriceTop = composeTestRule.onNodeWithText("$20.00", useUnmergedTree = true)
.getBoundsInRoot().top
assertTrue(
"Expected prices to align when one card reserves the carousel CTA slot " +
"(with=$withCtaPriceTop, without=$withoutCtaPriceTop)",
kotlin.math.abs(withCtaPriceTop.value - withoutCtaPriceTop.value) < 1f
)
}

@Test
fun extendedProductCard_reservedCtaSlot_placeholderIsHiddenFromSemanticsAndNotClickable() {
val element = MultimodalElement(
id = "without-cta",
content = mapOf(
"productName" to "Product without action",
"productPrice" to "$20.00"
)
)
var clickedButtons = 0

composeTestRule.setContent {
ConciergeTheme {
CompositionLocalProvider(LocalImageProvider provides DefaultImageProvider()) {
ExtendedProductCard(
element = element,
modifier = Modifier.height(cardMaxHeight),
onActionClick = { clickedButtons++ },
reserveCtaSlot = true
)
}
}
}

composeTestRule.waitForIdle()
composeTestRule.onNodeWithTag(CTA_BUTTON_TEST_TAG).assertDoesNotExist()
composeTestRule.onNodeWithTag(SECONDARY_CTA_BUTTON_TEST_TAG).assertDoesNotExist()
composeTestRule.onAllNodes(hasClickAction() and SemanticsMatcher.expectValue(SemanticsProperties.Role, Role.Button), useUnmergedTree = true)
.assertCountEquals(0)
assertEquals(0, clickedButtons)
}

@Test
fun extendedProductCard_reservedCtaSlot_occupiesSpaceWhenCardHasNoCtas() {
fun element(id: String, price: String) = MultimodalElement(
id = id,
content = mapOf(
"productName" to "Product without action",
"productPrice" to price
)
)

composeTestRule.setContent {
ConciergeTheme {
CompositionLocalProvider(LocalImageProvider provides DefaultImageProvider()) {
Row(modifier = Modifier.horizontalScroll(rememberScrollState())) {
ExtendedProductCard(
element = element("reserved", "$10.00"),
modifier = Modifier.height(cardMaxHeight),
reserveCtaSlot = true
)
ExtendedProductCard(
element = element("unreserved", "$20.00"),
modifier = Modifier.height(cardMaxHeight),
reserveCtaSlot = false
)
}
}
}
}

composeTestRule.waitForIdle()
val reservedPriceBottom = composeTestRule.onNodeWithText("$10.00", useUnmergedTree = true)
.getBoundsInRoot().bottom
val unreservedPriceBottom = composeTestRule.onNodeWithText("$20.00", useUnmergedTree = true)
.getBoundsInRoot().bottom
// The price is bottom-anchored, so a reserved (invisible) CTA slot pushes it up.
assertTrue(
"Expected the reserved CTA slot to take up space " +
"(reserved=$reservedPriceBottom, unreserved=$unreservedPriceBottom)",
reservedPriceBottom < unreservedPriceBottom
)
}

@Test
fun extendedProductCard_ctas_alignAcrossCards_whenOnlyOneCardHasWasPrice() {
fun element(id: String, wasPrice: String?) = MultimodalElement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasContentDescription
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.adobe.marketing.mobile.concierge.network.MultimodalElement
import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeTheme
import com.adobe.marketing.mobile.concierge.utils.image.DefaultImageProvider
import com.adobe.marketing.mobile.concierge.utils.image.LocalImageProvider
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test

Expand Down Expand Up @@ -276,4 +279,55 @@ class ProductCarouselTest {

composeTestRule.waitForIdle()
}

@Test
fun productCarousel_reservesCtaSlotAcrossExtendedCards() {
val elements = listOf(
MultimodalElement(
id = "with-cta",
content = mapOf(
"productName" to "Product with action",
"productPrice" to "$10.00",
"primaryText" to "Shop now",
"primaryUrl" to "https://example.com/product"
)
),
MultimodalElement(
id = "without-cta",
content = mapOf(
"productName" to "Product without action",
"productPrice" to "$20.00"
)
)
)

composeTestRule.setContent {
ConciergeTheme {
CompositionLocalProvider(LocalImageProvider provides DefaultImageProvider()) {
ProductCarousel(
elements = elements,
onImageClick = {},
useExtendedProductCards = true
)
}
}
}

composeTestRule.waitForIdle()
// The carousel's measure pass also composes each card, leaving a zero-size copy in the
// semantics tree; read the bounds of the card that is actually laid out.
fun renderedPriceTop(price: String) = composeTestRule
.onAllNodesWithText(price, useUnmergedTree = true)
.fetchSemanticsNodes()
.single { it.boundsInRoot.width > 0f }
.boundsInRoot.top
val withCtaPriceTop = renderedPriceTop("$10.00")
val withoutCtaPriceTop = renderedPriceTop("$20.00")

assertTrue(
"Expected prices to align when one extended carousel card has a CTA " +
"(with=$withCtaPriceTop, without=$withoutCtaPriceTop)",
kotlin.math.abs(withCtaPriceTop - withoutCtaPriceTop) < 1f
)
}
}
Loading
Loading