Improved the Capturing protocol in the Recording package target to capture interruptions and pause any active capture process.

This commit is contained in:
2026-07-04 15:19:26 +02:00
parent 6a0e7698a5
commit 1f1ac630f3
5 changed files with 211 additions and 17 deletions
@@ -342,6 +342,47 @@ struct RecordingViewModelTests {
}
// MARK: Interruptions
@MainActor
@Suite("Interruptions")
struct Interruptions {
@Test func `pauses an ongoing recording when the capture is interrupted`() async throws {
let capturer = CapturingMock()
let model = Model(capturer: capturer)
model.pressedMain()
try await Task.sleep(for: .seconds(0.1))
capturer.interrupt()
try await Task.sleep(for: .seconds(0.1))
#expect(model.state == .paused)
#expect(capturer.calls == ["start", "pause"])
}
@Test func `changes nothing when the capture is interrupted while paused`() async throws {
let capturer = CapturingMock()
let model = Model(capturer: capturer)
model.pressedMain()
model.pressedMain()
try await Task.sleep(for: .seconds(0.1))
capturer.interrupt()
try await Task.sleep(for: .seconds(0.1))
#expect(model.state == .paused)
#expect(capturer.calls == ["start", "pause"])
}
}
// MARK: Processing
@MainActor