fix(collection): recognize combination spec heading (#173)

This commit is contained in:
QiuSW
2026-08-31 16:22:54 +08:00
parent 21b38c4444
commit f30be4462f
3 changed files with 31 additions and 1 deletions
@@ -282,6 +282,33 @@ class PddProductDetailCollectorTest {
assertFalse(parsed.dimensions.any { it.key == "color" })
}
@Test
fun `configured combination heading is collected as the primary color dimension`() {
val snapshot = UiSnapshot(
PDD_PACKAGE,
ACTIVITY,
listOf(
node("content", "", 0, 0, 1080, 2200, resourceId = "android:id/content", className = "android.widget.FrameLayout"),
node("summary", "已选:", 20, 300, 700, 360),
node("title", "确认款式", 20, 370, 300, 410),
node("scroll", "", 0, 400, 1080, 1800, scrollable = true),
node("combination-heading", "组合", 20, 420, 300, 470, parentPath = "scroll"),
node("combination-white", "白色套装", 30, 500, 260, 580, clickable = true, parentPath = "scroll"),
node("combination-black", "黑色套装", 290, 500, 520, 580, clickable = true, parentPath = "scroll"),
node("size-heading", "尺码", 20, 620, 300, 670, parentPath = "scroll"),
node("size", "均码【80-120斤】", 30, 700, 500, 780, clickable = true, parentPath = "scroll"),
node("confirm", "确定", 0, 2000, 1080, 2150, clickable = true),
),
)
val configured = config().copy(colorAliases = config().colorAliases + "组合")
val dimensions = PddScreenParser.parse(snapshot, configured, GOODS_ID, evidence()).dimensions
assertEquals("组合", dimensions.first { it.key == "color" }.name)
assertEquals(listOf("白色套装", "黑色套装"), dimensions.first { it.key == "color" }.values.map { it.text })
assertEquals(listOf("均码【80-120斤】"), dimensions.first { it.key == "size" }.values.map { it.text })
}
@Test
fun unrelatedLongTextIsNotUsedAsProductTitle() {
val driver = FakeCollectorDriver()
@@ -72,6 +72,9 @@ func TestBuiltInPDDProductDetailTemplateIsValid(t *testing.T) {
if !bytes.Contains(raw, []byte(`"size":["尺码","尺寸","套餐","参考分类"]`)) {
t.Fatal("built-in template must classify 参考分类 as size")
}
if !bytes.Contains(raw, []byte(`"color":["颜色分类","颜色","款式","颜色款式","花色","组合"]`)) {
t.Fatal("built-in template must classify 组合 as color")
}
if !bytes.Contains(raw, []byte(`"orderSubmitAliases":["提交订单","提交訂單"]`)) {
t.Fatal("built-in template must carry read-only collector text aliases")
}
+1 -1
View File
@@ -17,7 +17,7 @@ var pddProductDetailTemplate = json.RawMessage(`{
"hooks":{"afterSpecPanelOpen":[]},
"collector":{
"collectorId":"pddProductDetailV1","specEntryStrategy":"safeBottomSpecEntryV1","priceParser":"pddRmbPriceV1","priceGranularity":"color",
"dimensionAliases":{"color":["颜色分类","颜色","款式","颜色款式","花色"],"size":["尺码","尺寸","套餐","参考分类"]},
"dimensionAliases":{"color":["颜色分类","颜色","款式","颜色款式","花色","组合"],"size":["尺码","尺寸","套餐","参考分类"]},
"textAliases":{
"specPanel":{"titleAliases":["确认款式","確認款式"],"closeAliases":["关闭","關閉"],"confirmAliases":["确定","確定","确认","確認"],"quantityDecreaseAliases":["减少数量","減少數量"],"quantityIncreaseAliases":["增加数量","增加數量"],"paymentAreaAliases":["微信支付","先用后付","先用後付","支付方式"],"orderSubmitAliases":["提交订单","提交訂單"],"quickBuyAliases":["现在买","現在買"]},
"dimension":{"colorSuffixes":["颜色","款式"],"sizeSuffixes":["尺码","尺寸"],"exactNames":["规格","型号","容量","类型","版本","口味"],"adaptiveAliases":["套餐"]},