Modern Apps git

← Modern-Apps.git

shop: search cards name the store that actually sells the tapped variant

Commit
3f3817881ac68d55c46ba134986a225135dd1026
Author
Vayun Mathur <[email protected]>
When
2026-12-01 15:33 UTC (4 days ago)
Parents
8cc6204
ProductCard labelled a Global Catalog product with the
product-level store name, but the card opens the first
variant's seller: 'Catalog Collective' on the card, 'Trail
Outfitters' on the product page it opened โ€” a store that
does not sell the tapped variant got the attribution. Every
other surface (detail, cart, assistant) already prefers
variant seller identity, as the module docs state.

The card now derives its label from its click target the
same way (variant storeName, else product name only when the
target domain is the product's, else the domain). Two
regression tests pin the attribution and the no-name
fallback. Cart totals, checkout and orders were audited and
cleared. Verified: :shop:testDevUnitTest 162 tests pass;
lint findings are pre-existing on untouched files.

Diff

shop/src/main/java/com/vayunmathur/shop/ui/SearchScreen.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/ui/SearchScreen.kt b/shop/src/main/java/com/vayunmathur/shop/ui/SearchScreen.ktindex 66e4bcee4a..cac98d1818 100644--- a/shop/src/main/java/com/vayunmathur/shop/ui/SearchScreen.kt+++ b/shop/src/main/java/com/vayunmathur/shop/ui/SearchScreen.kt@@ -257,7 +257,15 @@ private fun ProductCard(product: UcpProduct, onClick: () -> Unit) {                     style = MaterialTheme.typography.bodyMedium,                     color = MaterialTheme.colorScheme.primary,                 )-                product.storeName.takeIf { it.isNotBlank() }?.let {+                // The card opens the first variant, so it is labelled with that+                // variant's seller (as on the product page), not the product-level+                // store, which for Global Catalog products is the catalog host's+                // name rather than the merchant that sells the tapped variant.+                val target = product.variants.firstOrNull()+                val storeDomain = target?.shopDomain?.takeIf { it.isNotBlank() } ?: product.shopDomain+                val storeName = target?.storeName?.takeIf { it.isNotBlank() }+                    ?: product.storeName.takeIf { storeDomain == product.shopDomain }.orEmpty()+                storeName.ifBlank { storeDomain }.takeIf { it.isNotBlank() }?.let {                     Text(                         text = it,                         style = MaterialTheme.typography.bodySmall,
shop/src/test/java/com/vayunmathur/shop/ui/ShopSearchStoreDisplayTest.kt
diff --git a/shop/src/test/java/com/vayunmathur/shop/ui/ShopSearchStoreDisplayTest.kt b/shop/src/test/java/com/vayunmathur/shop/ui/ShopSearchStoreDisplayTest.ktnew file mode 100644index 0000000000..a35ac25add--- /dev/null+++ b/shop/src/test/java/com/vayunmathur/shop/ui/ShopSearchStoreDisplayTest.kt@@ -0,0 +1,101 @@+package com.vayunmathur.shop.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import com.vayunmathur.shop.data.Money+import com.vayunmathur.shop.data.ProductVariant+import com.vayunmathur.shop.data.UcpProduct+import kotlin.test.Test+import kotlin.test.assertEquals+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.annotation.Config++/**+ * Search-card store attribution: the card opens the product's first variant, so the+ * store it names must be that variant's seller โ€” the same name the product page+ * shows โ€” not the product-level store, which for Global Catalog products belongs+ * to the catalog host rather than the merchant selling the tapped variant.+ */+@RunWith(RobolectricTestRunner::class)+@Config(sdk = [34])+class ShopSearchStoreDisplayTest {++    @get:Rule+    val composeRule = createComposeRule()++    @Test+    fun searchCardNamesTheVariantSellerItOpensNotTheProductLevelStore() {+        var clicked: Triple<String, String, String>? = null+        val product = UcpProduct(+            id = "gid://shopify/Product/1",+            title = "Trail Runner",+            platformId = "shopify",+            shopDomain = "catalog.example",+            storeName = "Catalog Collective",+            priceRange = Money(12_999, "USD"),+            priceRangeMax = Money(12_999, "USD"),+            checkoutEligible = true,+            variants = listOf(+                ProductVariant(+                    id = "v-blue",+                    title = "9 / Blue",+                    price = Money(12_999, "USD"),+                    available = true,+                    storeName = "Trail Outfitters",+                    shopDomain = "trail.example",+                ),+            ),+        )+        composeRule.setContent {+            SearchContent(+                query = "runner",+                onQueryChange = {},+                searching = false,+                results = listOf(product),+                onSearch = {},+                onProductClick = { variantId, platformId, shopDomain ->+                    clicked = Triple(variantId, platformId, shopDomain)+                },+            )+        }+        // Pre-fix this asserted the product-level "Catalog Collective" instead.+        composeRule.onNodeWithText("Trail Outfitters").assertIsDisplayed()+        composeRule.onNodeWithText("Catalog Collective").assertDoesNotExist()+        composeRule.onNodeWithText("Trail Runner").performClick()+        assertEquals(Triple("v-blue", "shopify", "trail.example"), clicked)+    }++    @Test+    fun searchCardFallsBackToTheDomainWhenNoStoreNameIsKnown() {+        val product = UcpProduct(+            id = "p-plain",+            title = "Plain Mug",+            platformId = "generic",+            shopDomain = "mug.example",+            priceRange = Money(500, "USD"),+            variants = listOf(+                ProductVariant(+                    id = "v-mug",+                    title = "Default",+                    price = Money(500, "USD"),+                    available = true,+                ),+            ),+        )+        composeRule.setContent {+            SearchContent(+                query = "mug",+                onQueryChange = {},+                searching = false,+                results = listOf(product),+                onSearch = {},+                onProductClick = { _, _, _ -> },+            )+        }+        composeRule.onNodeWithText("mug.example").assertIsDisplayed()+    }+}