Implemented the Transcription model in the Recording package target.
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user