Added a discard button and error handling to the RecordingView view in the Recording package target.

This commit is contained in:
2026-07-04 15:59:30 +02:00
parent 7ec49264e6
commit b0c6e25639
7 changed files with 339 additions and 14 deletions
@@ -66,6 +66,23 @@ struct RecordingViewModelTests {
#expect(model.state == expected)
}
@Test(arguments: zip(
[Model.State.notRecording, .recording, .paused, .processing],
[Model.State.notRecording, .recording, .notRecording, .processing]
))
func `pressed discard transitions to the expected state`(
from initial: Model.State,
to expected: Model.State
) {
let model = Model()
model.drive(to: initial)
model.pressedDiscard()
#expect(model.state == expected)
}
}
// MARK: Computed properties
@@ -134,6 +151,21 @@ struct RecordingViewModelTests {
#expect(model.shouldDisableMain == expected)
}
@Test(arguments: zip(
[Model.State.notRecording, .recording, .paused, .processing],
[false, false, true, false]
))
func `discard button is visible only while paused`(
for state: Model.State,
expected: Bool
) {
let model = Model()
model.drive(to: state)
#expect(model.shouldShowDiscard == expected)
}
@Test(arguments: zip(
[Model.State.notRecording, .recording, .paused, .processing],
[false, false, true, true]
@@ -305,6 +337,21 @@ struct RecordingViewModelTests {
#expect(capturer.calls == ["start", "pause", "stop"])
}
@Test func `stops the capture when a paused recording is discarded`() async throws {
let capturer = CapturingMock()
let model = Model(capturer: capturer)
model.drive(to: .paused)
model.pressedDiscard()
try await Task.sleep(for: .seconds(0.1))
#expect(capturer.calls == ["start", "pause", "stop"])
#expect(model.state == .notRecording)
#expect(model.elapsedSeconds == 0)
}
@Test func `serializes the calls when states change rapidly`() async throws {
let capturer = CapturingMock()
@@ -378,6 +425,23 @@ struct RecordingViewModelTests {
#expect(model.error == .permissionDenied)
}
@Test func `surfaces unavailable speech model assets`() async throws {
let transcriber = TranscribingMock()
transcriber.error = AudioTranscribingError.assetsNotInstalled
let model = Model(
transcribe: transcriber
)
model.drive(to: .processing)
try await Task.sleep(for: .seconds(0.5))
#expect(model.error == .assetsUnavailable)
#expect(model.transcription == nil)
}
@Test func `surfaces a transcription failure`() async throws {
let transcriber = TranscribingMock()