Add failing test to cover removing an uninstalled version, fix it

https://github.com/RobotsAndPencils/XcodesApp/pull/44#issuecomment-756783640
This commit is contained in:
Brandon Evans 2021-01-08 17:38:01 -07:00
parent cc81f97c30
commit ad02e89449
No known key found for this signature in database
GPG key ID: D58A4B8DB64F8E93
2 changed files with 22 additions and 3 deletions

View file

@ -378,13 +378,15 @@ class AppState: ObservableObject {
.map { xcodeVersion in
let installedXcode = installedXcodes.first(where: { xcodeVersion.isEquivalentForDeterminingIfInstalled(toInstalled: $0.version) })
let availableXcode = availableXcodes.first { $0.version == xcodeVersion }
let existingXcode = allXcodes.first { $0.version == xcodeVersion }
let defaultInstallState: XcodeInstallState = installedXcode != nil ? .installed : .notInstalled
// If the existing install state is "installing", keep it
let existingXcodeInstallState = allXcodes.first { $0.version == xcodeVersion && $0.installing }?.installState
// Otherwise, determine it from whether there's an installed Xcode
let defaultXcodeInstallState: XcodeInstallState = installedXcode != nil ? .installed : .notInstalled
return Xcode(
version: xcodeVersion,
installState: existingXcode?.installState ?? defaultInstallState,
installState: existingXcodeInstallState ?? defaultXcodeInstallState,
selected: installedXcode != nil && selectedXcodePath?.hasPrefix(installedXcode!.path.string) == true,
path: installedXcode?.path.string,
icon: (installedXcode?.path.string).map(NSWorkspace.shared.icon(forFile:)),

View file

@ -27,4 +27,21 @@ class AppStateUpdateTests: XCTestCase {
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)
}
}