Add textbook reader, exercise grading, stem-change toggle, extraction pipeline
Major changes: - Textbook UI: chapter list, reader, and interactive exercise view (keyboard + Apple Pencil) surfaced under the Course tab. 30 chapters, 251 exercises. - Stem-change conjugation toggle on Week 4 flashcard decks (E-IE, E-I, O-UE). Uses existing VerbForm + IrregularSpan data to render highlighted present tense conjugations inline. - Deterministic on-device answer grader with partial credit (correct / close for accent-stripped or single-char-typo / wrong). 11 unit tests cover it. - SharedModels: TextbookChapter (local), TextbookExerciseAttempt (cloud- synced), AnswerGrader helpers. Bumped schema. - DataLoader: textbook seeder (version 8) + refresh helpers that preserve LanGo course decks when textbook data is re-seeded. - Local extraction pipeline in Conjuga/Scripts/textbook/ — XHTML chapter parser, answer-key parser, macOS Vision image OCR + PDF page OCR, merger, NSSpellChecker validator, language-aware auto-fixer, and repair pass that re-pairs quarantined vocab rows using bounding-box coordinates. - UI test target (ConjugaUITests) with three tests: end-to-end textbook flow, all-chapters screenshot audit, and stem-change toggle verification. Generated textbook content (textbook_data.json, textbook_vocab.json) and third-party source files are gitignored — re-run Scripts/textbook/run_pipeline.sh locally to regenerate. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
95
Conjuga/ConjugaUITests/AllChaptersScreenshotTests.swift
Normal file
95
Conjuga/ConjugaUITests/AllChaptersScreenshotTests.swift
Normal file
@@ -0,0 +1,95 @@
|
||||
import XCTest
|
||||
|
||||
/// Screenshot every chapter of the textbook — one top + one bottom frame each —
|
||||
/// so you can visually audit parsing / rendering issues across all 30 chapters.
|
||||
final class AllChaptersScreenshotTests: XCTestCase {
|
||||
|
||||
override func setUpWithError() throws {
|
||||
continueAfterFailure = true
|
||||
}
|
||||
|
||||
func testScreenshotEveryChapter() throws {
|
||||
let app = XCUIApplication()
|
||||
app.launchArguments += ["-onboardingComplete", "YES"]
|
||||
app.launch()
|
||||
|
||||
let courseTab = app.tabBars.buttons["Course"]
|
||||
XCTAssertTrue(courseTab.waitForExistence(timeout: 5))
|
||||
courseTab.tap()
|
||||
|
||||
let textbookRow = app.buttons.containing(NSPredicate(
|
||||
format: "label CONTAINS[c] 'Complete Spanish'"
|
||||
)).firstMatch
|
||||
XCTAssertTrue(textbookRow.waitForExistence(timeout: 5))
|
||||
textbookRow.tap()
|
||||
|
||||
// NOTE: SwiftUI List preserves scroll position across navigation pushes,
|
||||
// so visiting chapters in-order means the next one is already visible
|
||||
// after we return from the previous one. No need to reset.
|
||||
attach(app, name: "00-chapter-list-top")
|
||||
|
||||
for chapter in 1...30 {
|
||||
guard let row = findChapterRow(app: app, chapter: chapter) else {
|
||||
XCTFail("Chapter \(chapter) row not reachable")
|
||||
continue
|
||||
}
|
||||
row.tap()
|
||||
|
||||
// Chapter body — wait until the chapter's title appears as a nav bar label
|
||||
_ = app.navigationBars.firstMatch.waitForExistence(timeout: 3)
|
||||
|
||||
attach(app, name: String(format: "ch%02d-top", chapter))
|
||||
// One big scroll to sample the bottom of the chapter
|
||||
dragFullScreen(app, direction: .up)
|
||||
dragFullScreen(app, direction: .up)
|
||||
attach(app, name: String(format: "ch%02d-bottom", chapter))
|
||||
|
||||
tapNavBack(app)
|
||||
// Small settle wait
|
||||
_ = app.navigationBars.firstMatch.waitForExistence(timeout: 2)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private enum DragDirection { case up, down }
|
||||
|
||||
private func dragFullScreen(_ app: XCUIApplication, direction: DragDirection) {
|
||||
let top = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.12))
|
||||
let bot = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.88))
|
||||
switch direction {
|
||||
case .up: bot.press(forDuration: 0.1, thenDragTo: top)
|
||||
case .down: top.press(forDuration: 0.1, thenDragTo: bot)
|
||||
}
|
||||
}
|
||||
|
||||
private func findChapterRow(app: XCUIApplication, chapter: Int) -> XCUIElement? {
|
||||
// Chapter row accessibility label: "<n>, <title>, ..." (SwiftUI composes
|
||||
// label from inner Texts). Match by starting number.
|
||||
let predicate = NSPredicate(format: "label BEGINSWITH %@", "\(chapter),")
|
||||
let row = app.buttons.matching(predicate).firstMatch
|
||||
|
||||
if row.exists && row.isHittable { return row }
|
||||
|
||||
// Scroll down up to 8 times searching for the row — chapters visited
|
||||
// in order, so usually 0–2 swipes suffice.
|
||||
for _ in 0..<8 {
|
||||
if row.exists && row.isHittable { return row }
|
||||
dragFullScreen(app, direction: .up)
|
||||
}
|
||||
return row.exists ? row : nil
|
||||
}
|
||||
|
||||
private func tapNavBack(_ app: XCUIApplication) {
|
||||
let back = app.navigationBars.buttons.firstMatch
|
||||
if back.exists && back.isHittable { back.tap() }
|
||||
}
|
||||
|
||||
private func attach(_ app: XCUIApplication, name: String) {
|
||||
let screenshot = app.screenshot()
|
||||
let attachment = XCTAttachment(screenshot: screenshot)
|
||||
attachment.name = name
|
||||
attachment.lifetime = .keepAlways
|
||||
add(attachment)
|
||||
}
|
||||
}
|
||||
66
Conjuga/ConjugaUITests/StemChangeToggleTests.swift
Normal file
66
Conjuga/ConjugaUITests/StemChangeToggleTests.swift
Normal file
@@ -0,0 +1,66 @@
|
||||
import XCTest
|
||||
|
||||
final class StemChangeToggleTests: XCTestCase {
|
||||
|
||||
override func setUpWithError() throws {
|
||||
continueAfterFailure = false
|
||||
}
|
||||
|
||||
func testStemChangeConjugationToggle() throws {
|
||||
let app = XCUIApplication()
|
||||
app.launchArguments += ["-onboardingComplete", "YES"]
|
||||
app.launch()
|
||||
|
||||
// Course → LanGo Beginner I → Week 4 → E-IE stem-changing verbs
|
||||
app.tabBars.buttons["Course"].tap()
|
||||
|
||||
// Locate the E-IE deck row. Deck titles appear as static text / button.
|
||||
// Scroll until visible, then tap.
|
||||
let deckPredicate = NSPredicate(format: "label CONTAINS[c] 'E-IE stem changing verbs' AND NOT label CONTAINS[c] 'REVÉS'")
|
||||
let deckRow = app.buttons.matching(deckPredicate).firstMatch
|
||||
|
||||
let listRef = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.85))
|
||||
let topRef = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.10))
|
||||
for _ in 0..<12 {
|
||||
if deckRow.exists && deckRow.isHittable { break }
|
||||
listRef.press(forDuration: 0.1, thenDragTo: topRef)
|
||||
}
|
||||
XCTAssertTrue(deckRow.waitForExistence(timeout: 3), "E-IE deck row missing")
|
||||
deckRow.tap()
|
||||
|
||||
attach(app, name: "01-deck-top")
|
||||
|
||||
// Tap "Show conjugation" on the first card
|
||||
let showBtn = app.buttons.matching(NSPredicate(format: "label BEGINSWITH 'Show conjugation'")).firstMatch
|
||||
XCTAssertTrue(showBtn.waitForExistence(timeout: 3), "Show conjugation button missing")
|
||||
showBtn.tap()
|
||||
|
||||
// Wait for the conjugation rows + animation to settle.
|
||||
let yoLabel = app.staticTexts["yo"].firstMatch
|
||||
XCTAssertTrue(yoLabel.waitForExistence(timeout: 3), "yo row not rendered")
|
||||
// Give the transition time to complete before snapshotting.
|
||||
Thread.sleep(forTimeInterval: 0.6)
|
||||
attach(app, name: "02-conjugation-open")
|
||||
|
||||
// Also confirm all expected person labels are rendered.
|
||||
for person in ["yo", "tú", "nosotros"] {
|
||||
XCTAssertTrue(
|
||||
app.staticTexts[person].firstMatch.exists,
|
||||
"missing conjugation row for \(person)"
|
||||
)
|
||||
}
|
||||
|
||||
// Tap again to hide
|
||||
let hideBtn = app.buttons.matching(NSPredicate(format: "label BEGINSWITH 'Hide conjugation'")).firstMatch
|
||||
XCTAssertTrue(hideBtn.waitForExistence(timeout: 2))
|
||||
hideBtn.tap()
|
||||
}
|
||||
|
||||
private func attach(_ app: XCUIApplication, name: String) {
|
||||
let s = app.screenshot()
|
||||
let a = XCTAttachment(screenshot: s)
|
||||
a.name = name
|
||||
a.lifetime = .keepAlways
|
||||
add(a)
|
||||
}
|
||||
}
|
||||
80
Conjuga/ConjugaUITests/TextbookFlowUITests.swift
Normal file
80
Conjuga/ConjugaUITests/TextbookFlowUITests.swift
Normal file
@@ -0,0 +1,80 @@
|
||||
import XCTest
|
||||
|
||||
final class TextbookFlowUITests: XCTestCase {
|
||||
|
||||
override func setUpWithError() throws {
|
||||
continueAfterFailure = false
|
||||
}
|
||||
|
||||
func testTextbookFlow() throws {
|
||||
let app = XCUIApplication()
|
||||
// Skip onboarding via defaults (already set by run script, but harmless to override)
|
||||
app.launchArguments += ["-onboardingComplete", "YES"]
|
||||
app.launch()
|
||||
|
||||
// Dashboard should be default tab. Switch to Course.
|
||||
let courseTab = app.tabBars.buttons["Course"]
|
||||
XCTAssertTrue(courseTab.waitForExistence(timeout: 5), "Course tab missing")
|
||||
courseTab.tap()
|
||||
|
||||
// Attach a screenshot of the Course list
|
||||
attach(app, name: "01-course-list")
|
||||
|
||||
// Tap the Textbook entry
|
||||
let textbookRow = app.buttons.containing(NSPredicate(
|
||||
format: "label CONTAINS[c] 'Complete Spanish'"
|
||||
)).firstMatch
|
||||
XCTAssertTrue(textbookRow.waitForExistence(timeout: 5), "Textbook row missing in Course")
|
||||
textbookRow.tap()
|
||||
|
||||
attach(app, name: "02-textbook-chapter-list")
|
||||
|
||||
// Tap chapter 1 — should navigate to reader
|
||||
let chapterOneRow = app.buttons.containing(NSPredicate(
|
||||
format: "label CONTAINS[c] 'Nouns, Articles'"
|
||||
)).firstMatch
|
||||
XCTAssertTrue(chapterOneRow.waitForExistence(timeout: 5), "Chapter 1 row missing")
|
||||
chapterOneRow.tap()
|
||||
|
||||
attach(app, name: "03-chapter-body")
|
||||
|
||||
// Find the first exercise link ("Exercise 1.1")
|
||||
let exerciseRow = app.buttons.containing(NSPredicate(
|
||||
format: "label CONTAINS[c] 'Exercise 1.1'"
|
||||
)).firstMatch
|
||||
XCTAssertTrue(exerciseRow.waitForExistence(timeout: 5), "Exercise 1.1 link missing")
|
||||
exerciseRow.tap()
|
||||
|
||||
attach(app, name: "04-exercise-view")
|
||||
|
||||
// Check presence of input fields: at least a few numbered prompts
|
||||
// Text fields use SwiftUI placeholder "Your answer"
|
||||
let firstField = app.textFields["Your answer"].firstMatch
|
||||
XCTAssertTrue(firstField.waitForExistence(timeout: 5), "No input fields rendered for exercise")
|
||||
firstField.tap()
|
||||
firstField.typeText("el")
|
||||
|
||||
attach(app, name: "05-exercise-typed-el")
|
||||
|
||||
// Tap Check answers
|
||||
let checkButton = app.buttons["Check answers"]
|
||||
XCTAssertTrue(checkButton.waitForExistence(timeout: 3), "Check answers button missing")
|
||||
checkButton.tap()
|
||||
|
||||
attach(app, name: "06-exercise-graded")
|
||||
|
||||
// The first answer to Exercise 1.1 is "el" — we should see the first prompt
|
||||
// graded correct. Iterating too deeply is fragile; just take a screenshot
|
||||
// and check for presence of either a checkmark-like label or "Try again".
|
||||
let tryAgain = app.buttons["Try again"]
|
||||
XCTAssertTrue(tryAgain.waitForExistence(timeout: 3), "Grading did not complete")
|
||||
}
|
||||
|
||||
private func attach(_ app: XCUIApplication, name: String) {
|
||||
let screenshot = app.screenshot()
|
||||
let attachment = XCTAttachment(screenshot: screenshot)
|
||||
attachment.name = name
|
||||
attachment.lifetime = .keepAlways
|
||||
add(attachment)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user