import ParcelConfig import ParcelCore import ParcelEngine import 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) } }