Files
Termind/FrameworkTests/MultiConnectionSettingsTests.swift
T
Kaede Akino 82d871c4fe refactor: separate feature policies and UI workflows
Move connection policy out of ProAccess, keep terminal uploads with their
session, and share question interaction and highlight editing operations.
Consolidate CPU usage and settings snapshot handling, and remove obsolete
terminal selection, theme helpers, and hard-coded latest-schema assertions.

Fix draining connection-pool recovery and stale pane upload bindings. Keep
screenshot matrices opt-in and retain behavioral migration coverage.

Validation: 2468 macOS tests passed serially, 31 iOS tests passed, and both
SSH forwarding regressions passed against the local OpenSSH fixture.
Both app builds, Swift formatting, AppStrings, and Chinese localization
checks passed. Parallel test runs still exhibit intermittent timeouts.
2026-10-02 16:40:27 +08:00

62 lines
2.5 KiB
Swift

import Foundation
import SwiftUI
import TermindApplication
import TermindDomain
import TermindPresentation
import Testing
@Suite @MainActor
struct MultiConnectionSettingsTests {
@Test(arguments: SFTPConcurrencyStrategy.allCases)
func restrictedDisplayAndOtherEditsPreserveTheSavedStrategy(_ strategy: SFTPConcurrencyStrategy) {
let persistence = SettingsStore(.init(strategy: strategy))
let settings = SFTPSettingsModel(persistence: persistence)
var requests = 0
let access = MultiConnectionSettingsAccess(isAllowed: false) { requests += 1 }
let selection = access.strategy(for: settings)
#expect(selection.wrappedValue == .channelsOnly)
#expect(persistence.saves == 0)
selection.wrappedValue = .channelsOnly
#expect(persistence.saves == 0)
selection.wrappedValue = .smart
selection.wrappedValue = .connectionsPreferred
#expect(requests == 2)
#expect(persistence.saves == 0)
#expect(settings.set(12, for: \.globalLimit))
#expect(persistence.value.strategy == strategy)
#expect(persistence.saves == 1)
let upgraded = MultiConnectionSettingsAccess(isAllowed: true, requestAccess: {})
#expect(upgraded.strategy(for: settings).wrappedValue == strategy)
}
@Test func freeHostEditorSavesOtherFieldsWithoutReplacingItsConnectionCount() {
var host = Host(name: "Before", host: "example.invalid", portForwardingMaxConnections: 8)
var prompts = 0
let saved = Binding(get: { host.portForwardingMaxConnections }, set: { host.portForwardingMaxConnections = $0 })
let free = MultiConnectionSettingsAccess(isAllowed: false) { prompts += 1 }.forwardingConnections(saved)
#expect(free.wrappedValue == 1)
free.wrappedValue = 1
free.wrappedValue = 2
host.name = "After"
#expect(host.portForwardingMaxConnections == 8)
#expect(prompts == 1)
let paid = MultiConnectionSettingsAccess(isAllowed: true, requestAccess: {}).forwardingConnections(saved)
#expect(paid.wrappedValue == 8)
paid.wrappedValue = 4
#expect(host.portForwardingMaxConnections == 4)
}
}
@MainActor
private final class SettingsStore: SFTPPreferencesPersisting {
var value: SFTPPreferences
var saves = 0
init(_ value: SFTPPreferences) { self.value = value }
func loadSFTP() throws -> SFTPPreferences { value }
func saveSFTP(_ value: SFTPPreferences) throws {
self.value = value
saves += 1
}
}