From 85da70c98d5d9ba211ade0aaea6394157fd00a32 Mon Sep 17 00:00:00 2001 From: Lars <134181853+bo2themax@users.noreply.github.com> Date: Mon, 27 Oct 2025 21:25:40 +0100 Subject: [PATCH] Add more theme test cases from #9360 --- .../GhosttyCustomConfigCase.swift | 11 +- macos/GhosttyUITests/GhosttyThemeTests.swift | 150 +++++++++++++++--- 2 files changed, 136 insertions(+), 25 deletions(-) diff --git a/macos/GhosttyUITests/GhosttyCustomConfigCase.swift b/macos/GhosttyUITests/GhosttyCustomConfigCase.swift index 709533bcc..86e66fa75 100644 --- a/macos/GhosttyUITests/GhosttyCustomConfigCase.swift +++ b/macos/GhosttyUITests/GhosttyCustomConfigCase.swift @@ -24,13 +24,12 @@ class GhosttyCustomConfigCase: XCTestCase { } func updateConfig(_ newConfig: String) throws { - if let configFile { - try FileManager.default.removeItem(at: configFile) + if configFile == nil { + let temporaryConfig = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) + .appendingPathExtension("ghostty") + configFile = temporaryConfig } - let temporaryConfig = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) - .appendingPathExtension("ghostty") - try newConfig.write(to: temporaryConfig, atomically: true, encoding: .utf8) - configFile = temporaryConfig + try newConfig.write(to: configFile!, atomically: true, encoding: .utf8) } func ghosttyApplication() throws -> XCUIApplication { diff --git a/macos/GhosttyUITests/GhosttyThemeTests.swift b/macos/GhosttyUITests/GhosttyThemeTests.swift index fce4b061b..eabd2e535 100644 --- a/macos/GhosttyUITests/GhosttyThemeTests.swift +++ b/macos/GhosttyUITests/GhosttyThemeTests.swift @@ -5,42 +5,154 @@ // Created by luca on 27.10.2025. // -import XCTest import AppKit +import XCTest final class GhosttyThemeTests: GhosttyCustomConfigCase { + let windowTitle = "GhosttyThemeTests" + private func assertTitlebarAppearance( + _ appearance: XCUIDevice.Appearance, + for app: XCUIApplication, + title: String? = nil, + file: StaticString = #filePath, + line: UInt = #line + ) throws { + for i in 0 ..< app.windows.count { + let titleView = app.windows.element(boundBy: i).staticTexts.element(matching: NSPredicate(format: "value == '\(title ?? windowTitle)'")) + + let image = titleView.screenshot().image + guard let imageColor = image.colorAt(x: 0, y: 0) else { + throw XCTSkip("failed to get pixel color", file: file, line: line) + } + + switch appearance { + case .dark: + XCTAssertLessThanOrEqual(imageColor.luminance, 0.5, "Expected dark appearance for this test", file: file, line: line) + default: + XCTAssertGreaterThanOrEqual(imageColor.luminance, 0.5, "Expected light appearance for this test", file: file, line: line) + } + } + } /// https://github.com/ghostty-org/ghostty/issues/8282 - func testIssue8282() throws { - try updateConfig("theme=light:3024 Day,dark:3024 Night\ntitle=GhosttyThemeTests") + @MainActor + func testIssue8282() async throws { + try updateConfig("title=\(windowTitle) \n theme=light:3024 Day,dark:3024 Night") XCUIDevice.shared.appearance = .dark let app = try ghosttyApplication() app.launch() - let windowTitle = app.windows.firstMatch.title - let titleView = app.windows.firstMatch.staticTexts.element(matching: NSPredicate(format: "value == '\(windowTitle)'")) - - let image = titleView.screenshot().image - guard let imageColor = image.colorAt(x: 0, y: 0) else { - return - } - XCTAssertLessThanOrEqual(imageColor.luminance, 0.5, "Expected dark appearance for this test") + try assertTitlebarAppearance(.dark, for: app) // create a split app.groups["Terminal pane"].typeKey("d", modifierFlags: .command) // reload config app.typeKey(",", modifierFlags: [.command, .shift]) + try await Task.sleep(for: .seconds(0.5)) // create a new window app.typeKey("n", modifierFlags: [.command]) + try assertTitlebarAppearance(.dark, for: app) + } - for i in 0..