69 lines
3.7 KiB
Swift
69 lines
3.7 KiB
Swift
import ConjureKit
|
|
import Foundation
|
|
import Testing
|
|
|
|
@Test
|
|
func launcherAlignmentPositionsWindowEdgesOnOffsetDisplaysAndTracksWindowSize() {
|
|
let display = CGRect(x: -1920, y: 40, width: 1920, height: 1040)
|
|
let window = CGRect(x: -1500, y: 450, width: 750, height: 474)
|
|
let alignment = LauncherAlignment(windowFrame: window, visibleFrame: display)
|
|
#expect(alignment.targetFrame == CGRect(x: -1335, y: 398, width: 750, height: 474))
|
|
#expect(alignment.snappedOrigin == window.origin)
|
|
let resized = LauncherAlignment(windowFrame: CGRect(x: -1500, y: 400, width: 840, height: 500), visibleFrame: display)
|
|
#expect(resized.targetFrame == CGRect(x: -1380, y: 372, width: 840, height: 500))
|
|
}
|
|
|
|
@Test
|
|
func launcherAlignmentSnapsAxesIndependentlyAtBothThresholdBoundaries() {
|
|
let display = CGRect(x: 0, y: 0, width: 1500, height: 1000)
|
|
let target = CGPoint(x: 375, y: 326)
|
|
for offset: CGFloat in [-12, 12] {
|
|
let horizontal = LauncherAlignment(windowFrame: CGRect(x: target.x + offset, y: target.y + 40, width: 750, height: 474), visibleFrame: display)
|
|
#expect(horizontal.snappedOrigin == CGPoint(x: target.x, y: target.y + 40))
|
|
let vertical = LauncherAlignment(windowFrame: CGRect(x: target.x + 40, y: target.y + offset, width: 750, height: 474), visibleFrame: display)
|
|
#expect(vertical.snappedOrigin == CGPoint(x: target.x + 40, y: target.y))
|
|
}
|
|
let both = LauncherAlignment(windowFrame: CGRect(x: target.x - 6, y: target.y + 9, width: 750, height: 474), visibleFrame: display)
|
|
#expect(both.snappedOrigin == target)
|
|
}
|
|
|
|
@Test
|
|
func launcherAlignmentReleasesOutsideEitherSideOfTheSnapThreshold() {
|
|
let display = CGRect(x: 0, y: 0, width: 1500, height: 1000)
|
|
for offset: CGFloat in [-12.01, 12.01] {
|
|
let window = CGRect(x: 375 + offset, y: 326 + offset, width: 750, height: 474)
|
|
#expect(LauncherAlignment(windowFrame: window, visibleFrame: display).snappedOrigin == window.origin)
|
|
}
|
|
}
|
|
|
|
@Test
|
|
func launcherAlignmentKeepsFractionalDisplayCentersOnAStableWindowGrid() {
|
|
let display = CGRect(x: 0, y: 0, width: 1512, height: 949)
|
|
let window = CGRect(x: 390, y: 280, width: 750, height: 474)
|
|
let alignment = LauncherAlignment(windowFrame: window, visibleFrame: display)
|
|
#expect(alignment.targetFrame == CGRect(x: 381, y: 285, width: 750, height: 474))
|
|
#expect(alignment.snappedOrigin == CGPoint(x: 381, y: 285))
|
|
let placed = CGRect(origin: alignment.snappedOrigin, size: window.size)
|
|
#expect(LauncherAlignment(windowFrame: placed, visibleFrame: display).snappedOrigin == placed.origin)
|
|
}
|
|
|
|
@Test
|
|
func launcherPositionRestoresCentersAcrossSizesAndFallsBackForMissingOrOffscreenPositions() {
|
|
let display = CGRect(x: -1920, y: 40, width: 1920, height: 1040)
|
|
let size = CGSize(width: 750, height: 474)
|
|
let center = CGPoint(x: -1125, y: 687)
|
|
for windowSize in [size, CGSize(width: 570, height: 404), CGSize(width: 840, height: 620)] {
|
|
let frame = LauncherAlignment.restoredFrame(savedCenter: center, windowSize: windowSize, visibleFrame: display)
|
|
#expect(CGPoint(x: frame.midX, y: frame.midY) == center)
|
|
#expect(frame.size == windowSize)
|
|
}
|
|
for invalid: CGPoint? in [nil, CGPoint(x: 0, y: 687), CGPoint(x: -1125, y: 276),
|
|
CGPoint(x: CGFloat.nan, y: 687), CGPoint(x: -1125, y: CGFloat.infinity)] {
|
|
#expect(LauncherAlignment.restoredFrame(savedCenter: invalid, windowSize: size, visibleFrame: display)
|
|
== CGRect(x: -1335, y: 398, width: 750, height: 474))
|
|
}
|
|
let small = CGRect(x: 0, y: 40, width: 800, height: 500)
|
|
#expect(LauncherAlignment.restoredFrame(savedCenter: nil, windowSize: size, visibleFrame: small)
|
|
== CGRect(x: 25, y: 40, width: 750, height: 474))
|
|
}
|