ui(training): 统一课程学习与在线考试步骤栏样式
This commit is contained in:
@@ -56,6 +56,63 @@ struct TrainingUIRenderingTests {
|
||||
Attachment.record(cardImage, named: "320点长标题任务卡", as: .png)
|
||||
}
|
||||
|
||||
@Test("课程与考试步骤等宽居中,窄屏和大字体不裁切")
|
||||
func learningAndExamStepLayout() async throws {
|
||||
for width: CGFloat in [320, 390] {
|
||||
let domain = "training_step_layout_\(UUID().uuidString)"
|
||||
let defaults = try #require(UserDefaults(suiteName: domain))
|
||||
defer { defaults.removePersistentDomain(forName: domain) }
|
||||
let context = TrainingContext(accountScope: domain, scenicID: 1, storeID: 1)
|
||||
let model = TrainingRemoteExamViewModel(taskID: "task_1", context: context,
|
||||
pendingStore: TrainingPendingSubmissionStore(defaults: defaults), currentContext: { context })
|
||||
let source = TrainingDataStub()
|
||||
let course = TrainingCourseViewController(taskID: "task_1", service: source)
|
||||
let exam = TrainingExamViewController(taskID: "task_1", service: source, viewModel: model)
|
||||
for (controller, selectedTitle) in [(course as UIViewController, "1 课程学习"), (exam, "2 在线考试")] {
|
||||
let navigation = UINavigationController(rootViewController: controller)
|
||||
let window = try makeWindow(navigation, width: width)
|
||||
defer { window.isHidden = true }
|
||||
let deadline = ContinuousClock.now.advanced(by: .seconds(5))
|
||||
while (!allViews(controller.view).contains { $0 is TrainingStepView }
|
||||
|| (controller === exam && !model.canEdit)), ContinuousClock.now < deadline {
|
||||
try await Task.sleep(for: .milliseconds(10))
|
||||
}
|
||||
let steps = allViews(controller.view).compactMap { $0 as? TrainingStepView }
|
||||
#expect(steps.count == 1)
|
||||
let step = try #require(steps.first)
|
||||
navigation.view.layoutIfNeeded()
|
||||
let labels = allViews(step).compactMap { $0 as? UILabel }
|
||||
#expect(labels.map(\.text) == ["1 课程学习", "2 在线考试"])
|
||||
let first = try #require(labels.first)
|
||||
let second = try #require(labels.last)
|
||||
#expect(abs(first.bounds.width - second.bounds.width) < 1)
|
||||
#expect(first.convert(first.bounds, to: step).maxX <= second.convert(second.bounds, to: step).minX)
|
||||
#expect(labels.allSatisfy { $0.textAlignment == .center })
|
||||
#expect(labels.filter { $0.accessibilityTraits.contains(.selected) }.map(\.text) == [selectedTitle])
|
||||
#expect(labels.first { $0.text == selectedTitle }?.textColor == TrainingUI.primary)
|
||||
#expect(step.bounds.height >= 44)
|
||||
Attachment.record(render(step), named: "\(Int(width))点-\(selectedTitle)", as: .png)
|
||||
|
||||
if width == 320 {
|
||||
navigation.setOverrideTraitCollection(UITraitCollection(preferredContentSizeCategory: .accessibilityExtraExtraExtraLarge), forChild: controller)
|
||||
navigation.view.layoutIfNeeded()
|
||||
#expect(first.font.pointSize > 13)
|
||||
for label in labels {
|
||||
let frame = label.convert(label.bounds, to: step)
|
||||
#expect(frame.minY >= 0 && frame.maxY <= step.bounds.height + 1)
|
||||
#expect(label.sizeThatFits(CGSize(width: label.bounds.width, height: .greatestFiniteMagnitude)).height <= label.bounds.height + 1)
|
||||
}
|
||||
Attachment.record(render(step), named: "大字体-\(selectedTitle)", as: .png)
|
||||
}
|
||||
if controller === course {
|
||||
step.configure(mode: .study)
|
||||
#expect(second.text == "完成学习")
|
||||
#expect(first.accessibilityTraits.contains(.selected))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test("未通过成绩可展开解析并返回已有课程,旧失败成绩在通过后不可重考")
|
||||
func resultLearningAndReviewNavigation() async throws {
|
||||
let source = TrainingDataStub()
|
||||
@@ -120,10 +177,10 @@ struct TrainingUIRenderingTests {
|
||||
#expect(navigation.topViewController === center)
|
||||
}
|
||||
|
||||
private func makeWindow(_ navigation: UINavigationController) throws -> UIWindow {
|
||||
private func makeWindow(_ navigation: UINavigationController, width: CGFloat = 390) throws -> UIWindow {
|
||||
let scene = try #require(UIApplication.shared.connectedScenes.first as? UIWindowScene)
|
||||
let window = UIWindow(windowScene: scene)
|
||||
window.frame = CGRect(x: 0, y: 0, width: 390, height: 844)
|
||||
window.frame = CGRect(x: 0, y: 0, width: width, height: 844)
|
||||
window.rootViewController = navigation
|
||||
window.makeKeyAndVisible()
|
||||
navigation.view.layoutIfNeeded()
|
||||
|
||||
Reference in New Issue
Block a user