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.
77 lines
3.3 KiB
Swift
77 lines
3.3 KiB
Swift
import XCTest
|
|
@testable import EPODWindowBar
|
|
|
|
// TabLayoutTests check the pure layout function. See spec section 7.9.
|
|
final class TabLayoutTests: XCTestCase {
|
|
|
|
// All tabs fit. There is no overflow. The tabs have equal width.
|
|
func testAllTabsFitNoOverflow() {
|
|
let result = TabLayout.compute(availableWidth: 1000, windowCount: 4, activeIndex: 0)
|
|
XCTAssertEqual(result.visibleCount, 4)
|
|
XCTAssertFalse(result.showsOverflow)
|
|
XCTAssertEqual(result.overflowCount, 0)
|
|
XCTAssertEqual(result.visibleIndices, [0, 1, 2, 3])
|
|
XCTAssertTrue(result.overflowIndices.isEmpty)
|
|
}
|
|
|
|
// The tab width is equal for all tabs and inside the bounds.
|
|
func testTabWidthInsideBounds() {
|
|
let result = TabLayout.compute(availableWidth: 1000, windowCount: 4, activeIndex: 0)
|
|
XCTAssertGreaterThanOrEqual(result.tabWidth, 90)
|
|
XCTAssertLessThanOrEqual(result.tabWidth, 220)
|
|
}
|
|
|
|
// The tab width reaches the maximum when few tabs share a wide strip.
|
|
func testTabWidthReachesMaximum() {
|
|
let result = TabLayout.compute(availableWidth: 2000, windowCount: 2, activeIndex: 0)
|
|
XCTAssertEqual(result.tabWidth, 220, accuracy: 0.001)
|
|
}
|
|
|
|
// Too many tabs do not fit. The +N button appears.
|
|
func testOverflowAppears() {
|
|
let result = TabLayout.compute(availableWidth: 500, windowCount: 15, activeIndex: 0)
|
|
XCTAssertTrue(result.showsOverflow)
|
|
XCTAssertGreaterThan(result.overflowCount, 0)
|
|
XCTAssertEqual(result.visibleCount + result.overflowCount, 15)
|
|
}
|
|
|
|
// The visible tabs keep the minimum width in the overflow case.
|
|
func testOverflowTabsKeepMinimumWidth() {
|
|
let result = TabLayout.compute(availableWidth: 500, windowCount: 15, activeIndex: 0)
|
|
XCTAssertGreaterThanOrEqual(result.tabWidth, 90)
|
|
}
|
|
|
|
// The active window is always visible. The active window is in the overflow
|
|
// range before the swap. The swap puts the active window into the last
|
|
// visible slot.
|
|
func testActiveWindowAlwaysVisible() {
|
|
let result = TabLayout.compute(availableWidth: 500, windowCount: 15, activeIndex: 14)
|
|
XCTAssertTrue(result.visibleIndices.contains(14))
|
|
XCTAssertFalse(result.overflowIndices.contains(14))
|
|
XCTAssertEqual(result.visibleIndices.last, 14)
|
|
}
|
|
|
|
// The swap helper keeps the count correct.
|
|
func testSwapKeepsCounts() {
|
|
let split = TabLayout.visibleIndices(windowCount: 10, visibleCount: 3, activeIndex: 9)
|
|
XCTAssertEqual(split.visible.count, 3)
|
|
XCTAssertEqual(split.overflow.count, 7)
|
|
XCTAssertTrue(split.visible.contains(9))
|
|
XCTAssertFalse(Set(split.visible).intersection(Set(split.overflow)).isEmpty == false)
|
|
}
|
|
|
|
// Zero windows give an empty layout.
|
|
func testZeroWindows() {
|
|
let result = TabLayout.compute(availableWidth: 1000, windowCount: 0, activeIndex: nil)
|
|
XCTAssertEqual(result.visibleCount, 0)
|
|
XCTAssertFalse(result.showsOverflow)
|
|
XCTAssertTrue(result.visibleIndices.isEmpty)
|
|
}
|
|
|
|
// A nil active index does not swap. The first tabs stay visible.
|
|
func testNilActiveIndexNoSwap() {
|
|
let split = TabLayout.visibleIndices(windowCount: 10, visibleCount: 3, activeIndex: nil)
|
|
XCTAssertEqual(split.visible, [0, 1, 2])
|
|
}
|
|
}
|