feat(training): 新增已结束筛选并精简课程展示
新增已结束任务筛选与只读回顾资格,保留搜索和游标分页。移除任务小节数量及课程附件文件名、切换入口,并更新接口和界面回归测试。
This commit is contained in:
@@ -25,6 +25,7 @@ struct TrainingUIRenderingTests {
|
||||
Attachment.record(render(navigation.view), named: "培训首页", as: .png)
|
||||
let labels = allViews(controller.view).compactMap { $0 as? UILabel }
|
||||
#expect(labels.contains { $0.text == "一线服务规范学习" })
|
||||
#expect(labels.contains { $0.text == "学习 + 考试 · 30 题 · 80 分及格" })
|
||||
#expect(!labels.contains { $0.text?.contains("未同步景区后台") == true })
|
||||
|
||||
let original = try await source.task(id: "demo-service")
|
||||
@@ -34,6 +35,9 @@ struct TrainingUIRenderingTests {
|
||||
scoring: original.scoring, course: original.course, questions: original.questions, progress: original.progress)
|
||||
let cell = TrainingTaskCell(style: .default, reuseIdentifier: nil)
|
||||
cell.configure(task: longTask)
|
||||
#expect(allViews(cell.contentView).compactMap { $0 as? UILabel }.contains {
|
||||
$0.text == "学习 + 考试 · \(longTask.questions.count) 题 · \(longTask.passScore) 分及格"
|
||||
})
|
||||
let width: CGFloat = 320
|
||||
let shortCell = TrainingTaskCell(style: .default, reuseIdentifier: nil)
|
||||
shortCell.configure(task: original)
|
||||
@@ -55,6 +59,59 @@ struct TrainingUIRenderingTests {
|
||||
cell.layer.render(in: context.cgContext)
|
||||
}
|
||||
Attachment.record(cardImage, named: "320点长标题任务卡", as: .png)
|
||||
cell.configure(task: try await source.task(id: "demo-study"))
|
||||
#expect(allViews(cell.contentView).compactMap { $0 as? UILabel }.contains { $0.text == "仅学习" })
|
||||
}
|
||||
|
||||
@Test("任务页三种筛选独立查询,已结束任务显示回顾入口")
|
||||
func endedFilterAndReadOnlyCard() async throws {
|
||||
let source = TrainingDataStub()
|
||||
await source.configure {
|
||||
$0.tasksHandler = { status, _, _, _ in
|
||||
let state = status ?? .pendingExam
|
||||
return TrainingCursorPage(items: [TrainingRemoteFixtures.task(id: state.apiValue,
|
||||
title: "\(state.title)任务", learnerStatus: state)], nextCursor: nil, hasMore: false, serverTime: nil)
|
||||
}
|
||||
}
|
||||
for width: CGFloat in [320, 390] {
|
||||
let controller = TrainingCenterViewController(service: source)
|
||||
let navigation = UINavigationController(rootViewController: controller)
|
||||
let window = try makeWindow(navigation, width: width)
|
||||
defer { window.isHidden = true }
|
||||
controller.selectTab(.tasks)
|
||||
let buttons = allViews(controller.view).compactMap { $0 as? UIButton }
|
||||
.filter { $0.accessibilityIdentifier?.hasPrefix("training.filter.") == true }
|
||||
#expect(buttons.count == 3)
|
||||
for state in [TrainingLearnerStatus.ended, .completed, .pendingExam, .ended] {
|
||||
let index = try #require(TrainingLearnerStatus.allCases.firstIndex(of: state))
|
||||
let button = try #require(buttons.first { $0.tag == index })
|
||||
button.sendActions(for: .touchUpInside)
|
||||
let deadline = ContinuousClock.now.advanced(by: .seconds(5))
|
||||
while ContinuousClock.now < deadline {
|
||||
navigation.view.layoutIfNeeded()
|
||||
let hasTask = allViews(controller.view).compactMap { $0 as? UILabel }.contains { $0.text == "\(state.title)任务" }
|
||||
if button.accessibilityTraits.contains(.selected), hasTask { break }
|
||||
try await Task.sleep(for: .milliseconds(10))
|
||||
}
|
||||
#expect(button.accessibilityTraits.contains(.selected))
|
||||
#expect(buttons.filter { $0.accessibilityTraits.contains(.selected) }.count == 1)
|
||||
#expect(allViews(controller.view).compactMap { $0 as? UILabel }.contains { $0.text == "\(state.title)任务" })
|
||||
}
|
||||
#expect(buttons.map { $0.configuration?.title } == ["待考试 1", "已完成 0", "已结束"])
|
||||
for button in buttons {
|
||||
let frame = button.convert(button.bounds, to: controller.view)
|
||||
#expect(frame.minX >= 0 && frame.maxX <= width + 1)
|
||||
#expect(frame.height >= 44)
|
||||
}
|
||||
let labels = allViews(controller.view).compactMap { $0 as? UILabel }
|
||||
#expect(labels.contains { $0.text == "已结束" && $0.textColor == TrainingUI.muted })
|
||||
#expect(labels.contains { $0.text == "任务已结束,仅可回顾课程内容" })
|
||||
let action = try #require(allViews(controller.view).compactMap { $0 as? UIButton }
|
||||
.first { $0.accessibilityIdentifier == "training.task.action.ended" })
|
||||
#expect(action.configuration?.title == "回顾学习")
|
||||
#expect(action.isEnabled)
|
||||
Attachment.record(render(navigation.view), named: "\(Int(width))点-已结束筛选与只读任务", as: .png)
|
||||
}
|
||||
}
|
||||
|
||||
@Test("课程与考试步骤等宽居中,窄屏和大字体不裁切")
|
||||
@@ -103,6 +160,8 @@ struct TrainingUIRenderingTests {
|
||||
let buttons = allViews(controller.view).compactMap { $0 as? UIButton }
|
||||
#expect(!buttons.contains { $0.accessibilityIdentifier == "training.reading.sections" || $0.accessibilityIdentifier == "training.reading.attachments" })
|
||||
#expect(!buttons.contains { $0.configuration?.title == "章节目录" || $0.configuration?.title == "课程附件" })
|
||||
#expect(!buttons.contains { $0.accessibilityIdentifier == "training.reading.documentPicker" })
|
||||
#expect(!buttons.contains { $0.configuration?.title == "切换附件" || $0.configuration?.title == "培训资料.txt" })
|
||||
let frame = step.convert(step.bounds, to: controller.view)
|
||||
#expect(abs(frame.minY - controller.view.safeAreaInsets.top - 8) < 1)
|
||||
let preview = try #require(allViews(controller.view).compactMap { $0 as? TrainingDocumentPreviewView }.first)
|
||||
|
||||
Reference in New Issue
Block a user