62 lines
1.9 KiB
Swift
62 lines
1.9 KiB
Swift
import AppKit
|
|
import XCTest
|
|
@testable import PureMac
|
|
|
|
@MainActor
|
|
final class AppStateTests: XCTestCase {
|
|
func testScanForAppFilesTracksLocationsWhileResultsArePending() throws {
|
|
var completion: ((Set<URL>) -> Void)?
|
|
let expectedLocations = ["/one", "/two", "/three"]
|
|
let appState = AppState(
|
|
performStartupTasks: false,
|
|
locationsProvider: {
|
|
StubLocations(paths: expectedLocations)
|
|
},
|
|
appFileScanner: { _, locations, pendingCompletion in
|
|
XCTAssertEqual(locations.appSearch.paths, expectedLocations)
|
|
completion = pendingCompletion
|
|
}
|
|
)
|
|
|
|
appState.scanForAppFiles(makeApp())
|
|
|
|
XCTAssertTrue(appState.isScanningAppFiles)
|
|
XCTAssertTrue(appState.discoveredFiles.isEmpty)
|
|
XCTAssertEqual(appState.currentAppFileSearchLocationCount, expectedLocations.count)
|
|
|
|
let pendingCompletion = try XCTUnwrap(completion)
|
|
let urls: Set<URL> = [
|
|
URL(fileURLWithPath: "/tmp/B"),
|
|
URL(fileURLWithPath: "/tmp/A")
|
|
]
|
|
|
|
pendingCompletion(urls)
|
|
|
|
XCTAssertFalse(appState.isScanningAppFiles)
|
|
XCTAssertEqual(
|
|
appState.discoveredFiles,
|
|
urls.sorted { $0.path < $1.path }
|
|
)
|
|
XCTAssertEqual(appState.selectedFiles, urls)
|
|
XCTAssertEqual(appState.currentAppFileSearchLocationCount, urls.count)
|
|
}
|
|
|
|
private func makeApp() -> InstalledApp {
|
|
InstalledApp(
|
|
id: UUID(),
|
|
appName: "PureMac",
|
|
bundleIdentifier: "com.puremac.app",
|
|
path: URL(fileURLWithPath: "/Applications/PureMac.app"),
|
|
icon: NSImage(size: NSSize(width: 32, height: 32)),
|
|
size: 1
|
|
)
|
|
}
|
|
}
|
|
|
|
private final class StubLocations: Locations {
|
|
init(paths: [String]) {
|
|
super.init()
|
|
appSearch = SearchCategory(name: "Apps", paths: paths)
|
|
}
|
|
}
|