fix(#152): leave saved address panel safely

This commit is contained in:
QiuSW
2026-08-29 14:59:19 +08:00
parent 7fddd189b4
commit 19fa1c7dd3
3 changed files with 13 additions and 12 deletions
+2 -2
View File
@@ -11,8 +11,8 @@ android {
applicationId = "cn.ilapage.goauto.agent"
minSdk = 23
targetSdk = 34
versionCode = 37
versionName = "0.9.24"
versionCode = 38
versionName = "0.9.25"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
@@ -171,7 +171,7 @@ class PurchaseLiveAutomation(
val save = uniqueClickable(stable, stable.nodes.filter { it.visible && it.enabled && it.label == "保存" })
if (save.size != 1) fail("PURCHASE_ADDRESS_UPDATE_FAILED", "地址保存按钮不唯一,未创建订单")
click(save.single(), "保存地址")
val savedEvidence = waitForStableSavedAddress(expected, suffix)
val savedEvidence = waitForStableAddressEditorExit()
if (!hasFinalSavedAddressEvidence(savedEvidence, expected, suffix)) {
if (!driver.backPurchase()) fail("PURCHASE_ADDRESS_UPDATE_FAILED", "地址保存后无法返回订单页面,未创建订单")
waitFor("PURCHASE_ADDRESS_SAVE_TIMEOUT", "地址保存后无法返回订单页面,未创建订单") {
@@ -198,16 +198,16 @@ class PurchaseLiveAutomation(
private fun hasFinalSavedAddressEvidence(snapshot: UiSnapshot, expected: String, suffix: String): Boolean =
hasSavedAddressEvidence(snapshot, expected, suffix) && finalSubmitTargets(snapshot).size == 1
private fun waitForStableSavedAddress(expected: String, suffix: String): UiSnapshot {
var consecutiveMatches = 0
private fun waitForStableAddressEditorExit(): UiSnapshot {
var consecutiveExits = 0
repeat(50) {
val snapshot = driver.capture()
pageProblem(snapshot)
if (hasSavedAddressEvidence(snapshot, expected, suffix)) {
consecutiveMatches++
if (consecutiveMatches >= 2) return snapshot
if (snapshot.packageName == PDD_PACKAGE && shippingAddressEditors(snapshot).isEmpty()) {
consecutiveExits++
if (consecutiveExits >= 2) return snapshot
} else {
consecutiveMatches = 0
consecutiveExits = 0
}
pause(200)
}
@@ -52,8 +52,8 @@ class PurchaseLiveAutomationTest {
}
@Test
fun `saved address transition without legacy title or phone is accepted before final confirmation`() {
val driver = LiveDriver(savedTransitionWithoutLegacyContext = true)
fun `saved address transition may hide suffix before strict final confirmation`() {
val driver = LiveDriver(savedTransitionWithoutLegacyContext = true, savedTransitionHidesSuffix = true)
val automation = PurchaseLiveAutomation(driver, pause = {})
val address = automation.updateShippingAddress("_cg21")
@@ -176,6 +176,7 @@ class PurchaseLiveAutomationTest {
private val duplicateConfirmationSuffix: Boolean = false,
private val saveStaysInEdit: Boolean = false,
private val savedTransitionWithoutLegacyContext: Boolean = false,
private val savedTransitionHidesSuffix: Boolean = false,
) : PurchaseUiDriver {
private var page = "confirmation"
private var addressVisible = !addressClipped
@@ -208,7 +209,7 @@ class PurchaseLiveAutomationTest {
))
"saved-transition" -> snapshot(listOf(
node("transition-title", "选择收货信息"),
node("address-suffix", address.substring(address.lastIndexOf("_cg"))),
node("address-summary", if (savedTransitionHidesSuffix) "已保存的收货信息" else address.substring(address.lastIndexOf("_cg"))),
))
"order" -> snapshot(listOf(node("status", "待付款"), node("order", "订单号:PDD-202608210001"), node("time", "下单时间:2026-08-21 10:30:00"), node("pay", "立即支付", clickable = true)))
"chooser" -> UiSnapshot(if (trustedChooser) "android" else "example.untrusted", "com.android.internal.app.ChooserActivity", listOf(