Files
OSGKeyboard/OSGKeyboardTests/FlowHomePiPStatusPolicyTests.swift
T
Rocky 1ad22b8697
CI / Validate manifests (push) Has been cancelled
CI / SwiftLint (push) Has been cancelled
CI / iOS / Extension (push) Has been cancelled
CI / macOS (push) Has been cancelled
fix(home): simplify transient Flow status card
Show only connection state while Flow is preparing or unavailable, and remove the card entirely once the session is healthy.
2026-08-20 20:26:09 +08:00

148 lines
4.2 KiB
Swift

// FlowHomePiPStatusPolicyTests.swift
// OSGKeyboardTests
@testable import OSGKeyboard
import XCTest
final class FlowHomePiPStatusPolicyTests: XCTestCase {
func testPreparingAndRecoveringExposeAttemptProgress() {
XCTAssertEqual(
descriptor(for: .preparing(attempt: 1, total: 3)),
.progress(
localizationKey: "home.flow.preparingProgress",
attempt: 1,
total: 3
)
)
XCTAssertEqual(
descriptor(for: .recovering(attempt: 2, total: 3)),
.progress(
localizationKey: "home.flow.recoveringProgress",
attempt: 2,
total: 3
)
)
}
func testTakeoverAndFailureUseActionableStatuses() {
XCTAssertEqual(
descriptor(for: .waitingForForeground),
.text(localizationKey: "home.flow.waitingForForeground")
)
XCTAssertEqual(
descriptor(for: .failed(.systemRejected)),
.text(localizationKey: "home.flow.recoveryFailed")
)
}
func testActiveSessionDoesNotClaimReadyWithoutReadyContract() {
XCTAssertEqual(
FlowHomePiPStatusPolicy.descriptor(
lifecycle: .active,
isStarting: false,
isRecording: false,
isProcessing: false,
isActive: true,
isHostReady: false
),
.text(localizationKey: "home.flow.notReady")
)
XCTAssertEqual(
FlowHomePiPStatusPolicy.descriptor(
lifecycle: .active,
isStarting: false,
isRecording: false,
isProcessing: false,
isActive: true,
isHostReady: true
),
.text(localizationKey: "home.flow.label")
)
}
func testRetryAppearsOnlyForRecoverableFailureWithPermissions() {
XCTAssertTrue(
FlowHomePiPStatusPolicy.canRetry(
lifecycle: .failed(.timedOut),
needsPermissionSetup: false
)
)
XCTAssertFalse(
FlowHomePiPStatusPolicy.canRetry(
lifecycle: .failed(.timedOut),
needsPermissionSetup: true
)
)
XCTAssertFalse(
FlowHomePiPStatusPolicy.canRetry(
lifecycle: .recovering(attempt: 1, total: 3),
needsPermissionSetup: false
)
)
}
func testConnectionCardDisappearsWhenSessionIsHealthy() {
XCTAssertFalse(
shouldShowConnectionCard(
lifecycle: .active,
isHostReady: true
)
)
}
func testConnectionCardRemainsVisibleWhilePreparingOrFailed() {
XCTAssertTrue(
shouldShowConnectionCard(
lifecycle: .preparing(attempt: 1, total: 3),
isHostReady: false
)
)
XCTAssertTrue(
shouldShowConnectionCard(
lifecycle: .failed(.timedOut),
isHostReady: false
)
)
}
func testNormalRecordingDoesNotBringConnectionCardBack() {
XCTAssertFalse(
shouldShowConnectionCard(
lifecycle: .active,
isRecording: true,
isHostReady: false
)
)
}
private func descriptor(
for lifecycle: FlowPiPLifecycleState
) -> FlowHomePiPStatusDescriptor {
FlowHomePiPStatusPolicy.descriptor(
lifecycle: lifecycle,
isStarting: false,
isRecording: false,
isProcessing: false,
isActive: false,
isHostReady: false
)
}
private func shouldShowConnectionCard(
lifecycle: FlowPiPLifecycleState,
isRecording: Bool = false,
isHostReady: Bool
) -> Bool {
FlowHomePiPStatusPolicy.shouldShowConnectionCard(
lifecycle: lifecycle,
needsPermissionSetup: false,
needsAPIKeySetup: false,
hasSessionWarning: false,
isRecording: isRecording,
isProcessing: false,
isHostReady: isHostReady
)
}
}