Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import AppKit
@testable import CmuxNextDesign
@testable import CmuxNextSidebar
import CmuxNextTestSupport
import Testing

/// Disclosure rows participate in the keyboard walk without selecting a workspace.
@MainActor @Suite(.serialized) struct SidebarFoldKeyboardTests {
@MainActor @Suite(.serialized, .closesItsWindows) struct SidebarFoldKeyboardTests {
private static let fold = SidebarDoneFoldID(section: .machine(.local), group: nil)

@Test(arguments: [false, true])
Expand Down Expand Up @@ -156,7 +157,7 @@ import Testing
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 300, height: 800),
styleMask: [.borderless], backing: .buffered, defer: false)
window.isReleasedWhenClosed = false
defer { window.close() }
defer { window.closeAfterTest() }
window.contentView = list
list.reload(animated: false)
try body(list)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import AppKit
import CmuxTheme
@testable import CmuxNextDesign
@testable import CmuxNextSidebar
import CmuxNextTestSupport
import Foundation
import Testing

/// The workspace hover card's tab list in a dark theme reads as clearly as the card around it:
/// each tab's name draws in the theme's primary text, and its path in the theme's secondary text
/// (the token the card's facts use), not a washed-out tertiary grey on the glass (review of the
/// #24785 dark capture; the list landed in #28897).
@MainActor @Suite(.serialized) struct WorkspaceTabHoverCardContrastTests {
@MainActor @Suite(.serialized, .closesItsWindows) struct WorkspaceTabHoverCardContrastTests {
private struct Mounted {
let window: NSWindow
let scope: ThemeScope
Expand All @@ -18,13 +19,13 @@ import Testing

private static func mount(_ body: NSView, recolor: @escaping () -> Void) throws -> Mounted {
_ = NSApplication.shared
let input = ThemeInput(background: ThemeRGB(hex: 0x1E1E1E), foreground: ThemeRGB(hex: 0xD4D4D4))
let scope = ThemeScope(level: .room)
scope.setOverride(try #require(ThemeSpec("Tab Card Dark")), input: input, animated: false)
let window = NSWindow(contentRect: NSRect(x: 100, y: 100, width: 360, height: 260), styleMask: [.borderless],
backing: .buffered, defer: false)
window.isReleasedWhenClosed = false
window.appearance = NSAppearance(named: .darkAqua)
let input = ThemeInput(background: ThemeRGB(hex: 0x1E1E1E), foreground: ThemeRGB(hex: 0xD4D4D4))
let scope = ThemeScope(level: .room)
scope.setOverride(try #require(ThemeSpec("Tab Card Dark")), input: input, animated: false)
let root = NSView(frame: NSRect(x: 0, y: 0, width: 360, height: 260))
window.contentView = root
scope.root(root)
Expand Down Expand Up @@ -90,7 +91,7 @@ import Testing
SidebarTab(id: TabID("t2"), title: "shell", kind: .terminal, folder: "~", state: .success),
])
let mounted = try Self.mount(card) { [weak card] in card?.applyColors() }
defer { mounted.window.close() }
defer { mounted.window.closeAfterTest() }
let primary = try #require(Self.rgb(mounted.scope.perform { Palette.textPrimary }))
let secondary = try #require(Self.rgb(mounted.scope.perform { Palette.textSecondary }))
let byText = Dictionary(Self.labels(in: card).map { ($0.stringValue, $0) }, uniquingKeysWith: { a, _ in a })
Expand All @@ -117,6 +118,7 @@ import Testing
let window = NSWindow(contentRect: NSRect(x: 100, y: 100, width: 460, height: 640), styleMask: [.borderless],
backing: .buffered, defer: false)
window.isReleasedWhenClosed = false
defer { window.closeAfterTest() }
window.appearance = NSAppearance(named: .darkAqua)
let input = ThemeInput(background: ThemeRGB(hex: 0x1E1E1E), foreground: ThemeRGB(hex: 0xD4D4D4))
let scope = ThemeScope(level: .room)
Expand All @@ -140,7 +142,6 @@ import Testing
out[label.stringValue] = Self.brightestInk(label, in: host, rep: rep)
report.append("\(label.stringValue): color=\(String(describing: Self.rgb(label.textColor))) ink=\(out[label.stringValue] ?? -1)")
}
window.close()
return out
}
let inks = try measure(host)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@testable import CmuxNextPages
import AppKit
import CmuxNextPagesTestSupport
import CmuxNextTestSupport
import Foundation
import Testing

Expand All @@ -12,6 +13,7 @@ import Testing
/// W1 "appkit content (PageWebView) != model agentPage", W4 "chromium page nil != model tab").
/// A page with no focus model still grants it itself.
@MainActor
@Suite(.closesItsWindows)
struct PageWebViewFocusViewChangeTests {
private let root: URL
private let descriptor = PageDescriptor(id: "test.focus-view", resource: "focus-view", namespaces: [])
Expand All @@ -37,6 +39,10 @@ struct PageWebViewFocusViewChangeTests {
defer { try? FileManager.default.removeItem(at: root) }
let hosting = FakeChromiumHosting()
let (view, window) = try shownAndFocused(hosting)
defer {
window.closeAfterTest()
view.close()
}
view.chromiumClock = PageTestClock.never
let focusViews = FocusViewRecord()
hosting.focusModel = { page in
Expand All @@ -50,21 +56,21 @@ struct PageWebViewFocusViewChangeTests {
#expect(focusViews.views.count == 1, "the host was not told that Chromium's page takes the keys now")
#expect((focusViews.views.first ?? nil) === page.contentView)
#expect(page.focusAsks.isEmpty, "the page granted Chromium focus behind the host's focus model: \(page.focusAsks)")
window.close()
view.close()
}

@Test func withNoHostThePageTakesTheKeysItselfWhenItsWebKitViewHadThem() async throws {
defer { try? FileManager.default.removeItem(at: root) }
let hosting = FakeChromiumHosting()
let (view, window) = try shownAndFocused(hosting)
defer {
window.closeAfterTest()
view.close()
}
view.chromiumClock = PageTestClock.never

await view.chromiumStart?.value
let page = try #require(hosting.made.first)
#expect(page.focusAsks == [true])
window.close()
view.close()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import AppKit
import CmuxNextActions
import CmuxNextDesign
@testable import CmuxNextPalette
import CmuxNextTestSupport
import Foundation
import Testing

Expand All @@ -16,7 +17,7 @@ import Testing
/// `.build/palette-large-text.png` in the package) for the PR: Search on the left, the command
/// list on the right.
@MainActor
@Suite(.paletteRanker)
@Suite(.paletteRanker, .closesItsWindows)
struct PaletteLargeTextTests {
private struct Case {
let tokens: DensityTokens
Expand All @@ -42,11 +43,11 @@ struct PaletteLargeTextTests {
commands.show(.commands)
await commands.model.settle()
defer {
search.hide()
commands.hide()
search.closeForTest()
commands.closeForTest()
}
var windows: [NSWindow] = []
defer { windows.forEach { $0.close() } }
defer { windows.forEach { $0.closeAfterTest() } }
var images: [(String, NSImage)] = []
for item in Self.cases {
try DensityTokens.$scoped.withValue(item.tokens) {
Expand All @@ -64,7 +65,7 @@ struct PaletteLargeTextTests {
let search = PaletteController(registry: ActionRegistry.standard(), sources: PaletteSources(), frecencyPersistence: nil)
#expect(search.show(scope: PaletteScopeID.search))
await search.model.settle()
defer { search.hide() }
defer { search.closeForTest() }
try Self.checkLiveTextSizeChange(search.model, rows: 0)
}

Expand All @@ -75,13 +76,13 @@ struct PaletteLargeTextTests {
let commands = PaletteController(registry: ActionRegistry.standard(), sources: PaletteSources(), frecencyPersistence: nil)
commands.show(.commands)
await commands.model.settle()
defer { commands.hide() }
defer { commands.closeForTest() }
try Self.checkLiveTextSizeChange(commands.model, rows: 5)
}

private static func checkLiveTextSizeChange(_ model: PaletteModel, rows: Int) throws {
var windows: [NSWindow] = []
defer { windows.forEach { $0.close() } }
defer { windows.forEach { $0.closeAfterTest() } }
let view = DensityTokens.$scoped.withValue(DensityPreset.compact.tokens) {
let view = PaletteContentView(model: model)
host(view, windows: &windows)
Expand Down
Loading