vibetunnel/mac/VibeTunnelTests/DockIconManagerTests.swift

111 lines
No EOL
4 KiB
Swift

import Foundation
import Testing
import AppKit
@testable import VibeTunnel
@Suite("Dock Icon Manager Tests")
struct DockIconManagerTests {
@Test("Singleton instance")
@MainActor
func singletonInstance() {
let instance1 = DockIconManager.shared
let instance2 = DockIconManager.shared
#expect(instance1 === instance2)
}
@Test("User preference for dock icon")
func userPreferenceForDockIcon() {
// Store current value to restore later
let currentValue = UserDefaults.standard.bool(forKey: "showInDock")
// Test with dock icon enabled
UserDefaults.standard.set(true, forKey: "showInDock")
#expect(UserDefaults.standard.bool(forKey: "showInDock") == true)
// Test with dock icon disabled
UserDefaults.standard.set(false, forKey: "showInDock")
#expect(UserDefaults.standard.bool(forKey: "showInDock") == false)
// Restore original value
UserDefaults.standard.set(currentValue, forKey: "showInDock")
}
@Test("Update dock visibility based on windows")
@MainActor
func updateDockVisibilityBasedOnWindows() {
let manager = DockIconManager.shared
// Save original preference
let originalPref = UserDefaults.standard.bool(forKey: "showInDock")
// Set preference to hide dock
UserDefaults.standard.set(false, forKey: "showInDock")
// Update visibility - with no windows, dock should be hidden
manager.updateDockVisibility()
// The policy depends on whether there are windows open
// In test environment, NSApp might be nil
if let app = NSApp {
#expect(app.activationPolicy() == .regular || app.activationPolicy() == .accessory)
} else {
// In test environment without NSApp, just verify no crash
#expect(true)
}
// Restore original preference
UserDefaults.standard.set(originalPref, forKey: "showInDock")
}
@Test("Temporarily show dock")
@MainActor
func temporarilyShowDock() {
let manager = DockIconManager.shared
// Call temporarilyShowDock
manager.temporarilyShowDock()
// In CI environment, NSApp might behave differently
if let app = NSApp {
// Accept either regular or accessory since CI environment differs
#expect(app.activationPolicy() == .regular || app.activationPolicy() == .accessory)
} else {
// In test environment without NSApp, just verify no crash
#expect(true)
}
}
@Test("Dock visibility with user preference")
@MainActor
func dockVisibilityWithUserPreference() {
let manager = DockIconManager.shared
let originalPref = UserDefaults.standard.bool(forKey: "showInDock")
// Test with showInDock = true (user wants dock visible)
UserDefaults.standard.set(true, forKey: "showInDock")
manager.updateDockVisibility()
if let app = NSApp {
// In CI environment, policy might not change immediately
#expect(app.activationPolicy() == .regular || app.activationPolicy() == .accessory)
} else {
// In test environment without NSApp, just verify no crash
#expect(true)
}
// Test with showInDock = false (user wants dock hidden)
UserDefaults.standard.set(false, forKey: "showInDock")
manager.updateDockVisibility()
// Dock visibility depends on whether windows are open
// In test environment, NSApp might be nil
if let app = NSApp {
#expect(app.activationPolicy() == .regular || app.activationPolicy() == .accessory)
} else {
// In test environment without NSApp, just verify no crash
#expect(true)
}
// Restore
UserDefaults.standard.set(originalPref, forKey: "showInDock")
}
}