v0.3.0 — Phase β-2 Study-Loop

Voller Lern-Flow mit Web-Parität: fällige Karten via /reviews/due
laden, flip + rate (4 Buttons + Haptic), Grades via Offline-Queue
ans Server-FSRS schicken.

- Card/Review/DueReview DTOs mit snake_case + camelCase-deckId-
  Sonderfall im embedded card-Subobjekt
- CardType-Enum (alle 7 Typen), Rating-Enum mit deutschen Labels
- Cloze-Helper 1:1-Port aus cards-domain (extractClusterIds,
  subIndexCount, clusterId, renderPrompt/Answer, hint)
- CardsAPI.dueReviews(deckId:) + gradeReview(cardId,subIndex,rating,reviewedAt)
- PendingGrade SwiftData-Model + GradeQueue (FIFO-Drain, originaler
  Timestamp bleibt, bei Netzfehler in Queue, Retry beim nächsten Drain)
- StudySession @Observable State-Machine
- CardRenderer für basic, basic-reverse, cloze; Placeholder für
  image-occlusion/audio-front/typing/multiple-choice (β-3/β-4)
- RatingBar mit UIImpactFeedbackGenerator (medium/heavy)
- StudySessionView per NavigationLink aus DeckListView
- 9 neue Tests (Cloze: 8, Review-Decoding: 3), insgesamt 17 grün

Server-authoritative FSRS bleibt — kein ts-fsrs-Port.
Endurance-Test auf realem Gerät steht aus (siehe PLAN.md).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-05-13 00:16:11 +02:00
parent f664a00b64
commit 3b861af3fb
15 changed files with 1013 additions and 23 deletions

View file

@ -0,0 +1,59 @@
import Foundation
import Testing
@testable import CardsNative
@Suite("Cloze")
struct ClozeTests {
@Test("Extrahiert distinct Cluster-IDs sortiert")
func extractsClusterIds() {
let text = "{{c2::a}} und {{c1::b}} sowie {{c2::c}}"
#expect(Cloze.extractClusterIds(text) == [1, 2])
}
@Test("Leerer Text → leere Cluster-Liste")
func noClustersWhenEmpty() {
#expect(Cloze.extractClusterIds("Kein Cluster hier") == [])
}
@Test("subIndexCount entspricht distinct Clustern")
func subIndexCountMatchesClusters() {
#expect(Cloze.subIndexCount("Nur {{c1::eins}}") == 1)
#expect(Cloze.subIndexCount("{{c1::a}} {{c2::b}} {{c3::c}}") == 3)
#expect(Cloze.subIndexCount("Nichts") == 0)
}
@Test("clusterId-für-subIndex mappt aufsteigend")
func clusterIdForSubIndex() {
let text = "{{c2::a}} {{c1::b}}"
#expect(Cloze.clusterId(for: text, subIndex: 0) == 1)
#expect(Cloze.clusterId(for: text, subIndex: 1) == 2)
#expect(Cloze.clusterId(for: text, subIndex: 2) == nil)
}
@Test("Prompt ersetzt aktiven Cluster mit Ellipsis")
func renderPromptHidesActive() {
let text = "Hauptstadt von {{c1::Frankreich}} ist {{c2::Paris}}."
let prompt = Cloze.renderPrompt(text, activeClusterId: 2)
#expect(prompt == "Hauptstadt von Frankreich ist […].")
}
@Test("Prompt nutzt Hint wenn vorhanden")
func renderPromptUsesHint() {
let text = "Die {{c1::Sonne::Stern}} ist heiß."
#expect(Cloze.renderPrompt(text, activeClusterId: 1) == "Die [Stern] ist heiß.")
}
@Test("Answer markiert aktiven Cluster mit Markdown-Bold")
func renderAnswerBoldsActive() {
let text = "{{c1::A}} und {{c2::B}}"
#expect(Cloze.renderAnswer(text, activeClusterId: 1) == "**A** und B")
#expect(Cloze.renderAnswer(text, activeClusterId: 2) == "A und **B**")
}
@Test("Hint-Lookup gibt erstes Vorkommen")
func hintLookup() {
let text = "{{c1::a}} {{c1::b::tipp}}"
#expect(Cloze.hint(for: text, clusterId: 1) == "tipp")
#expect(Cloze.hint(for: text, clusterId: 2) == nil)
}
}

View file

@ -0,0 +1,83 @@
import Foundation
import Testing
@testable import CardsNative
@Suite("Review-JSON-Decoding")
struct ReviewDecodingTests {
@Test("Review-Wire-Format decodet vollständig")
func decodesReview() throws {
let json = """
{
"card_id": "card_1",
"sub_index": 0,
"user_id": "user_1",
"due": "2026-05-13T10:00:00.000Z",
"stability": 2.5,
"difficulty": 5.0,
"elapsed_days": 1.0,
"scheduled_days": 3.0,
"learning_steps": 0,
"reps": 5,
"lapses": 1,
"state": "review",
"last_review": "2026-05-10T10:00:00.000Z"
}
""".data(using: .utf8)!
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601withFractional
let review = try decoder.decode(Review.self, from: json)
#expect(review.cardId == "card_1")
#expect(review.subIndex == 0)
#expect(review.state == .review)
#expect(review.reps == 5)
#expect(review.lastReview != nil)
}
@Test("DueReview embedded card decodet (camelCase deckId!)")
func decodesDueReview() throws {
// Achtung: Server liefert hier `deckId` camelCase im embedded card,
// weil das aus Drizzle direkt rauskommt, nicht durch toCardDto.
let json = """
{
"card_id": "c1",
"sub_index": 0,
"user_id": "u1",
"due": "2026-05-13T10:00:00.000Z",
"stability": 0,
"difficulty": 0,
"elapsed_days": 0,
"scheduled_days": 0,
"learning_steps": 0,
"reps": 0,
"lapses": 0,
"state": "new",
"last_review": null,
"card": {
"id": "c1",
"deckId": "d1",
"type": "basic",
"fields": {"front": "Was ist 1+1?", "back": "2"}
}
}
""".data(using: .utf8)!
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601withFractional
let due = try decoder.decode(DueReview.self, from: json)
#expect(due.review.cardId == "c1")
#expect(due.card.deckId == "d1")
#expect(due.card.type == .basic)
#expect(due.card.fields["front"] == "Was ist 1+1?")
}
@Test("Rating-Enum-Werte sind exakt wie ts-fsrs erwartet")
func ratingValues() {
#expect(Rating.again.rawValue == "again")
#expect(Rating.hard.rawValue == "hard")
#expect(Rating.good.rawValue == "good")
#expect(Rating.easy.rawValue == "easy")
}
}