import XCTest @testable import CallsKit final class CallBarFitTests: XCTestCase { private let all = CallBarFit.Control.allCases func testEveryWindowTheAppAllowsHasRoomForEverything() { // 760 is the window's minimum (CallsMac.swift). for width in stride(from: 760.0, through: 3840, by: 1) { let fit = CallBarFit.fit(windowWidth: width, controls: all) XCTAssertEqual(fit.overflow, [], "at \(width)") XCTAssertEqual(fit.spacing, CallBarFit.roomy, "at \(width)") XCTAssertLessThanOrEqual(fit.width, CallBarFit.maxWidth) XCTAssertLessThanOrEqual(fit.width + 2 * CallBarFit.margin, width, "at \(width)") } } func testNarrowerItTightensThenMovesTheLeastUsedIntoMore() { var last = CallBarFit.fit(windowWidth: 760, controls: all) for width in stride(from: 759.0, through: 200, by: -1) { let fit = CallBarFit.fit(windowWidth: width, controls: all) // Never the controls that matter most. for control in all where control.essential { XCTAssertTrue(fit.shows(control), "\(control) at \(width)") } // Only ever more in ⋯ as it narrows, and in the bar's order. XCTAssertTrue(Set(last.overflow).isSubset(of: Set(fit.overflow)), "at \(width)") XCTAssertEqual(fit.overflow, all.filter { fit.overflow.contains($0) }) // Whatever is shown fits the pane, while the essentials can. let shown = all.filter(fit.shows) let needed = CallBarFit.needed(shown, fit.spacing, more: !fit.overflow.isEmpty) let essentials = CallBarFit.needed(all.filter(\.essential), CallBarFit.tight, more: true) if width - 2 * CallBarFit.margin >= essentials { XCTAssertLessThanOrEqual(needed, fit.width + 0.001, "at \(width)") } last = fit } XCTAssertEqual( CallBarFit.fit(windowWidth: 300, controls: all).overflow, [.share, .devices, .layout, .link]) } func testTheFirstToGoAreTheLinkThenLayout() { // ⋯ takes a button's place, so the first time anything moves, two do: // the link, and the layout (in the bar's order in ⋯). let tightAll = CallBarFit.needed(all, CallBarFit.tight, more: false) let fit = CallBarFit.fit(windowWidth: tightAll + 2 * CallBarFit.margin - 1, controls: all) XCTAssertEqual(fit.overflow, [.layout, .link]) // A guest has no link: the layout and Devices go first instead. let guest = all.filter { $0 != .link } let tightGuest = CallBarFit.needed(guest, CallBarFit.tight, more: false) XCTAssertEqual( CallBarFit.fit(windowWidth: tightGuest + 2 * CallBarFit.margin - 1, controls: guest).overflow, [.devices, .layout]) } }