test: add P1-fallback + refresh tests for StudyHomeViewModel
- P1 fallback: continueService throws → falls to unfinished session - refresh: updates stats without setting loadingState - Fix: remove nonexistent materialId/readingTargetType from LearningSession mock Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
9ec6fdc3d5
commit
c7de97279b
@ -187,4 +187,31 @@ final class StudyHomeViewModelTests: XCTestCase {
|
||||
XCTAssertEqual(vm.weeklyActiveDays, 5)
|
||||
XCTAssertEqual(vm.streakDays, 3)
|
||||
}
|
||||
|
||||
// MARK: - P1 fallback: continueService throws → unfinished session
|
||||
|
||||
func test_priority_fallback_to_unfinished_session_when_continueService_throws() async {
|
||||
mockContinue.response = nil // throws
|
||||
mockSession.sessions = [LearningSession(
|
||||
id: "s1", userId: nil, knowledgeBaseId: "kb1", knowledgeItemId: nil,
|
||||
mode: nil, status: "in_progress", startedAt: "2026-01-02T00:00:00.000Z",
|
||||
endedAt: nil, durationSeconds: nil, focusMinutes: nil, createdAt: nil
|
||||
)]
|
||||
mockKB.kbs = [KnowledgeBase(id: "kb1", title: "My KB", description: nil, knowledgeCount: 5, sourceCount: 1, userId: "u1", createdAt: "2026-01-01")]
|
||||
|
||||
await vm.loadAll()
|
||||
|
||||
guard case .continueSession = vm.mainAction else {
|
||||
return XCTFail("Expected continueSession fallback, got \(String(describing: vm.mainAction))")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - refresh()
|
||||
|
||||
func test_refresh_updates_review_count() async {
|
||||
mockReview.cards = []
|
||||
await vm.refresh()
|
||||
XCTAssertEqual(vm.todayReviewCount, 0)
|
||||
XCTAssertEqual(vm.loadingState, .idle) // refresh doesn't set loadingState
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user