fix(training): 优化答题交互并消除按钮置灰闪动
This commit is contained in:
@@ -87,6 +87,7 @@ struct TrainingUIRenderingTests {
|
||||
#expect(allViews(result.view).compactMap { $0 as? UILabel }.contains { $0.text == TrainingRemoteFixtures.review().stem })
|
||||
Attachment.record(render(navigation.view), named: "成绩答案解析展开", as: .png)
|
||||
learning.sendActions(for: .touchUpInside)
|
||||
try await waitForNavigation(in: navigation) { $0 === course }
|
||||
try await settleTransitions(in: navigation)
|
||||
#expect(navigation.topViewController === course)
|
||||
navigation.setViewControllers([center, result], animated: false)
|
||||
@@ -94,6 +95,7 @@ struct TrainingUIRenderingTests {
|
||||
await result.reload()
|
||||
let newLearning = try #require(allViews(result.view).compactMap { $0 as? UIButton }.first { $0.accessibilityIdentifier == "training.result.learning" })
|
||||
newLearning.sendActions(for: .touchUpInside)
|
||||
try await waitForNavigation(in: navigation) { ($0 as? TrainingCourseViewController)?.taskID == "task_1" }
|
||||
try await settleTransitions(in: navigation)
|
||||
#expect((navigation.topViewController as? TrainingCourseViewController)?.taskID == "task_1")
|
||||
await source.configure { $0.attemptHandler = { _ in
|
||||
@@ -113,6 +115,7 @@ struct TrainingUIRenderingTests {
|
||||
Attachment.record(render(navigation.view), named: "通过成绩仍可返回学习", as: .png)
|
||||
let completion = try #require(allViews(passedResult.view).compactMap { $0 as? UIButton }.first { $0.accessibilityIdentifier == "training.result.action" })
|
||||
completion.sendActions(for: .touchUpInside)
|
||||
try await waitForNavigation(in: navigation) { $0 === center }
|
||||
try await settleTransitions(in: navigation)
|
||||
#expect(navigation.topViewController === center)
|
||||
}
|
||||
@@ -158,6 +161,16 @@ struct TrainingUIRenderingTests {
|
||||
Attachment.record(image, named: "100题答题卡", as: .png)
|
||||
}
|
||||
|
||||
/// 等待实际目标页面,避免转场尚未开始时误把 nil coordinator 当作完成。
|
||||
private func waitForNavigation(in navigation: UINavigationController, matches: (UIViewController?) -> Bool) async throws {
|
||||
let deadline = ContinuousClock.now.advanced(by: .seconds(3))
|
||||
while !matches(navigation.topViewController), ContinuousClock.now < deadline {
|
||||
try await Task.sleep(for: .milliseconds(10))
|
||||
}
|
||||
let reached = matches(navigation.topViewController)
|
||||
try #require(reached)
|
||||
}
|
||||
|
||||
/// 前一导航动画结束后再执行后续操作,避免测试同时驱动互相冲突的转场。
|
||||
private func settleTransitions(in navigation: UINavigationController) async throws {
|
||||
await Task.yield()
|
||||
|
||||
Reference in New Issue
Block a user