mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 02:29:55 +02:00
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
This commit is contained in:
43
apple/Tests/FilePreviewRepositoryTests.swift
Normal file
43
apple/Tests/FilePreviewRepositoryTests.swift
Normal file
@@ -0,0 +1,43 @@
|
||||
import XCTest
|
||||
@testable import VniDrop
|
||||
|
||||
/// Ports `feature/send/FilePreviewRepositoryTest.kt` — persisted thumbnails,
|
||||
/// restore pruned to live transfer ids, and removal.
|
||||
@MainActor
|
||||
final class FilePreviewRepositoryTests: XCTestCase {
|
||||
|
||||
/// Minimal bytes that pass the PNG magic-byte check.
|
||||
private let png = Data([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A])
|
||||
|
||||
private func makeRepo() -> FilePreviewRepository {
|
||||
FilePreviewRepository(appDataDir: NSTemporaryDirectory() + "previews-" + UUID().uuidString)
|
||||
}
|
||||
|
||||
func testSaveStoresPreview() {
|
||||
let repo = makeRepo()
|
||||
repo.save(transferId: 1, bytes: png)
|
||||
XCTAssertEqual(repo.previews[1], png)
|
||||
}
|
||||
|
||||
func testSaveRejectsNonImageBytes() {
|
||||
let repo = makeRepo()
|
||||
repo.save(transferId: 1, bytes: Data("not an image".utf8))
|
||||
XCTAssertNil(repo.previews[1])
|
||||
}
|
||||
|
||||
func testRestorePrunesToActiveIds() {
|
||||
let repo = makeRepo()
|
||||
repo.save(transferId: 1, bytes: png)
|
||||
repo.save(transferId: 2, bytes: png)
|
||||
repo.restore(activeTransferIds: [1])
|
||||
XCTAssertEqual(repo.previews[1], png)
|
||||
XCTAssertNil(repo.previews[2])
|
||||
}
|
||||
|
||||
func testRemoveDeletesPreview() {
|
||||
let repo = makeRepo()
|
||||
repo.save(transferId: 1, bytes: png)
|
||||
repo.remove(transferId: 1)
|
||||
XCTAssertNil(repo.previews[1])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user