31f5937a7f
Reduce extension memory pressure and delivery races while adding richer candidates, tactile feedback, and safer two-level creative polishing.
107 lines
3.3 KiB
Swift
107 lines
3.3 KiB
Swift
// MicVoiceAvailabilityTests.swift
|
|
// OSGKeyboardTests
|
|
|
|
import XCTest
|
|
@testable import OSGKeyboardShared
|
|
|
|
final class MicVoiceAvailabilityTests: XCTestCase {
|
|
|
|
func testReadyWhenHostReadyAndIdle() {
|
|
let availability = MicVoiceAvailabilityResolver.resolve(
|
|
phase: .idle,
|
|
micDisabled: false,
|
|
hasFullAccess: true,
|
|
appGroupAvailable: true,
|
|
hostReady: true,
|
|
isPreparingSession: false
|
|
)
|
|
XCTAssertEqual(availability, .ready)
|
|
}
|
|
|
|
func testUnavailableWhenMissingAPIKey() {
|
|
let availability = MicVoiceAvailabilityResolver.resolve(
|
|
phase: .idle,
|
|
micDisabled: true,
|
|
hasFullAccess: true,
|
|
appGroupAvailable: true,
|
|
hostReady: true,
|
|
isPreparingSession: false
|
|
)
|
|
XCTAssertEqual(availability, .unavailable(.missingAPIKey))
|
|
}
|
|
|
|
func testUnavailableWhenHostNotReady() {
|
|
let availability = MicVoiceAvailabilityResolver.resolve(
|
|
phase: .idle,
|
|
micDisabled: false,
|
|
hasFullAccess: true,
|
|
appGroupAvailable: true,
|
|
hostReady: false,
|
|
isPreparingSession: false
|
|
)
|
|
XCTAssertEqual(availability, .unavailable(.hostNotReady))
|
|
}
|
|
|
|
func testUnavailableWhenPreparingSession() {
|
|
let availability = MicVoiceAvailabilityResolver.resolve(
|
|
phase: .idle,
|
|
micDisabled: false,
|
|
hasFullAccess: true,
|
|
appGroupAvailable: true,
|
|
hostReady: false,
|
|
isPreparingSession: true
|
|
)
|
|
XCTAssertEqual(availability, .unavailable(.preparingSession))
|
|
}
|
|
|
|
func testRecordingOverridesReady() {
|
|
let availability = MicVoiceAvailabilityResolver.resolve(
|
|
phase: .recording,
|
|
micDisabled: false,
|
|
hasFullAccess: true,
|
|
appGroupAvailable: true,
|
|
hostReady: true,
|
|
isPreparingSession: false
|
|
)
|
|
XCTAssertEqual(availability, .recording)
|
|
}
|
|
|
|
func testUnavailableWhenOnboardingIncomplete() {
|
|
let availability = MicVoiceAvailabilityResolver.resolve(
|
|
phase: .idle,
|
|
micDisabled: false,
|
|
hasFullAccess: true,
|
|
appGroupAvailable: true,
|
|
hostReady: true,
|
|
isPreparingSession: false,
|
|
hasCompletedOnboarding: false
|
|
)
|
|
XCTAssertEqual(availability, .unavailable(.onboardingIncomplete))
|
|
}
|
|
|
|
func testOnboardingIncompleteTakesPrecedenceOverMissingAPIKey() {
|
|
let availability = MicVoiceAvailabilityResolver.resolve(
|
|
phase: .idle,
|
|
micDisabled: true,
|
|
hasFullAccess: true,
|
|
appGroupAvailable: true,
|
|
hostReady: true,
|
|
isPreparingSession: false,
|
|
hasCompletedOnboarding: false
|
|
)
|
|
XCTAssertEqual(availability, .unavailable(.onboardingIncomplete))
|
|
}
|
|
|
|
func testProcessingOverridesUnavailable() {
|
|
let availability = MicVoiceAvailabilityResolver.resolve(
|
|
phase: .processing,
|
|
micDisabled: false,
|
|
hasFullAccess: true,
|
|
appGroupAvailable: true,
|
|
hostReady: false,
|
|
isPreparingSession: false
|
|
)
|
|
XCTAssertEqual(availability, .processing)
|
|
}
|
|
}
|