Repository Public
1import AppKit2import DesignSystem3import SettingsModel4import WorkspaceKit5import XCTest6@testable import SPTerm78/// SP Term Next: chrome modes, toolbar, dynamic accent, completion feedback, motion policy.9@MainActor10final class NextDesignTests: AppTestCase {11 func testWorkspaceFullScreenShowsTheOverviewAndRestoresTheWindow() {12 let model = makeModel()13 let window = model.openWindow()14 window.focusMode = true15 XCTAssertFalse(window.sidebarVisible)16 model.perform(.workspaceFullScreen, in: window)17 XCTAssertNotNil(window.workspaceFullScreen)18 XCTAssertTrue(window.sidebarVisible)19 XCTAssertFalse(window.focusMode)20 XCTAssertTrue(AppAction.workspaceFullScreen.isActive(in: window))21 model.perform(.workspaceFullScreen, in: window)22 XCTAssertNil(window.workspaceFullScreen)23 XCTAssertFalse(window.sidebarVisible, "the sidebar goes back to what it was")24 XCTAssertTrue(window.focusMode, "focus mode goes back to what it was")25 // Leaving native full screen by another route ends the mode too.26 model.perform(.workspaceFullScreen, in: window)27 model.windowDidLeaveFullScreen(window)28 XCTAssertNil(window.workspaceFullScreen)29 XCTAssertFalse(window.sidebarVisible)30 }3132 func testDensityAndFocusModeActions() {33 let model = makeModel()34 let window = model.openWindow()35 XCTAssertEqual(model.settings.density, .compact)36 model.perform(.toggleDensity)37 XCTAssertEqual(model.settings.density, .expanded)38 model.perform(.toggleDensity)39 XCTAssertEqual(model.settings.density, .compact)40 window.chromePeek = true41 model.perform(.focusMode, in: window)42 XCTAssertTrue(window.focusMode)43 XCTAssertFalse(window.chromePeek, "entering focus mode starts with the chrome hidden")44 }4546 func testToolbarIsCustomizableAndKeepsCatalogueOrder() {47 let model = makeModel()48 XCTAssertEqual(model.toolbarActions, [.splitRight, .splitDown, .commandPalette, .toggleAssistant])49 model.setToolbar(.find, shown: true)50 model.setToolbar(.toggleGit, shown: true)51 model.setToolbar(.splitDown, shown: false)52 XCTAssertEqual(model.toolbarActions, [.splitRight, .commandPalette, .toggleAssistant, .toggleGit, .find])53 model.setToolbar(.find, shown: true)54 XCTAssertEqual(model.toolbarActions.filter { $0 == .find }.count, 1, "no duplicate button")55 // Identifiers that are unknown or not offered as buttons are ignored, not fatal.56 model.settings.toolbarItems = ["nope", "closeWindow", "zoomPane"]57 XCTAssertEqual(model.toolbarActions, [.zoomPane])58 for action in AppAction.allCases { XCTAssertFalse(action.symbol.isEmpty, action.rawValue) }59 }6061 func testDynamicAccentGivesEachHostItsOwnStableColour() {62 let model = makeModel()63 let window = model.openWindow()64 let local = window.focusedPane!65 let first = model.newTab(in: window, kind: .ssh(hostAlias: "alpha.invalid"))66 let alpha = window.tabs.first { $0.id == first }!.focusedPane!67 let second = model.newTab(in: window, kind: .ssh(hostAlias: "beta.invalid"))68 let beta = window.tabs.first { $0.id == second }!.focusedPane!69 XCTAssertEqual(model.accent(for: local), model.accent, "a local session keeps the theme accent")70 XCTAssertNotEqual(model.accent(for: alpha), model.accent)71 XCTAssertNotEqual(model.accent(for: alpha), model.accent(for: beta))72 XCTAssertEqual(model.accent(for: alpha), AccentEngine.accent(forHost: "alpha.invalid", theme: model.theme))73 XCTAssertEqual(model.palette(in: window).accentColor, model.accent(for: beta), "the window follows its focused pane")74 model.settings.dynamicAccent = false75 XCTAssertEqual(model.accent(for: alpha), model.accent)76 }7778 func testCompletionFeedbackIsRecordedOnlyForCommandsWorthSignalling() {79 let model = makeModel()80 let window = model.openWindow()81 let pane = window.focusedPane!82 model.noteCompletion(pane, name: "ls", duration: 0.3)83 XCTAssertNil(model.completions[pane], "short commands are not signalled")84 model.noteCompletion(pane, name: "make", duration: 12)85 XCTAssertEqual(model.completions[pane]?.name, "make")86 model.settings.completionFeedback = false87 model.noteCompletion(pane, name: "swift", duration: 40)88 XCTAssertEqual(model.completions[pane]?.name, "make", "nothing new is recorded once the setting is off")89 model.closePane(pane, in: window, confirmed: true)90 XCTAssertNil(model.completions[pane], "a closed pane leaves nothing behind")91 }9293 func testReducedMotionReplacesMovementWithFades() {94 let model = makeModel()95 model.reduceMotion = false96 model.settings.motion = .system97 XCTAssertFalse(model.motion.reduced)98 model.settings.motion = .reduced99 XCTAssertTrue(model.motion.reduced)100 model.settings.motion = .system101 model.reduceMotion = true102 XCTAssertTrue(model.motion.reduced, "the system setting is honoured")103 XCTAssertNil(model.motion.ambient, "the ambient light does not move")104 XCTAssertNotNil(Motion(reduced: false).ambient)105 // High-contrast themes get neither glass nor tint.106 model.increaseContrast = true107 XCTAssertFalse(model.chromeContext.glass)108 XCTAssertEqual(model.theme.tintedChrome(accent: model.accent), model.theme.chromeBackground)109 }110111 func testClosingAWindowReleasesItsAssistant() {112 let model = makeModel()113 let keep = model.openWindow()114 let window = model.openWindow()115 _ = model.assistant(for: window)116 XCTAssertNotNil(model.assistants[window.id])117 model.closeWindow(window, confirmed: true)118 XCTAssertNil(model.assistants[window.id])119 XCTAssertEqual(model.windows.map(\.id), [keep.id])120 }121122 func testAWindowKeepsItsControllerUntilItIsClosed() async {123 let model = makeModel()124 let keep = model.openWindow()125 let window = model.openWindow()126 weak var controller = window.controller127 weak var nsWindow = window.controller?.window128 // Let the run loop and its autorelease pool turn: the controller must survive on its own.129 try? await Task.sleep(for: .milliseconds(200))130 XCTAssertNotNil(controller, "the window state owns its controller")131 XCTAssertTrue(nsWindow?.delegate === controller, "the window still has its delegate")132 XCTAssertFalse(window.isFullScreen)133 XCTAssertTrue(window.showsTitleBar)134 model.closeWindow(window, confirmed: true)135 XCTAssertNil(window.controller, "closing the window breaks the ownership cycle")136 XCTAssertNotNil(keep.controller)137 }138}139