Files
focus-fixer/FocusFixerTests/DebounceTests.swift
T
sttlab-tech 561a547b70 Initial FocusFixer implementation
Menu-bar utility that fixes cross-display keyboard focus loss: a
listen-only CGEvent tap locates the window under the cursor and
reasserts app activation + AX focus on it, with debounce, tap
auto-recovery, and an Accessibility permission gate.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-10 12:02:29 +02:00

41 lines
1.2 KiB
Swift

import XCTest
@testable import FocusFixer
final class DebounceTests: XCTestCase {
func testFirstEventIsAlwaysProcessed() {
var clockValue: TimeInterval = 0
var debouncer = Debouncer(interval: 0.15, clock: { clockValue })
XCTAssertTrue(debouncer.shouldProcess())
}
func testEventWithinIntervalIsSuppressed() {
var clockValue: TimeInterval = 0
var debouncer = Debouncer(interval: 0.15, clock: { clockValue })
XCTAssertTrue(debouncer.shouldProcess())
clockValue += 0.05
XCTAssertFalse(debouncer.shouldProcess())
}
func testEventAfterIntervalIsProcessed() {
var clockValue: TimeInterval = 0
var debouncer = Debouncer(interval: 0.15, clock: { clockValue })
XCTAssertTrue(debouncer.shouldProcess())
clockValue += 0.2
XCTAssertTrue(debouncer.shouldProcess())
}
func testAcceptedEventResetsTheWindow() {
var clockValue: TimeInterval = 0
var debouncer = Debouncer(interval: 0.15, clock: { clockValue })
XCTAssertTrue(debouncer.shouldProcess())
clockValue += 0.2
XCTAssertTrue(debouncer.shouldProcess())
clockValue += 0.05
XCTAssertFalse(debouncer.shouldProcess())
}
}