Files
vnidrop/apple/Tests/SettingsModelTests.swift
cdricms 17099d32f2 test(apple): CoreGateway seam, XCTest suite, and CI
- Introduce a CoreGateway protocol so feature models depend on a seam
  (CoreRepository conforms); enables faking the core in tests
- Add a VniDropTests target with 42 tests mirroring the KMP suites:
  approval coordinator, send/receive/settings/app models, preferences,
  file previews, invitation decode, message queue, error mapping
- Add a fake gateway/file-system/device-info and fixtures
- Add .github/workflows/apple.yml: build the Rust core, generate the
  project, and run the tests on an iOS Simulator
2026-07-19 23:48:11 +02:00

46 lines
1.7 KiB
Swift

import XCTest
@testable import VniDrop
/// Ports settings assertions from `feature/ViewModelsTest.kt` username debounce
/// persistence and the Storage "delete all transfers" flow.
@MainActor
final class SettingsModelTests: XCTestCase {
private func makeModel(_ core: FakeCoreGateway, preferences: AppPreferencesRepository) -> SettingsModel {
SettingsModel(
environment: PlatformEnvironment(name: "Test", appVersion: "0.1.0", defaultCoreDataDir: NSTemporaryDirectory()),
deviceInfoProvider: FakeDeviceInfoProvider(),
fileSystemService: FakeFileSystemService(),
repository: core,
preferences: preferences,
notifications: LocalNotificationService(),
messages: UiMessageController(),
bugReports: NoopBugReportService(),
diagnosticsIncluded: false
)
}
func testUsernameChangeDebouncesAndPersists() async {
let prefs = Fixtures.preferences(username: "Original")
let model = makeModel(FakeCoreGateway(), preferences: prefs)
model.setUsername("Alice")
XCTAssertEqual(model.state.username, "Alice") // immediate local echo
await waitUntil { prefs.preferences.username == "Alice" } // persisted after debounce
XCTAssertEqual(prefs.preferences.username, "Alice")
}
func testDeleteAllTransfersDeletesEveryTransfer() async {
let core = FakeCoreGateway()
let model = makeModel(core, preferences: Fixtures.preferences())
core.setState(CoreState(isInitialized: true, transfers: [
Fixtures.transfer(id: 2, direction: .send, status: .sharing),
Fixtures.transfer(id: 3, direction: .receive, status: .done),
]))
model.deleteAllTransfers()
await waitUntil { core.deletedTransfers.count == 2 }
XCTAssertEqual(Set(core.deletedTransfers), [2, 3])
}
}