Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169import Foundationimport ParcelConfigimport ParcelCoreimport ParcelPlatformimport Testing
@testable import ParcelUI
@MainActor @Suite("Layout configuration settings", .timeLimit(.minutes(1)))struct ConfigLayoutSettingsTests { @Test func countChoicesFollowTheRunningWorkspaceRatherThanConfiguredDefaults() { let model = SettingsModel(store: ConfigStore()) let id = UUID() let displayID = DisplayID(rawValue: id.uuidString) let bounds = CGRect(x: 0, y: 0, width: 2560, height: 1080) let displays = [ParcelPlatform.Display(id: id, frame: bounds, visibleFrame: bounds, scale: 1, isBuiltIn: false)] #expect(model.configuration.layout.global.defaultLayout == .grid) for (layout, maximum) in [(ConfigLayout.side, 5), (.grid, 4), (.rows, 3)] { model.updateRunningLayouts([displayID: layout], activeDisplay: displayID) let limit = SettingsWindowLimit(layout: model.runningLayout(for: id), display: id, displays: displays) #expect(limit.layout == layout) #expect(limit.choices == Array(0...maximum)) #expect(limit.help.contains(layout.settingsTitle)) #expect(model.configuration.layout.global.defaultLayout == .grid) } model.updateRunningLayouts([:], activeDisplay: nil) let unavailable = SettingsWindowLimit(layout: model.runningLayout(for: id), display: id, displays: displays) #expect(unavailable.choices == nil) #expect(unavailable.layout == nil) }
@Test func mainSizeAvailabilityFollowsSelectedOrActiveRunningLayoutWithoutChangingConfiguration() { let model = SettingsModel(store: ConfigStore()) let side = UUID() let grid = UUID() let sideID = DisplayID(rawValue: side.uuidString.lowercased()) let gridID = DisplayID(rawValue: grid.uuidString) let configuration = model.configuration model.updateRunningLayouts([sideID: .side, gridID: .accordion], activeDisplay: gridID) #expect(MainSizePreset.disabledReason(layout: model.runningLayout(for: nil)) != nil) #expect(MainSizePreset.disabledReason(layout: model.runningLayout(for: side)) == nil) #expect(MainSizePreset.disabledReason(layout: model.runningLayout(for: grid)) != nil) model.updateRunningLayouts([sideID: .side, gridID: .grid], activeDisplay: gridID) #expect(MainSizePreset.disabledReason(layout: model.runningLayout(for: nil)) == nil) #expect(MainSizePreset.disabledReason(layout: model.runningLayout(for: grid)) == nil) model.updateRunningLayouts([:], activeDisplay: nil) #expect(MainSizePreset.disabledReason(layout: model.runningLayout(for: side)) == nil) #expect(MainSizePreset.disabledReason(layout: model.runningLayout(for: nil)) == nil) #expect(model.configuration == configuration) }
@Test func overflowPickerOptionsAndCommandLabelsAreLocalized() { #expect(SettingsLayoutField.whenFull.title == "When this Space is full") #expect(ConfigWhenFull.stack.settingsTitle == "Join the active tile") #expect(ConfigWhenFull.float.settingsTitle == "Float in the center") let commands: [(ConfigCommand, String)] = [ (.makePrimary, "Make window primary"), (.windowNext, "Next window"), (.windowPrevious, "Previous window"), (.resetSizes, "Reset tile sizes"), (.unstack, "Unstack window"), (.close, "Close window"), (.toggleFullscreen, "Toggle full screen"), (.alwaysFloat, "Always float matching windows"), (.toggleFocus, "Toggle Focus"), (.toggleNoPeek, "Toggle No peek"), (.toggleCleanSpace, "Toggle Clean Space"), (.toggleBorders, "Toggle borders"), (.toggleHoverFocus, "Toggle hover focus"), (.undo, "Undo window change"), ] for (command, title) in commands { #expect(command.settingsTitle == title) } for count in 1...5 { #expect(ConfigCommand.setWindowCap(count).settingsTitle == "Set window limit to \(count)") } }
@Test func globalOverflowEditingPreservesFormattingAndUpdatesInheritedDisplays() throws { let key = "a1b2c3d4-1234-5678-9abc-0123456789ab" let id = try #require(UUID(uuidString: key)) let source = "# café\r\n[layout]\r\nwhen-full = 'stack' # overflow\r\nwindow-cap = 0 # unlimited\r\n[layout.displays.'\(key)'] # screen\r\nratio = 0.7\r\n" var document = try TOMLDocument(parsing: source) try SettingsDocumentEditor.apply(.value(.layout(.whenFull), .string("float")), to: &document) #expect(document.render() == source.replacingOccurrences(of: "'stack'", with: "\"float\"")) let configuration = try SettingsDocumentEditor.validate(document) #expect(configuration.layout.global.whenFull == .float) #expect(configuration.layout.values(for: id).whenFull == .float) #expect(configuration.layout.values(for: id).windowCap == 0) #expect(configuration.layout.values(for: id).ratio == 0.7) }
@Test func displayOverflowEditingUsesExistingUUIDSpellingAndDoesNotChangeGlobalValues() throws { let key = "a1b2c3d4-1234-5678-9abc-0123456789ab" let id = try #require(UUID(uuidString: key)) var document = try TOMLDocument( parsing: "[layout]\nwhen-full='float'\nwindow-cap=0\n[layout.displays.'\(key)'] # screen\nratio=0.7\n") try SettingsDocumentEditor.apply(.value(.layout(.whenFull, display: id), .string("stack")), to: &document) let configuration = try SettingsDocumentEditor.validate(document) #expect(configuration.layout.global == LayoutValues(windowCap: 0, whenFull: .float)) #expect(configuration.layout.values(for: id) == LayoutValues(ratio: 0.7, windowCap: 0, whenFull: .stack)) #expect(document.source.contains("[layout.displays.'\(key)'] # screen")) #expect(document.node(forKey: ["layout", "displays", id.uuidString]) == nil) #expect(document.node(forKey: ["layout", "displays", key, "when-full"])?.value == .string("stack")) }
@Test func firstOverflowEditCreatesOnlyTheRequestedDisplayOverride() throws { let id = UUID() var document = try TOMLDocument(parsing: "# defaults\n") try SettingsDocumentEditor.apply(.value(.layout(.whenFull, display: id), .string("float")), to: &document) let configuration = try SettingsDocumentEditor.validate(document) #expect(configuration.layout.global == LayoutValues()) #expect(configuration.layout.values(for: id) == LayoutValues(whenFull: .float)) let values = try #require(document.node(forKey: ["layout", "displays", id.uuidString])) guard case .table(let fields) = values.value else { Issue.record("The display override must be a table.") return } #expect(Set(fields.keys) == ["when-full"]) #expect(document.source.contains("# defaults")) }
@Test func settingsModelSavesOverflowBehaviorReloadsInheritanceAndRetainsUnlimitedCaps() async throws { let directory = FileManager.default.temporaryDirectory.appendingPathComponent( UUID().uuidString, isDirectory: true) try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: false) defer { do { try FileManager.default.removeItem(at: directory) } catch { Issue.record(error) } } let file = directory.appendingPathComponent("parcel.toml") let id = UUID() let source = "# settings\n[layout]\nwindow-cap=0\n[layout.displays.'\(id.uuidString)']\nratio=0.7\n" try Data(source.utf8).write(to: file) let model = SettingsModel(store: ConfigStore(fileURL: file)) await model.start() do { #expect(model.configuration.layout.global.whenFull == .stack) try await model.setValue(.string("float"), for: .layout(.whenFull)) #expect(model.configuration.layout.values(for: id).whenFull == .float) #expect(model.configuration.layout.values(for: id).windowCap == 0) try await model.setValue(.string("stack"), for: .layout(.whenFull, display: id)) try await model.setValue(.integer(2), for: .layout(.windowCap, display: id)) await model.reload() #expect(model.configuration.layout.global == LayoutValues(windowCap: 0, whenFull: .float)) #expect( model.configuration.layout.values(for: id) == LayoutValues(ratio: 0.7, windowCap: 2, whenFull: .stack)) #expect(model.error == nil) #expect(model.diagnostics.isEmpty) let written = try String(contentsOf: file, encoding: .utf8) #expect(written.contains("# settings")) #expect(try SettingsDocumentEditor.validate(TOMLDocument(parsing: written)) == model.configuration) } catch { await model.stop() throw error } await model.stop() }
@Test(arguments: [TOMLValue.string("Stack"), .string("unknown"), .bool(false), .integer(1)]) func invalidOverflowSettingsNeverReachDisk(value: TOMLValue) throws { let directory = FileManager.default.temporaryDirectory.appendingPathComponent( UUID().uuidString, isDirectory: true) try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: false) defer { do { try FileManager.default.removeItem(at: directory) } catch { Issue.record(error) } } let file = directory.appendingPathComponent("parcel.toml") let source = "# unchanged\n[layout]\nwhen-full='stack'\n" try Data(source.utf8).write(to: file) #expect(throws: SettingsFailure.self) { try SettingsFileEditor.commit(.value(.layout(.whenFull), value), fileURL: file, expectedSource: source) } #expect(try String(contentsOf: file, encoding: .utf8) == source) }}