mirror of
https://github.com/XcodesOrg/XcodesApp.git
synced 2026-03-25 08:55:46 +00:00
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:
parent
cc81f97c30
commit
ad02e89449
2 changed files with 22 additions and 3 deletions
|
|
@ -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:)),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue