mirror of
https://github.com/XcodesOrg/XcodesApp.git
synced 2026-03-25 08:55:46 +00:00
We were appending a version without appending a corresponding AvailableXcode, and these two arrays were being zipped later so they wouldn't line up. This change simplifies this method a bit by working on only a single array, and then also moves that appending to the end after the array of Xcodes is created.
109 lines
4.2 KiB
Swift
109 lines
4.2 KiB
Swift
import Path
|
|
import Version
|
|
@testable import Xcodes
|
|
import XCTest
|
|
|
|
class AppStateUpdateTests: XCTestCase {
|
|
var subject: AppState!
|
|
|
|
override func setUpWithError() throws {
|
|
Current = .mock
|
|
subject = AppState()
|
|
}
|
|
|
|
func testDoesNotReplaceInstallState() throws {
|
|
subject.allXcodes = [
|
|
Xcode(version: Version("0.0.0")!, installState: .installing(.unarchiving), selected: false, path: nil, icon: nil)
|
|
]
|
|
|
|
subject.updateAllXcodes(
|
|
availableXcodes: [
|
|
AvailableXcode(version: Version("0.0.0")!, url: URL(string: "https://apple.com/xcode.xip")!, filename: "mock.xip", releaseDate: nil)
|
|
],
|
|
installedXcodes: [
|
|
],
|
|
selectedXcodePath: nil
|
|
)
|
|
|
|
XCTAssertEqual(subject.allXcodes[0].installState, .installing(.unarchiving))
|
|
}
|
|
|
|
func testRemovesUninstalledVersion() throws {
|
|
subject.allXcodes = [
|
|
Xcode(version: Version("0.0.0")!, installState: .installed, selected: true, path: "/Applications/Xcode-0.0.0.app", icon: NSImage(systemSymbolName: "app.fill", accessibilityDescription: nil))
|
|
]
|
|
|
|
subject.updateAllXcodes(
|
|
availableXcodes: [
|
|
AvailableXcode(version: Version("0.0.0")!, url: URL(string: "https://apple.com/xcode.xip")!, filename: "mock.xip", releaseDate: nil)
|
|
],
|
|
installedXcodes: [
|
|
],
|
|
selectedXcodePath: nil
|
|
)
|
|
|
|
XCTAssertEqual(subject.allXcodes[0].installState, .notInstalled)
|
|
}
|
|
|
|
func testDeterminesIfInstalledByBuildMetadataAlone() throws {
|
|
subject.allXcodes = [
|
|
]
|
|
|
|
subject.updateAllXcodes(
|
|
availableXcodes: [
|
|
// Note "GM" prerelease identifier
|
|
AvailableXcode(version: Version("0.0.0-GM+ABC123")!, url: URL(string: "https://apple.com/xcode.xip")!, filename: "mock.xip", releaseDate: nil)
|
|
],
|
|
installedXcodes: [
|
|
InstalledXcode(path: Path("/Applications/Xcode-0.0.0.app")!)!
|
|
],
|
|
selectedXcodePath: nil
|
|
)
|
|
|
|
XCTAssertEqual(subject.allXcodes[0].version, Version("0.0.0+ABC123")!)
|
|
XCTAssertEqual(subject.allXcodes[0].installState, .installed)
|
|
XCTAssertEqual(subject.allXcodes[0].selected, false)
|
|
XCTAssertEqual(subject.allXcodes[0].path, "/Applications/Xcode-0.0.0.app")
|
|
}
|
|
|
|
func testAdjustedVersionsAreUsedToLookupAvailableXcode() throws {
|
|
subject.allXcodes = [
|
|
]
|
|
|
|
subject.updateAllXcodes(
|
|
availableXcodes: [
|
|
// Note "GM" prerelease identifier
|
|
AvailableXcode(version: Version("0.0.0-GM+ABC123")!, url: URL(string: "https://apple.com/xcode.xip")!, filename: "mock.xip", releaseDate: nil, sdks: .init(iOS: .init("14.3")))
|
|
],
|
|
installedXcodes: [
|
|
InstalledXcode(path: Path("/Applications/Xcode-0.0.0.app")!)!
|
|
],
|
|
selectedXcodePath: nil
|
|
)
|
|
|
|
XCTAssertEqual(subject.allXcodes[0].version, Version("0.0.0+ABC123")!)
|
|
XCTAssertEqual(subject.allXcodes[0].installState, .installed)
|
|
XCTAssertEqual(subject.allXcodes[0].selected, false)
|
|
XCTAssertEqual(subject.allXcodes[0].path, "/Applications/Xcode-0.0.0.app")
|
|
// XCModel types aren't equatable, so just check for non-nil for now
|
|
XCTAssertNotNil(subject.allXcodes[0].sdks)
|
|
}
|
|
|
|
func testAppendingInstalledVersionThatIsNotAvailable() {
|
|
subject.allXcodes = [
|
|
]
|
|
|
|
subject.updateAllXcodes(
|
|
availableXcodes: [
|
|
AvailableXcode(version: Version("1.2.3")!, url: URL(string: "https://apple.com/xcode.xip")!, filename: "mock.xip", releaseDate: nil, sdks: .init(iOS: .init("14.3")))
|
|
],
|
|
installedXcodes: [
|
|
// There's a version installed which for some reason isn't listed online
|
|
InstalledXcode(path: Path("/Applications/Xcode-0.0.0.app")!)!
|
|
],
|
|
selectedXcodePath: nil
|
|
)
|
|
|
|
XCTAssertEqual(subject.allXcodes.map(\.version), [Version("1.2.3")!, Version("0.0.0+ABC123")!])
|
|
}
|
|
}
|