Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677import ParcelConfigimport ParcelCoreimport ParcelEngineimport Testing
struct HoverFocusModelTests { let target = HoverFocusTarget(window: WindowID(rawValue: 1), workspace: engineWorkspace)
@Test func disabledByDefault() { var model = HoverFocusModel() model.moved(to: Point(), target: target, at: 0, configuration: .init(), enabled: false) #expect(model.target == nil) #expect(model.deadline == nil) }
@Test func focusRequiresSettlingAndIsConsumedOnce() { var model = HoverFocusModel() model.moved(to: Point(), target: target, at: 0, configuration: .init(), enabled: true) #expect(model.deadline == 0.35) #expect(model.settled(at: 0.35, target: target) == target) #expect(model.settled(at: 0.4, target: target) == nil) }
@Test func movementRestartsButSmallJitterDoesNot() { var model = HoverFocusModel() model.moved(to: Point(), target: target, at: 0, configuration: .init(), enabled: true) model.moved(to: Point(x: 1, y: 1), target: target, at: 0.1, configuration: .init(), enabled: true) #expect(model.deadline == 0.35) model.moved(to: Point(x: 10), target: target, at: 0.2, configuration: .init(), enabled: true) #expect(model.deadline == 0.55) }
@Test func typingCancelsPendingAndRequiresNewMovementAfterCooldown() { var model = HoverFocusModel() model.moved(to: Point(), target: target, at: 0, configuration: .init(), enabled: true) model.typed(at: 0.2) #expect(model.deadline == nil) model.moved(to: Point(), target: target, at: 1.19, configuration: .init(), enabled: true) #expect(model.deadline == nil) model.moved(to: Point(), target: target, at: 1.2, configuration: .init(), enabled: true) #expect(model.deadline.map { abs($0 - 1.55) < 0.000_001 } == true) }
@Test func changedSpaceOrTargetCannotFocusCapturedWindow() { var model = HoverFocusModel() model.moved(to: Point(), target: target, at: 0, configuration: .init(), enabled: true) let other = HoverFocusTarget( window: target.window, workspace: WorkspaceKey( display: engineDisplay, space: SpaceID(rawValue: 2))) #expect(model.settled(at: 0.35, target: other) == nil) }
@Test(arguments: [Double.nan, .infinity, -1]) func invalidOrBackwardTimeCancels(time: Double) { var model = HoverFocusModel() model.moved(to: Point(), target: target, at: 0, configuration: .init(), enabled: true) model.moved(to: Point(), target: target, at: time, configuration: .init(), enabled: true) #expect(model.deadline == nil) }
@Test func invalidCoordinatesAndExplicitCancelClearCandidate() { var model = HoverFocusModel() model.moved(to: Point(x: .nan), target: target, at: 0, configuration: .init(), enabled: true) #expect(model.deadline == nil) model.moved(to: Point(), target: target, at: 1, configuration: .init(), enabled: true) model.cancel() #expect(model.target == nil) }
@Test func earlyClockCannotActivate() { var model = HoverFocusModel() model.moved(to: Point(), target: target, at: 0, configuration: .init(), enabled: true) #expect(model.settled(at: 0.3, target: target) == nil) }}