Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114import ParcelCoreimport ParcelUIimport Testing
@testable import ParcelApp
extension AppFeedbackTests { @Test(arguments: [ Report.retiled(moved: 6), .cannotFit([WindowID(rawValue: 1)]), .spaceFull(WindowID(rawValue: 1)), .atWindowCap(2), .layoutCapabilityLimit(layout: .side, maximum: 2), .minimumSizeReached, .maximumSizeReached, .noUndoHistory, .undoConflict(WindowID(rawValue: 1)), ]) func layoutReportsStayQuietUntilCommit(_ report: Report) { var policy = LayoutNoticePolicy(held: true) #expect(!policy.allows(report)) policy.commit(noticeState(count: 6)) #expect(policy.allows(report)) policy.hold() #expect(!policy.allows(report)) policy.resume() #expect(policy.allows(report)) }
@Test(arguments: [ Announcement.windowsStacked(window: WindowID(rawValue: 1), count: 6), .tilesMerged(count: 4, limit: 2), .layoutChanged(.side), .ratioChanged(.half), .focused(WindowID(rawValue: 1)), .floatingChanged(WindowID(rawValue: 1), isFloating: true), .windowCapChanged(2), ]) func heldAnnouncementsReachNeitherCardsNorVoiceOver(_ announcement: Announcement) { let services = EngineShellServices(tourUnresolved: true) var speech: [String] = [] let announcer = AppAnnouncer( postAnnouncement: { speech.append($0) }, allowsLayoutNotice: { services.allowsLayoutNotice($0, state: noticeState(count: 6)) }, onModeChange: {}) announcer.announce(announcement) #expect(speech.isEmpty) services.finishTour(automatic: true) announcer.announce(announcement) let expected: Int switch announcement { case .windowsStacked, .tilesMerged: expected = 0 default: expected = 1 } #expect(speech.count == expected) }
@Test(arguments: [2, 6, 7]) func tidyCohortStaysQuietThroughLateStackRegrouping(_ count: Int) { var policy = LayoutNoticePolicy(held: true) policy.commit(noticeState(count: 7)) let state = noticeState(count: count) let firstStack = policy.allows(.windowsStacked(window: WindowID(rawValue: 1), count: count), state: state) let focus = policy.allows(.focused(WindowID(rawValue: 1)), state: state) let repeatedStack = policy.allows(.windowsStacked(window: WindowID(rawValue: 1), count: count), state: state) #expect(!firstStack && focus && !repeatedStack) }
@Test func aNewArrivalOrReusedIdentityStillGetsItsStackNotice() { var policy = LayoutNoticePolicy(held: true) policy.commit(noticeState(count: 6)) var state = noticeState(count: 7) let arrival = policy.allows(.windowsStacked(window: WindowID(rawValue: 1), count: 7), state: state) #expect(arrival) state = noticeState(count: 6) state.windows[WindowID(rawValue: 3)]?.app = AppID(pid: 999, bundleID: "test.replacement") let replacement = policy.allows(.windowsStacked(window: WindowID(rawValue: 1), count: 6), state: state) #expect(replacement) }
@Test(arguments: [ Announcement.layoutChanged(.grid), .ratioChanged(.half), .floatingChanged(WindowID(rawValue: 1), isFloating: true), .stackChanged(window: WindowID(rawValue: 1), count: 6), .windowCapChanged(1), .sizesReset, .undone(WindowID(rawValue: 1)), ]) func anExplicitLayoutEditEndsTheQuietTidyBaseline(_ announcement: Announcement) { var policy = LayoutNoticePolicy(held: true) let state = noticeState(count: 6) policy.commit(state) let edit = policy.allows(announcement, state: state) let stack = policy.allows(.windowsStacked(window: WindowID(rawValue: 1), count: 6), state: state) #expect(edit && stack) }
@Test func restorePointRestoresNoticeHoldAndOrdinaryCommandsRemainLive() { let services = EngineShellServices(tourUnresolved: true) let point = services.captureAutomaticTilingState() services.finishTour(automatic: false) #expect(services.allowsLayoutNotice(.retiled(moved: 6))) services.restoreAutomaticTilingState(point) #expect(!services.allowsLayoutNotice(.retiled(moved: 6))) services.resolveTour() #expect(services.allowsLayoutNotice(.retiled(moved: 6))) services.holdForTour() #expect(!services.allowsLayoutNotice(.retiled(moved: 0))) }}
private func noticeState(count: Int) -> State { let display = DisplayID(rawValue: "notice-display") let key = WorkspaceKey(display: display, space: SpaceID(rawValue: 1)) let windows = (1...count).map { ManagedWindow(id: WindowID(rawValue: UInt32($0)), app: AppID(pid: Int32($0), bundleID: "test.document")) } return reduce( State( displays: [Display(id: display, frame: Rect(width: 1200, height: 800))], activeSpaces: [display: key.space], workspaces: [key: Workspace(key: key, windowCap: 1, order: windows.map(\.id))], windows: Dictionary(uniqueKeysWithValues: windows.map { ($0.id, $0) }), focusedWindow: windows[0].id), .relayout ).0}