Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114import Foundationimport ParcelCoreimport Testing
@testable import ParcelUI
@MainActorstruct SetupEditorTests { @Test func newSetupDefaultsToHidingOtherApps() { let editor = SetupEditorModel() #expect(editor.setupID == nil) #expect(editor.hideOtherApps) #expect(editor.emoji.isEmpty) #expect(editor.shortcut.isEmpty) #expect(!editor.canSubmit) }
@Test func draftPreservesUnicodeNameAndCanonicalizesOptionalShortcut() throws { let editor = SetupEditorModel() editor.name = " Research 日本語 " editor.emoji = " 📚 " editor.shortcut = " alt-ctrl-1 " editor.hideOtherApps = false let draft = try editor.validatedDraft() #expect(draft.name == "Research 日本語") #expect(draft.emoji == "📚") #expect(draft.shortcut == "ctrl-alt-1") #expect(!draft.hideOtherApps) }
@Test func emptyOptionalValuesBecomeNil() throws { let editor = SetupEditorModel() editor.name = "Research" editor.emoji = " " editor.shortcut = " " let draft = try editor.validatedDraft() #expect(draft.emoji == nil) #expect(draft.shortcut == nil) }
@Test(arguments: ["", " ", String(repeating: "a", count: 129), "Research\nWork"]) func invalidNamesAreRejected(name: String) { let editor = SetupEditorModel() editor.name = name #expect(throws: (any Error).self) { try editor.validatedDraft() } }
@Test(arguments: ["ab", "📚🎨", "a"]) func invalidEmojiIsRejected(emoji: String) { let editor = SetupEditorModel() editor.name = "Research" editor.emoji = emoji #expect(throws: SettingsFailure.self) { try editor.validatedDraft() } }
@Test func malformedShortcutIsRejected() { let editor = SetupEditorModel() editor.name = "Research" editor.shortcut = "not-a-shortcut" #expect(throws: (any Error).self) { try editor.validatedDraft() } }
@Test func editingPersistsMetadataWithoutLaunchingApps() async throws { let setup = SavedSetup(name: "Research", emoji: "📚", shortcut: "ctrl-alt-1", memory: .init()) let fixture = try SetupTestFixture(setups: [setup]) defer { fixture.cleanUp() } try await fixture.coordinator.load() let editor = SetupEditorModel(setup: setup) editor.name = "Writing" editor.emoji = "✍️" editor.shortcut = "ctrl-alt-2" editor.hideOtherApps = false #expect(await editor.submit(to: fixture.coordinator)) #expect(editor.failure == nil) #expect(!editor.isSaving) let saved = try #require(fixture.coordinator.setups.first) #expect(saved.id == setup.id) #expect(saved.name == "Writing") #expect(saved.emoji == "✍️") #expect(saved.shortcut == "ctrl-alt-2") #expect(!saved.hideOtherApps) #expect(saved.memory == setup.memory) #expect(try fixture.store.load().setups == [saved]) }
@Test func saveFailureKeepsTheDraftAndVisibleError() async throws { let fixture = try SetupTestFixture() defer { fixture.cleanUp() } try await fixture.coordinator.load() let editor = SetupEditorModel() editor.name = "Research" #expect(!(await editor.submit(to: fixture.coordinator))) #expect(editor.name == "Research") #expect(editor.failure == fixture.coordinator.failure) #expect(editor.failure?.isEmpty == false) #expect(!editor.isSaving) #expect(fixture.coordinator.setups.isEmpty) }
@Test func duplicateRenameIsVisibleAndDoesNotChangeStoredSetups() async throws { let first = SavedSetup(name: "Research", memory: .init()) let second = SavedSetup(name: "Writing", memory: .init()) let fixture = try SetupTestFixture(setups: [first, second]) defer { fixture.cleanUp() } try await fixture.coordinator.load() let editor = SetupEditorModel(setup: second) editor.name = first.name #expect(!(await editor.submit(to: fixture.coordinator))) #expect(editor.failure?.isEmpty == false) #expect(fixture.coordinator.setups == [first, second]) #expect(try fixture.store.load().setups == [first, second]) }}