Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Xcodes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
AF29174092FE4E0F921AB001 /* InstallationProgressViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF29174092FE4E0F921AB002 /* InstallationProgressViewTests.swift */; };
14d2f5a1273f6c350cad4406 /* NewVersionNotificationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884f01aed2f43048ab4d3323 /* NewVersionNotificationTests.swift */; };
1596C2913043765600178C86 /* FileOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1596C2903043765600178C86 /* FileOperations.swift */; };
1596C2923043765600178C86 /* FileOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1596C2903043765600178C86 /* FileOperations.swift */; };
Expand Down Expand Up @@ -188,6 +189,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
AF29174092FE4E0F921AB002 /* InstallationProgressViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstallationProgressViewTests.swift; sourceTree = "<group>"; };
1596C2903043765600178C86 /* FileOperations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileOperations.swift; sourceTree = "<group>"; };
15F5B88F2CCF09B900705E2F /* CryptoKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CryptoKit.framework; path = System/Library/Frameworks/CryptoKit.framework; sourceTree = SDKROOT; };
3328073E2CA5E2C80036F691 /* SignInSecurityKeyPinView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInSecurityKeyPinView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -598,6 +600,7 @@
isa = PBXGroup;
children = (
CA452BBD259FDDBF0072DFA4 /* Fixtures */,
AF29174092FE4E0F921AB002 /* InstallationProgressViewTests.swift */,
CAC281E1259FA44600B8AB0B /* Bundle+XcodesTests.swift */,
CAC281E6259FA45A00B8AB0B /* Environment+Mock.swift */,
CAD2E7B72449575100113D76 /* AppStateTests.swift */,
Expand Down Expand Up @@ -980,6 +983,7 @@
buildActionMask = 2147483647;
files = (
CAC281E7259FA45A00B8AB0B /* Environment+Mock.swift in Sources */,
AF29174092FE4E0F921AB001 /* InstallationProgressViewTests.swift in Sources */,
CAC281E2259FA44600B8AB0B /* Bundle+XcodesTests.swift in Sources */,
CA2518EC25A7FF2B00F08414 /* AppStateUpdateTests.swift in Sources */,
14d2f5a1273f6c350cad4406 /* NewVersionNotificationTests.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions Xcodes/Frontend/InfoPane/InstallationStepDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct InstallationStepDetailView: View {
style: .bar,
showsAdditionalDescription: true
)
.id(ObjectIdentifier(progress))

case .authenticating, .unarchiving, .moving, .trashingArchive, .checkingSecurity, .finishing:
ProgressView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct RuntimeInstallationStepDetailView: View {
style: .bar,
showsAdditionalDescription: true
)
.id(ObjectIdentifier(progress))

case .installing, .trashingArchive:
ObservingProgressIndicator(
Expand Down
1 change: 1 addition & 0 deletions Xcodes/Frontend/XcodeList/InstallationStepRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct InstallationStepRowView: View {
controlSize: .small,
style: .spinning
)
.id(ObjectIdentifier(progress))
case .authenticating, .unarchiving, .moving, .trashingArchive, .checkingSecurity, .finishing:
ProgressView()
.scaleEffect(0.5)
Expand Down
58 changes: 58 additions & 0 deletions XcodesTests/InstallationProgressViewTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import Cocoa
import SwiftUI
import XCTest

@testable import Xcodes

@MainActor
final class InstallationProgressViewTests: XCTestCase {
func testXcodeDetailUsesReplacementDownloadProgress() {
assertUsesReplacementProgress { progress in
InstallationStepDetailView(installationStep: .downloading(progress: progress))
}
}

func testXcodeRowUsesReplacementDownloadProgress() {
assertUsesReplacementProgress { progress in
InstallationStepRowView(
installationStep: .downloading(progress: progress),
highlighted: false,
cancel: {}
)
}
}

func testRuntimeDetailUsesReplacementDownloadProgress() {
assertUsesReplacementProgress { progress in
RuntimeInstallationStepDetailView(installationStep: .downloading(progress: progress))
}
}

private func assertUsesReplacementProgress<Content: View>(
@ViewBuilder content: (Progress) -> Content,
file: StaticString = #filePath,
line: UInt = #line
) {
let original = Progress(totalUnitCount: 100)
original.completedUnitCount = 6
let hostingView = NSHostingView(rootView: content(original))
hostingView.frame = NSRect(x: 0, y: 0, width: 420, height: 180)
hostingView.layoutSubtreeIfNeeded()
XCTAssertEqual(progressIndicator(in: hostingView)?.doubleValue, 0.06, file: file, line: line)

// A resumed download supplies a new Progress while remaining in the downloading stage.
let replacement = Progress(totalUnitCount: 100)
replacement.completedUnitCount = 75
hostingView.rootView = content(replacement)
hostingView.layoutSubtreeIfNeeded()

XCTAssertEqual(progressIndicator(in: hostingView)?.doubleValue, 0.75, file: file, line: line)
}

private func progressIndicator(in view: NSView) -> NSProgressIndicator? {
if let indicator = view as? NSProgressIndicator {
return indicator
}
return view.subviews.lazy.compactMap { self.progressIndicator(in: $0) }.first
}
}
Loading