Skip to content

Testing

ChiefVenzox edited this page Jun 5, 2026 · 1 revision

Testing

Run tests from the package root:

swift test

Current Test Coverage

NotebookFlowKit includes unit tests for:

  • JSON parsing
  • supported screen type aliases
  • blocked navigation when required answers are missing
  • answer collection
  • typed answer helpers
  • conditional navigation
  • route validation
  • missing next screen validation

Testing The Loader

Use NotebookFlowLoader to decode JSON data in tests:

let flow = try NotebookFlowLoader().decode(data)
XCTAssertEqual(flow.name, "StarterFlow")

Testing Navigation

Use FlowStateManager to test navigation without rendering SwiftUI.

let manager = FlowStateManager(flow: flow)

XCTAssertEqual(manager.currentScreen?.id, "welcome")
XCTAssertEqual(manager.advance(), .advanced(to: flow.screens[1]))

Testing Conditional Routes

manager.selectChoice("Fitness", for: "goal")
let event = manager.advance()

guard case .advanced(let screen) = event else {
    XCTFail("Expected advanced event")
    return
}

XCTAssertEqual(screen.id, "fitness_setup")

Clone this wiki locally