This commit is contained in:
2026-10-10 14:54:39 +02:00
parent a0b3ef9975
commit 499fcd12ca
27 changed files with 435 additions and 46 deletions
@@ -1,3 +1,4 @@
import AppKit
@testable import HelderUI
import Testing
@@ -31,4 +32,65 @@ import Testing
#expect(shape(isOverText: false, isSelecting: true) == .iBeam)
#expect(shape(overlayOpen: true, isEnabled: false, isOverText: false, isSelecting: true) == .iBeam)
}
private func clickable(layer: PointerLayer = .workspace, overlayOpen: Bool = false, isEnabled: Bool = true,
isSelecting: Bool = false) -> PointerShape {
PointerPolicy.shape(forClickable: layer, overlayOpen: overlayOpen, isEnabled: isEnabled, isSelecting: isSelecting)
}
@Test func aClickableInAColumnTakesTheHand() {
#expect(clickable() == .pointingHand)
}
@Test func anOpenOverlayGivesTheClickablesBehindItTheArrow() {
#expect(clickable(overlayOpen: true) == .arrow)
}
@Test func aClickableInsideTheOverlayKeepsTheHand() {
#expect(clickable(layer: .overlay, overlayOpen: true) == .pointingHand)
}
@Test func aDisabledClickableKeepsTheArrow() {
#expect(clickable(isEnabled: false) == .arrow)
#expect(clickable(layer: .overlay, overlayOpen: true, isEnabled: false) == .arrow)
}
@Test func aDragSelectionKeepsTheIBeamOverAClickable() {
#expect(clickable(isSelecting: true) == .iBeam)
#expect(clickable(overlayOpen: true, isEnabled: false, isSelecting: true) == .iBeam)
}
@Test func textAndClickablesShareTheOverlayGate() {
#expect(PointerPolicy.isBehindOverlay(.workspace, overlayOpen: true))
#expect(!PointerPolicy.isBehindOverlay(.workspace, overlayOpen: false))
#expect(!PointerPolicy.isBehindOverlay(.overlay, overlayOpen: true))
}
@MainActor @Test func aRegionOutOfViewHasAnEmptyFiniteAreaAndNoCursorRect() {
let area = OffscreenRegion(frame: NSRect(x: 0, y: 0, width: 210, height: 24)).visibleRectWithoutScrollers
#expect(area.isEmpty)
#expect(area.origin.x.isFinite && area.origin.y.isFinite)
#expect(!area.isUsableCursorRect)
}
@Test func removingAStripFromANullRectStaysFinite() {
let rest = NSRect.null.removing(NSRect(x: 0, y: 0, width: 10, height: 10))
#expect(rest.origin.x.isFinite && rest.origin.y.isFinite)
#expect(!NSRect.null.isUsableCursorRect)
}
@MainActor @Test func aRegionsAreaNeverExceedsItsBounds() {
let region = UnclippedRegion(frame: NSRect(x: 0, y: 0, width: 49, height: 27))
#expect(region.visibleRectWithoutScrollers == region.bounds)
}
}
/// Stands in for a view in SwiftUI's platform-view host, which does not clip its visible rect.
private final class UnclippedRegion: PointerRegionView {
override var visibleRect: NSRect { NSRect(x: -629, y: -904.5, width: 1512, height: 940) }
}
/// A region scrolled out of view: its visible rect misses its bounds.
private final class OffscreenRegion: PointerRegionView {
override var visibleRect: NSRect { NSRect(x: 500, y: 500, width: 10, height: 10) }
}