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
22 changes: 17 additions & 5 deletions Documentation/style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,11 @@ Used when `behavior.productCard.cardStyle` is `"productDetail"`.
| `--product-card-badge-text-color` | `cssLayout.productCardBadgeTextColor` | `String` | `"#FFFFFF"` | Badge text color (hex) |
| `--product-card-badge-background-color` | `cssLayout.productCardBadgeBackgroundColor` | `String` | primary color | Badge background (hex) |
| `--product-card-was-price-color` | `cssLayout.productCardWasPriceColor` | `String` | `"#6E6E6E"` | "Was" price text color (hex) |
| `--product-card-cta-button-background-color` | `colors.productCardCtaButton.background` | `String` | `"#BB5811"` | Product card CTA button background color (hex) |
| `--product-card-cta-button-text-color` | `colors.productCardCtaButton.text` | `String` | `"#FFFFFF"` | Product card CTA button label text color (hex) |
| `--product-card-cta-button-background-color` | `colors.productCardCtaButton.background` | `String` | `"#BB5811"` | Product card primary CTA button background color (hex) |
| `--product-card-cta-button-text-color` | `colors.productCardCtaButton.text` | `String` | `"#FFFFFF"` | Product card primary CTA button label text color (hex) |
| `--product-card-secondary-cta-button-background-color` | `colors.productCardSecondaryCtaButton.background` | `String` | transparent | Product card secondary CTA button background color (hex); outlined style |
| `--product-card-secondary-cta-button-text-color` | `colors.productCardSecondaryCtaButton.text` | `String` | `"#BB5811"` | Product card secondary CTA button label text color (hex) |
| `--product-card-secondary-cta-button-border-color` | `colors.productCardSecondaryCtaButton.border` | `String` | `"#BB5811"` | Product card secondary CTA button border color (hex) |

> **Layout value format:** All layout measurements are specified as CSS strings in the JSON theme object (e.g. `"8px"`, `"16px"`) and integer quantities as numeric strings (e.g. `"700"`, `"400"`). The SDK parses these into their internal Kotlin types (`Double` for dp values, `Int` for weights and orders). The **Type** and **Default** columns below reflect the internal representation.

Expand Down Expand Up @@ -888,6 +891,7 @@ When `behavior.productCard.cardStyle` is `"productDetail"`, product recommendati
| `--product-card-cta-button-vertical-padding` | `cssLayout.productCardCtaButtonVerticalPadding` | `Double` | `8.0` | Product card CTA button vertical padding (dp). |
| `--product-card-cta-button-font-size` | `cssLayout.productCardCtaButtonFontSize` | `Double` | `12.0` | Product card CTA button label font size (sp) |
| `--product-card-cta-button-font-weight` | `cssLayout.productCardCtaButtonFontWeight` | `Int` | `600` | Product card CTA button label font weight |
| `--product-card-secondary-cta-button-border-width` | `cssLayout.productCardSecondaryCtaButtonBorderWidth` | `Double` | `1.0` | Product card secondary CTA button border width (dp). Radius, padding, and font are shared with the primary CTA button's tokens above. |

### Layout - Buttons

Expand Down Expand Up @@ -1294,7 +1298,11 @@ Non-CSS `components.feedback` overrides for the feedback dialog.
"--product-card-cta-button-horizontal-padding": "16px",
"--product-card-cta-button-vertical-padding": "8px",
"--product-card-cta-button-font-size": "12px",
"--product-card-cta-button-font-weight": "600"
"--product-card-cta-button-font-weight": "600",
"--product-card-secondary-cta-button-background-color": "transparent",
"--product-card-secondary-cta-button-text-color": "#BB5811",
"--product-card-secondary-cta-button-border-color": "#BB5811",
"--product-card-secondary-cta-button-border-width": "1px"
}
}
```
Expand Down Expand Up @@ -1532,8 +1540,11 @@ These colors are used internally by composables but cannot be customized in them
| `--product-card-badge-text-color` | ✅ | Extended product card badge text color | `ExtendedProductCard` |
| `--product-card-badge-background-color` | ✅ | Extended product card badge background | `ExtendedProductCard` |
| `--product-card-was-price-color` | ✅ | Extended product card "was" price color | `ExtendedProductCard` |
| `--product-card-cta-button-background-color` | ✅ | Product card CTA button background color | `ExtendedProductCard` |
| `--product-card-cta-button-text-color` | ✅ | Product card CTA button label text color | `ExtendedProductCard` |
| `--product-card-cta-button-background-color` | ✅ | Product card primary CTA button background color | `ExtendedProductCard` |
| `--product-card-cta-button-text-color` | ✅ | Product card primary CTA button label text color | `ExtendedProductCard` |
| `--product-card-secondary-cta-button-background-color` | ✅ | Product card secondary CTA button background color | `ExtendedProductCard` |
| `--product-card-secondary-cta-button-text-color` | ✅ | Product card secondary CTA button label text color | `ExtendedProductCard` |
| `--product-card-secondary-cta-button-border-color` | ✅ | Product card secondary CTA button border color | `ExtendedProductCard` |

Note: The feedback dialog checkbox uses `--color-primary` for the check box filled color; the checkmark icon is white and is not configurable via theme.

Expand Down Expand Up @@ -1594,6 +1605,7 @@ Note: The feedback dialog checkbox uses `--color-primary` for the check box fill
| `--product-card-cta-button-vertical-padding` | ✅ | Product card CTA button vertical padding | `ExtendedProductCard` |
| `--product-card-cta-button-font-size` | ✅ | Product card CTA button label font size | `ExtendedProductCard` |
| `--product-card-cta-button-font-weight` | ✅ | Product card CTA button label font weight | `ExtendedProductCard` |
| `--product-card-secondary-cta-button-border-width` | ✅ | Product card secondary CTA button border width | `ExtendedProductCard` |
| `--button-height-s` | ⚠️ | Parsed but not used in composables | - |
| `--cta-button-border-radius` | ✅ | CTA button corner radius | `CtaButton` |
| `--cta-button-horizontal-padding` | ✅ | CTA button horizontal padding | `CtaButton` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ class ExtendedProductCardTest {
}

@Test
fun extendedProductCard_hidesCtaButton_whenSubtitlePresent_evenWithPrimaryAction() {
fun extendedProductCard_showsCtaButton_whenSubtitlePresent() {
// CTA visibility depends only on text+url, not subtitle presence.
val element = MultimodalElement(
id = "buy-now-with-subtitle",
url = "https://example.com/image.jpg",
Expand All @@ -312,7 +313,7 @@ class ExtendedProductCardTest {
}

composeTestRule.waitForIdle()
composeTestRule.onNodeWithText("Buy now").assertDoesNotExist()
composeTestRule.onNodeWithText("Buy now").assertExists()
}

@Test
Expand Down Expand Up @@ -355,6 +356,317 @@ class ExtendedProductCardTest {
}


// -----------------------------------------------------------------------
// Secondary CTA (entity_info.secondary)
// -----------------------------------------------------------------------

@Test
fun extendedProductCard_displaysBothCtaButtons_whenPrimaryAndSecondaryPresent() {
val element = MultimodalElement(
id = "buy-now-and-learn-more",
url = "https://example.com/image.jpg",
content = mapOf(
"productName" to "Product Name",
"productPrice" to "$63.97",
"primaryText" to "Buy now",
"primaryUrl" to "myapp://checkout?productId=prod-123",
"secondaryText" to "Learn more",
"secondaryUrl" to "https://shop.com/products/prod-123"
)
)

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

composeTestRule.waitForIdle()
composeTestRule.onNodeWithText("Buy now").assertIsDisplayed()
composeTestRule.onNodeWithText("Learn more").assertIsDisplayed()
}

@Test
fun extendedProductCard_secondaryCtaRendersAfterPrimary() {
val element = MultimodalElement(
id = "order-check",
url = "https://example.com/image.jpg",
content = mapOf(
"productName" to "Product Name",
"productPrice" to "$63.97",
"primaryText" to "Buy now",
"primaryUrl" to "https://example.com/checkout",
"secondaryText" to "Learn more",
"secondaryUrl" to "https://example.com/learn-more"
)
)

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

composeTestRule.waitForIdle()
val primaryLeft = composeTestRule.onNodeWithTag(CTA_BUTTON_TEST_TAG).getBoundsInRoot().left
val secondaryLeft = composeTestRule.onNodeWithTag(SECONDARY_CTA_BUTTON_TEST_TAG).getBoundsInRoot().left
assertTrue(
"Expected the secondary CTA (left=$secondaryLeft) to render to the right of the primary CTA (left=$primaryLeft)",
secondaryLeft > primaryLeft
)
}

@Test
fun extendedProductCard_showsSecondaryCtaOnly_whenPrimaryHasNoUrl() {
val element = MultimodalElement(
id = "secondary-only",
url = "https://example.com/image.jpg",
content = mapOf(
"productName" to "Product Name",
"productPrice" to "$63.97",
"primaryText" to "Buy now",
"secondaryText" to "Learn more",
"secondaryUrl" to "https://example.com/learn-more"
)
)

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

composeTestRule.waitForIdle()
composeTestRule.onNodeWithText("Buy now").assertDoesNotExist()
composeTestRule.onNodeWithText("Learn more").assertIsDisplayed()
}

@Test
fun extendedProductCard_showsBothCtaButtons_whenSubtitlePresent() {
val element = MultimodalElement(
id = "parking-with-subtitle",
url = "https://example.com/image.jpg",
content = mapOf(
"productName" to "Practice Facility Garage",
"productDescription" to "\$0.00 · Covered, Guaranteed spot",
"primaryText" to "Book on ParkWhiz",
"primaryUrl" to "https://widget.example.com/checkout",
"secondaryText" to "Get directions",
"secondaryUrl" to "https://maps.example.com/directions"
)
)

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

composeTestRule.waitForIdle()
composeTestRule.onNodeWithText("Book on ParkWhiz").assertExists()
composeTestRule.onNodeWithText("Get directions").assertExists()
}

@Test
fun extendedProductCard_hidesSecondaryCtaButton_whenSecondaryUrlIsBlank() {
val element = MultimodalElement(
id = "blank-secondary-url",
url = "https://example.com/image.jpg",
content = mapOf(
"productName" to "Product Name",
"productPrice" to "$63.97",
"primaryText" to "Buy now",
"primaryUrl" to "https://example.com/checkout",
"secondaryText" to "Learn more",
"secondaryUrl" to " "
)
)

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

composeTestRule.waitForIdle()
composeTestRule.onNodeWithText("Buy now").assertIsDisplayed()
composeTestRule.onNodeWithTag(SECONDARY_CTA_BUTTON_TEST_TAG).assertDoesNotExist()
composeTestRule.onNodeWithText("Learn more").assertDoesNotExist()
}

@Test
fun extendedProductCard_trimsWhitespace_fromCtaTextAndUrl() {
var clicked: ProductActionButton? = null
val element = MultimodalElement(
id = "padded-cta",
url = "https://example.com/image.jpg",
content = mapOf(
"productName" to "Product Name",
"productPrice" to "$63.97",
"primaryText" to " Buy now ",
"primaryUrl" to " https://example.com/checkout "
)
)

composeTestRule.setContent {
ConciergeTheme {
CompositionLocalProvider(LocalImageProvider provides DefaultImageProvider()) {
ExtendedProductCard(
element = element,
modifier = Modifier.height(cardMaxHeight),
onActionClick = { clicked = it }
)
}
}
}

composeTestRule.waitForIdle()
composeTestRule.onNodeWithText("Buy now").performClick()
assertEquals("https://example.com/checkout", clicked?.url)
assertEquals("Buy now", clicked?.text)
}

@Test
fun extendedProductCard_secondaryCtaClick_firesActionClick_notCardClick() {
var actionClicks = 0
var cardClicks = 0
var clicked: ProductActionButton? = null
val element = MultimodalElement(
id = "secondary-click-isolation",
url = "https://example.com/image.jpg",
content = mapOf(
"productName" to "Product Name",
"productPrice" to "$63.97",
"primaryText" to "Buy now",
"primaryUrl" to "https://example.com/checkout",
"secondaryText" to "Learn more",
"secondaryUrl" to "https://example.com/learn-more"
)
)

composeTestRule.setContent {
ConciergeTheme {
CompositionLocalProvider(LocalImageProvider provides DefaultImageProvider()) {
ExtendedProductCard(
element = element,
modifier = Modifier.height(cardMaxHeight),
onCardClick = { cardClicks++ },
onActionClick = {
actionClicks++
clicked = it
}
)
}
}
}

composeTestRule.waitForIdle()
composeTestRule.onNodeWithTag(SECONDARY_CTA_BUTTON_TEST_TAG).performClick()
composeTestRule.waitForIdle()

assertEquals(1, actionClicks)
assertEquals(0, cardClicks)
assertEquals("secondary-click-isolation_secondary", clicked?.id)
assertEquals("Learn more", clicked?.text)
assertEquals("https://example.com/learn-more", clicked?.url)
}

@Test
fun extendedProductCard_singleCtaButton_keepsIntrinsicWidth_doesNotStretchFullWidth() {
val element = MultimodalElement(
id = "single-cta-width",
url = "https://example.com/image.jpg",
content = mapOf(
"productName" to "Product Name",
"productPrice" to "$63.97",
"primaryText" to "Buy now",
"primaryUrl" to "https://example.com/checkout"
)
)

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

composeTestRule.waitForIdle()
val bounds = composeTestRule.onNodeWithTag(CTA_BUTTON_TEST_TAG).getBoundsInRoot()
val ctaWidth = bounds.right - bounds.left
// Content area is 218dp (250dp card - 2x16dp padding); intrinsic "Buy now" stays well under.
assertTrue(
"Expected the lone CTA to keep its intrinsic width, but it measured $ctaWidth wide",
ctaWidth < 150.dp
)
}

@Test
fun extendedProductCard_bothCtaButtons_shareRowWidthEqually() {
val element = MultimodalElement(
id = "both-ctas-width",
url = "https://example.com/image.jpg",
content = mapOf(
"productName" to "Product Name",
"productPrice" to "$63.97",
"primaryText" to "Buy now",
"primaryUrl" to "https://example.com/checkout",
"secondaryText" to "Learn more",
"secondaryUrl" to "https://example.com/learn-more"
)
)

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

composeTestRule.waitForIdle()
val primaryBounds = composeTestRule.onNodeWithTag(CTA_BUTTON_TEST_TAG).getBoundsInRoot()
val secondaryBounds = composeTestRule.onNodeWithTag(SECONDARY_CTA_BUTTON_TEST_TAG).getBoundsInRoot()
val primaryWidth = primaryBounds.right - primaryBounds.left
val secondaryWidth = secondaryBounds.right - secondaryBounds.left
assertTrue(
"Expected both CTAs to share the row width equally (primary=$primaryWidth, secondary=$secondaryWidth)",
kotlin.math.abs(primaryWidth.value - secondaryWidth.value) < 2f
)
}

// -----------------------------------------------------------------------
// Drop shadow rendering (--multimodal-card-box-shadow)
// -----------------------------------------------------------------------
Expand Down
Loading
Loading