Files
attendi/Packages/Features/Tests/Recording/Models/TranscriptionTests.swift
T

108 lines
2.6 KiB
Swift

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)
}
@Test func `initializer stores the given identifier`() {
let id = UUID()
let transcription = Transcription(
id: id,
text: "This is a transcription."
)
#expect(transcription.id == id)
}
}
// 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: Equatable
@Suite("Equatable")
struct EquatableConformance {
@Test func `transcriptions with the same identifier and text are equal`() {
let id = UUID()
let first = Transcription(
id: id,
text: "This is a transcription."
)
let second = Transcription(
id: id,
text: "This is a transcription."
)
#expect(first == second)
}
@Test func `transcriptions with generated identifiers are never equal`() {
let first = Transcription(text: "This is a transcription.")
let second = Transcription(text: "This is a transcription.")
#expect(first != second)
}
}
// 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)
}
}
}