From 8b46c4e7d1e612f76716e2df24fced93fbdd6264 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Sat, 4 Jul 2026 10:48:57 +0200 Subject: [PATCH] Implemented the Transcription model in the Recording package target. --- .../View Models/ContentViewModel.swift | 12 ---- .../Recording/Models/Transcription.swift | 35 ++++++++++ .../Recording/Models/TranscriptionTests.swift | 68 +++++++++++++++++++ .../RecordingViewModelTests.swift | 0 4 files changed, 103 insertions(+), 12 deletions(-) create mode 100644 Packages/Features/Sources/Recording/Models/Transcription.swift create mode 100644 Packages/Features/Tests/Recording/Models/TranscriptionTests.swift rename Packages/Features/Tests/Recording/{ => View Models}/RecordingViewModelTests.swift (100%) diff --git a/Apps/Attendi/View Models/ContentViewModel.swift b/Apps/Attendi/View Models/ContentViewModel.swift index 16efd82..f15e346 100644 --- a/Apps/Attendi/View Models/ContentViewModel.swift +++ b/Apps/Attendi/View Models/ContentViewModel.swift @@ -45,15 +45,3 @@ extension ContentView { } } - -// MARK: - Models - -extension ContentView.Model { - /// A transcription of a processed recording to present in the modal sheet. - struct Transcription: Identifiable { - /// The unique identifier of the transcription. - let id = UUID() - /// The transcribed text of the processed recording. - let text: String - } -} diff --git a/Packages/Features/Sources/Recording/Models/Transcription.swift b/Packages/Features/Sources/Recording/Models/Transcription.swift new file mode 100644 index 0000000..5c88ebc --- /dev/null +++ b/Packages/Features/Sources/Recording/Models/Transcription.swift @@ -0,0 +1,35 @@ +import Foundation + +/// A transcription of a processed recording. +public struct Transcription { + + // MARK: Properties + + /// The unique identifier of the transcription. + public let id: UUID = .init() + + /// The transcribed text of the processed recording. + public let text: String + + // MARK: Initializers + + /// Creates a transcription with a given text. + /// - Parameter text: The transcribed text of the processed recording. + public init( + text: String + ) { + self.text = text + } + + // MARK: Computed + + /// A Boolean value that indicates whether the transcription has no text. + var isEmpty: Bool { + text.isEmpty + } + +} + +// MARK: - Identifiable + +extension Transcription: Identifiable {} diff --git a/Packages/Features/Tests/Recording/Models/TranscriptionTests.swift b/Packages/Features/Tests/Recording/Models/TranscriptionTests.swift new file mode 100644 index 0000000..19113f1 --- /dev/null +++ b/Packages/Features/Tests/Recording/Models/TranscriptionTests.swift @@ -0,0 +1,68 @@ +import Foundation +import Testing + +@testable import Recording + +@Suite("Transcription model") +struct TranscriptionTests { + + // MARK: Initializers + + @Suite("Initializers") + struct Initializers { + + @Test(arguments: [ + "", + "This is a transcription.", + " ", + "Multiline\ntranscribed\ntext." + ]) + func `initializer stores the given text`(text: String) { + let transcription = Transcription(text: text) + + #expect(transcription.text == text) + } + + } + + // MARK: Computed properties + + @Suite("Computed properties") + struct ComputedProperties { + + @Test(arguments: zip( + ["", "This is a transcription.", " "], + [true, false, false] + )) + func `is empty only when the text has no characters`( + for text: String, + expected: Bool + ) { + let transcription = Transcription(text: text) + + #expect(transcription.isEmpty == expected) + } + + } + + // MARK: Identifiable + + @Suite("Identifiable") + struct IdentifiableConformance { + + @Test func `identifier is stable across accesses`() { + let transcription = Transcription(text: "This is a transcription.") + + #expect(transcription.id == transcription.id) + } + + @Test func `identifiers differ between transcriptions`() { + let first = Transcription(text: "This is a transcription.") + let second = Transcription(text: "This is a transcription.") + + #expect(first.id != second.id) + } + + } + +} diff --git a/Packages/Features/Tests/Recording/RecordingViewModelTests.swift b/Packages/Features/Tests/Recording/View Models/RecordingViewModelTests.swift similarity index 100% rename from Packages/Features/Tests/Recording/RecordingViewModelTests.swift rename to Packages/Features/Tests/Recording/View Models/RecordingViewModelTests.swift