|
| 1 | +// macspansoTests/MatchManagerWindowPlacementTests.swift |
| 2 | +import XCTest |
| 3 | +@testable import macspanso |
| 4 | + |
| 5 | +/// The menu-bar action recenters the Match Manager window when a display change |
| 6 | +/// (undocking, switching from an external monitor to the internal one) has left |
| 7 | +/// it where the user can't reach it. The old guard used `frame.intersects`, |
| 8 | +/// which is true for even a 1px overlap — so a window left straddling a screen |
| 9 | +/// edge passed the check and was ordered front effectively off-screen, looking |
| 10 | +/// like "the window didn't open". These tests pin the stronger contract: a |
| 11 | +/// window only counts as visible when a real fraction of it is on a screen. |
| 12 | +final class MatchManagerWindowPlacementTests: XCTestCase { |
| 13 | + |
| 14 | + /// 1440×900 internal display; menu bar eats the top 23pt, so visibleFrame |
| 15 | + /// height is 877. This is the screen that remains after undocking. |
| 16 | + private let internalVisibleFrame = CGRect(x: 0, y: 0, width: 1440, height: 877) |
| 17 | + |
| 18 | + /// After undocking, macOS can leave the window straddling the left edge with |
| 19 | + /// only a thin sliver on the remaining display. `intersects` would say "on |
| 20 | + /// screen"; the user sees nothing usable. This must recenter. |
| 21 | + func testRecentersWindowStraddlingScreenEdgeWithOnlyASliverVisible() { |
| 22 | + // Window spans x:-1100...100, so only 100pt of its 1200pt width overlaps. |
| 23 | + let frame = CGRect(x: -1100, y: 400, width: 1200, height: 820) |
| 24 | + |
| 25 | + let placement = MatchManagerWindowController.placement( |
| 26 | + forFrame: frame, visibleFrames: [internalVisibleFrame]) |
| 27 | + |
| 28 | + XCTAssertEqual(placement, .recenter) |
| 29 | + } |
| 30 | + |
| 31 | + /// A window comfortably within the remaining display must be left alone — |
| 32 | + /// recentering a perfectly-visible window would be its own annoying bug. |
| 33 | + func testKeepsWindowComfortablyOnScreen() { |
| 34 | + let frame = CGRect(x: 120, y: 40, width: 1200, height: 820) |
| 35 | + |
| 36 | + let placement = MatchManagerWindowController.placement( |
| 37 | + forFrame: frame, visibleFrames: [internalVisibleFrame]) |
| 38 | + |
| 39 | + XCTAssertEqual(placement, .keep) |
| 40 | + } |
| 41 | + |
| 42 | + /// The external monitor was to the left at negative coordinates; once it's |
| 43 | + /// gone, the window's frame intersects no remaining screen at all. |
| 44 | + func testRecentersWindowFullyOffScreen() { |
| 45 | + let frame = CGRect(x: -2000, y: 100, width: 1200, height: 820) |
| 46 | + |
| 47 | + let placement = MatchManagerWindowController.placement( |
| 48 | + forFrame: frame, visibleFrames: [internalVisibleFrame]) |
| 49 | + |
| 50 | + XCTAssertEqual(placement, .recenter) |
| 51 | + } |
| 52 | +} |
0 commit comments