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
36 changes: 17 additions & 19 deletions apps/ios/CookUITests/MembershipStoreKitUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,19 @@ final class MembershipStoreKitUITests: XCTestCase {
}

@MainActor func testUserCancelsLocalAppleConfirmationWithoutGrantingMembership() throws {
// CI reached the cancelled and inactive assertions at 119 seconds.
// Keep the original UI deadlines and leave bounded room for teardown.
executionTimeAllowance = 180
let url = try XCTUnwrap(Bundle(for: Self.self).url(forResource: "MembershipProducts", withExtension: "storekit"))
let session = try SKTestSession(contentsOf: url)
session.resetToDefaultState(); session.clearTransactions(); session.disableDialogs = false
clearSessionAfterAppTeardown(session)
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-membership", "-ui-testing-membership-storekit", "-ui-testing-reset-membership",
"-ui-testing-reset-consent", "-ui-testing-disable-animations"]
app.launchEnvironment["COOK_UI_TEST_DECLINE_CONSENT"] = "1"
app.launchEnvironment["COOK_MEMBERSHIP_FIXTURE_SETTLEMENT"] = "confirmed"
terminateAppAfterTest(app)
app.launch()
let mine = app.buttons.matching(NSPredicate(format: "label == %@", "我的")).firstMatch
XCTAssertTrue(mine.waitForExistence(timeout: 15)); mine.tap()
let entry = app.buttons.matching(identifier: "settings.membership").element
XCTAssertTrue(entry.waitForExistence(timeout: 10)); entry.tap()
let app = launchScene(reset: true)
let list = app.collectionViews.matching(identifier: "membership.content").element
let buy = list.buttons.matching(identifier: "membership.buy.fun.yunle.cook.local.nonrenewing").element
XCTAssertTrue(buy.waitForExistence(timeout: 10))
for _ in 0..<8 where !buy.isHittable { list.swipeUp() }
XCTAssertTrue(buy.isHittable); buy.tap()
reveal(buy, in: list, maxSwipes: 8)
buy.tap()
let system = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let confirmation = system.otherElements.matching(identifier: "payment-sheet").element
XCTAssertTrue(confirmation.waitForExistence(timeout: 15), "The real local Apple confirmation must appear")
Expand All @@ -118,7 +111,7 @@ final class MembershipStoreKitUITests: XCTestCase {
cancel.tap()
XCTAssertTrue(confirmation.waitForNonExistence(timeout: 10))
let message = list.staticTexts.matching(identifier: "membership.message").element
for _ in 0..<8 where !message.exists || !message.isHittable { list.swipeUp() }
reveal(message, in: list, maxSwipes: 8)
XCTAssertEqual(message.waitForState("label CONTAINS %@", timeout: 10, argument: "已取消购买"), .completed)
let inactive = list.staticTexts.matching(identifier: "membership.inactive").element
reveal(inactive, in: list, upwards: false)
Expand All @@ -130,6 +123,9 @@ final class MembershipStoreKitUITests: XCTestCase {
}

@MainActor func testRefundFromOutsideAppDeliversVerifiedRevocationWithoutManualRefresh() async throws {
// The live update and the subsequent restore both passed in CI, but
// XCTest timed out while shutting down the App and test session.
executionTimeAllowance = 180
let url = try XCTUnwrap(Bundle(for: Self.self).url(forResource: "MembershipProducts", withExtension: "storekit"))
let session = try SKTestSession(contentsOf: url)
session.resetToDefaultState(); session.clearTransactions(); session.disableDialogs = true
Expand Down Expand Up @@ -165,7 +161,8 @@ final class MembershipStoreKitUITests: XCTestCase {
app.launchEnvironment["COOK_MEMBERSHIP_FIXTURE_SETTLEMENT"] = "confirmed"
app.launchEnvironment["COOK_MEMBERSHIP_FIXTURE_OWNER"] = owner
terminateAppAfterTest(app); app.launch()
let mine = app.buttons.matching(NSPredicate(format: "label == %@", "我的")).firstMatch
let tab = app.tabBars.buttons["我的"].firstMatch
let mine = tab.exists ? tab : app.buttons.matching(NSPredicate(format: "label == %@", "我的")).firstMatch
XCTAssertTrue(mine.waitForExistence(timeout: 15)); mine.tap()
let entry = app.buttons.matching(identifier: "settings.membership").element
XCTAssertTrue(entry.waitForExistence(timeout: 10)); entry.tap()
Expand Down Expand Up @@ -210,11 +207,12 @@ final class MembershipStoreKitUITests: XCTestCase {
}
}

@MainActor private func reveal(_ element: XCUIElement, in list: XCUIElement, upwards: Bool = true) {
for _ in 0..<12 {
if element.exists && element.isHittable { return }
@MainActor private func reveal(_ element: XCUIElement, in list: XCUIElement, upwards: Bool = true, maxSwipes: Int = 12,
file: StaticString = #filePath, line: UInt = #line) {
for _ in 0..<maxSwipes {
if element.isHittable { return }
if upwards { list.swipeUp() } else { list.swipeDown() }
}
XCTAssertTrue(element.exists && element.isHittable)
XCTAssertTrue(element.isHittable, file: file, line: line)
}
}
2 changes: 2 additions & 0 deletions docs/dev/ios-membership.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,5 @@ asc subscriptions list --app 6824589542
扩大重复测试又发现通知用例的监听生命周期不完整:收到第一条更新后直接 `break`,随后取消已退出的消费任务,不能保证在下一轮会话重置前终止底层观察者。现在保留消费循环,首次匹配时只完成一次 expectation,在原 10 秒等待结束后显式取消并等待消费任务结束;[AsyncStream 的取消回调](https://developer.apple.com/documentation/swift/asyncstream/continuation/ontermination) 负责通知底层观察者停止。固定同一模拟器的 100 轮对照中,旧写法 98 通过、2 失败,新写法 100 通过;这支持测试监听隔离的修复,不宣称证明了 StoreKit 平台内部原因。原失败及对照结果均保留。

合并上述测试准备与监听清理后,同一共享模拟器上的完整 SDK 组连续 20 轮,共 140 次执行全部通过、0 失败、0 跳过。应用代码、交易 UI 与 CI 脚本未在这一轮再改动。

[#228 的 PR 检查](https://github.com/YunYouJun/cook/actions/runs/43609921325/job/132492651530)中,外部退款、无手动刷新撤销权益和显式恢复均完成,随后在退出 App 时超过 120 秒。[合并后检查](https://github.com/YunYouJun/cook/actions/runs/43610289509/job/132493859822)的取消购买用例也已确认系统确认页关闭且会员仍未开通,但耗时约 119 秒才开始退出。两个用例各自使用现有 180 秒上限,为界面操作和清理留出时间;购买确认、状态等待、退款恢复断言、清理顺序和整组超时均不变。界面测试优先在 Tab 栏内找「我的」,滚动时只查询控件能否点击,减少对同一行重复查询。
Loading