Files
epod-window-bar/Tests/WindowOrderTests.swift
Erhan Keseli 70d7ca5efe EPOD Window Bar: a window strip above the macOS Dock
EPOD Window Bar is a macOS agent app. It shows a thin strip above the Dock
with one tab per window of the frontmost application. One click raises the
window.

Build from source with XcodeGen and Xcode. Signing uses Config.xcconfig
(ad-hoc by default; a local Local.xcconfig can set a team ID). The app needs
Accessibility and Screen Recording permissions, and runs in a reduced mode
without Screen Recording.

See README.md and docs/ for details.
2026-11-21 21:41:06 +01:00

82 lines
3.1 KiB
Swift

import XCTest
@testable import EPODWindowBar
// WindowOrderTests checks the stable order of the WindowStore (decision D5).
// The store sorts windows by firstSeen. A known window keeps its firstSeen
// value on a refresh. A new window gets the firstSeen value "now". A window
// that closes and opens again gets a new firstSeen value.
@MainActor
final class WindowOrderTests: XCTestCase {
private let pid: pid_t = 42
private func makeWindow(id: CGWindowID, title: String) -> WindowInfo {
return WindowInfo(
id: id,
pid: pid,
bundleID: "com.test.app",
title: title,
spaceIDs: [],
isOnCurrentSpace: true,
isMinimized: false,
isFullScreen: false,
firstSeen: Date(timeIntervalSince1970: 0))
}
func testEqualFirstSeenSortsByID() {
let store = WindowStore()
let t0 = Date(timeIntervalSince1970: 100)
store.replaceWindows([makeWindow(id: 2, title: "B"),
makeWindow(id: 1, title: "A")],
for: pid, now: t0)
let order = store.windows(for: pid).map { $0.id }
XCTAssertEqual(order, [1, 2])
}
func testNewWindowKeepsStableOrder() {
let store = WindowStore()
let t0 = Date(timeIntervalSince1970: 100)
store.replaceWindows([makeWindow(id: 1, title: "A"),
makeWindow(id: 2, title: "B")],
for: pid, now: t0)
// A later refresh adds window 3. The order of 1 and 2 does not change.
let t1 = Date(timeIntervalSince1970: 200)
store.replaceWindows([makeWindow(id: 2, title: "B"),
makeWindow(id: 1, title: "A"),
makeWindow(id: 3, title: "C")],
for: pid, now: t1)
let order = store.windows(for: pid).map { $0.id }
XCTAssertEqual(order, [1, 2, 3])
}
func testReopenGetsNewFirstSeen() {
let store = WindowStore()
let t0 = Date(timeIntervalSince1970: 100)
store.replaceWindows([makeWindow(id: 1, title: "A"),
makeWindow(id: 2, title: "B")],
for: pid, now: t0)
// Window 1 closes.
let t1 = Date(timeIntervalSince1970: 200)
store.replaceWindows([makeWindow(id: 2, title: "B")], for: pid, now: t1)
// Window 1 opens again. Window 1 gets a new firstSeen value. Window 1
// moves after window 2.
let t2 = Date(timeIntervalSince1970: 300)
store.replaceWindows([makeWindow(id: 2, title: "B"),
makeWindow(id: 1, title: "A")],
for: pid, now: t2)
let order = store.windows(for: pid).map { $0.id }
XCTAssertEqual(order, [2, 1])
}
func testFrontmostWindows() {
let store = WindowStore()
store.replaceWindows([makeWindow(id: 1, title: "A")], for: pid,
now: Date(timeIntervalSince1970: 100))
store.setFrontmost(pid)
XCTAssertEqual(store.frontmostWindows.map { $0.id }, [1])
}
}