Remove the redundant desktop adapter and retain its behavior through the existing Application policy. Expand regression coverage and record verification evidence. Verification: 1,399 macOS tests passed. iOS had 428 passing tests and five repeatable failures with baseline status unverified. Strict Swift formatting and Chinese localization checks passed.
78 lines
3.1 KiB
Swift
78 lines
3.1 KiB
Swift
import Foundation
|
|
import TermindApplication
|
|
import TermindDomain
|
|
import Testing
|
|
|
|
import struct TermindDomain.Host
|
|
|
|
@Suite
|
|
struct PortForwardingEditorPolicyTests {
|
|
@Test(
|
|
arguments: [false, true],
|
|
[
|
|
(false, false, true, true, false),
|
|
(true, false, false, true, true),
|
|
(false, true, false, false, false),
|
|
(true, true, false, false, false),
|
|
])
|
|
func controlsKeepSavedEligibilityIntentAndActivityIndependent(
|
|
hasSavedConfiguration: Bool,
|
|
scenario: (enabled: Bool, active: Bool, canStartSaved: Bool, canEdit: Bool, waitsWhenUnsaved: Bool)
|
|
) {
|
|
let host = Host(name: "Server", host: "server.invalid")
|
|
let rule = PortForwardingRule(hostID: host.id)
|
|
let policy = PortForwardingEditorPolicy(
|
|
rule: rule, savedRule: hasSavedConfiguration ? rule : nil, savedHost: host,
|
|
isEnabled: scenario.enabled, isRuntimeActive: scenario.active)
|
|
|
|
#expect(policy.hasSavedConfiguration == hasSavedConfiguration)
|
|
#expect(policy.isEnabled == scenario.enabled)
|
|
#expect(policy.isRuntimeActive == scenario.active)
|
|
#expect(policy.canStart == (hasSavedConfiguration && scenario.canStartSaved))
|
|
#expect(policy.canToggle)
|
|
#expect(policy.canEdit == scenario.canEdit)
|
|
#expect(policy.isWaitingForSave == (!hasSavedConfiguration && scenario.waitsWhenUnsaved))
|
|
}
|
|
|
|
enum UnavailableConfiguration: CaseIterable {
|
|
case missingRule, missingHost, mismatchedHost, mismatchedRuleID
|
|
}
|
|
|
|
@Test(arguments: UnavailableConfiguration.allCases)
|
|
func missingOrMismatchedSavedConfigurationCannotStart(configuration: UnavailableConfiguration) {
|
|
let host = Host(name: "Server", host: "server.invalid")
|
|
let rule = PortForwardingRule(hostID: host.id)
|
|
var savedRule: PortForwardingRule? = rule
|
|
var savedHost: Host? = host
|
|
switch configuration {
|
|
case .missingRule: savedRule = nil
|
|
case .missingHost: savedHost = nil
|
|
case .mismatchedHost: savedHost = Host(name: "Other", host: "other.invalid")
|
|
case .mismatchedRuleID: savedRule?.id = UUID()
|
|
}
|
|
let policy = PortForwardingEditorPolicy(
|
|
rule: rule, savedRule: savedRule, savedHost: savedHost,
|
|
isEnabled: false, isRuntimeActive: false)
|
|
|
|
#expect(!policy.hasSavedConfiguration)
|
|
#expect(!policy.canStart)
|
|
#expect(policy.canToggle)
|
|
#expect(policy.canEdit)
|
|
}
|
|
|
|
@Test(arguments: [0, 65_536])
|
|
func aValidDraftCannotMakeAnInvalidSavedRuleStartable(invalidPort: Int) {
|
|
let host = Host(name: "Server", host: "server.invalid")
|
|
let draft = PortForwardingRule(hostID: host.id)
|
|
var savedRule = draft
|
|
savedRule.bindPort = invalidPort
|
|
let policy = PortForwardingEditorPolicy(
|
|
rule: PortForwardingEditorPolicy.normalized(draft), savedRule: savedRule, savedHost: host,
|
|
isEnabled: false, isRuntimeActive: false)
|
|
|
|
#expect(!policy.hasSavedConfiguration)
|
|
#expect(!policy.canStart)
|
|
#expect(policy.canEdit)
|
|
}
|
|
}
|