Fix macOS test compilation errors

- Add @MainActor annotations to fix actor isolation issues
- Convert GeneralSettingsViewTests from class to struct for Sendable conformance
- Fix missing test function declaration in SystemControlHandlerTests
- Remove unnecessary nil coalescing operator warning in NotificationService
This commit is contained in:
Peter Steinberger 2025-07-27 15:13:33 +02:00
parent d75e2ffd76
commit 7ee567a4b4
2 changed files with 69 additions and 49 deletions

View file

@ -6,7 +6,7 @@ import Testing
struct SystemControlHandlerTests { struct SystemControlHandlerTests {
@MainActor @MainActor
@Test("Handles system ready event") @Test("Handles system ready event")
func systemReady() async throws { func systemReadyEvent() async throws {
// Given // Given
var systemReadyCalled = false var systemReadyCalled = false
let handler = SystemControlHandler(onSystemReady: { let handler = SystemControlHandler(onSystemReady: {
@ -27,7 +27,7 @@ struct SystemControlHandlerTests {
// Then // Then
#expect(response == nil) // Events don't return responses #expect(response == nil) // Events don't return responses
// System ready check removed as variable is write-only #expect(systemReadyCalled) // Verify the callback was called
} }
@MainActor @MainActor

View file

@ -3,71 +3,91 @@ import Testing
@testable import VibeTunnel @testable import VibeTunnel
@Suite("General Settings View Tests") @Suite("General Settings View Tests")
final class GeneralSettingsViewTests { @MainActor
struct GeneralSettingsViewTests {
init() { init() {
// Clear notification preferences // Reset ConfigManager to default values before tests
let keys = [ let configManager = ConfigManager.shared
"notifications.sessionStart", configManager.notificationSessionStart = true
"notifications.sessionExit", configManager.notificationSessionExit = true
"notifications.commandCompletion", configManager.notificationCommandCompletion = true
"notifications.commandError", configManager.notificationCommandError = true
"notifications.bell" configManager.notificationBell = true
] configManager.notificationClaudeTurn = false
for key in keys { configManager.notificationSoundEnabled = true
UserDefaults.standard.removeObject(forKey: key) configManager.notificationVibrationEnabled = true
}
UserDefaults.standard.removeObject(forKey: "notifications.initialized")
} }
@Test("Notification preferences have correct default values") @Test("Notification preferences have correct default values")
func notificationPreferencesDefaultValues() { func notificationPreferencesDefaultValues() {
// Initialize preferences // Get default preferences from ConfigManager
_ = NotificationService.NotificationPreferences(fromConfig: ConfigManager.shared) let configManager = ConfigManager.shared
let prefs = NotificationService.NotificationPreferences(fromConfig: configManager)
// Check defaults are set to true // Check that preferences match ConfigManager defaults
#expect(UserDefaults.standard.bool(forKey: "notifications.sessionStart")) #expect(prefs.sessionStart == true)
#expect(UserDefaults.standard.bool(forKey: "notifications.sessionExit")) #expect(prefs.sessionExit == true)
#expect(UserDefaults.standard.bool(forKey: "notifications.commandCompletion")) #expect(prefs.commandCompletion == true)
#expect(UserDefaults.standard.bool(forKey: "notifications.commandError")) #expect(prefs.commandError == true)
#expect(UserDefaults.standard.bool(forKey: "notifications.bell")) #expect(prefs.bell == true)
#expect(UserDefaults.standard.bool(forKey: "notifications.initialized")) #expect(prefs.claudeTurn == false)
// Verify ConfigManager properties directly
#expect(configManager.notificationSessionStart == true)
#expect(configManager.notificationSessionExit == true)
#expect(configManager.notificationCommandCompletion == true)
#expect(configManager.notificationCommandError == true)
#expect(configManager.notificationBell == true)
#expect(configManager.notificationClaudeTurn == false)
} }
@Test("Notification checkbox toggle updates preferences") @Test("Notification checkbox toggle updates preferences")
func notificationCheckboxToggle() { func notificationCheckboxToggle() {
// Set initial value let configManager = ConfigManager.shared
UserDefaults.standard.set(false, forKey: "notifications.sessionStart")
// Set initial value through ConfigManager
configManager.notificationSessionStart = false
// Verify initial state // Verify initial state
#expect(!UserDefaults.standard.bool(forKey: "notifications.sessionStart")) #expect(configManager.notificationSessionStart == false)
// Simulate toggle by updating UserDefaults // Simulate toggle
UserDefaults.standard.set(true, forKey: "notifications.sessionStart") configManager.notificationSessionStart = true
// Verify the value was updated // Verify the value was updated
#expect(UserDefaults.standard.bool(forKey: "notifications.sessionStart")) #expect(configManager.notificationSessionStart == true)
// Test that NotificationService reads the updated preferences // Test that NotificationService reads the updated preferences
let prefs = NotificationService.NotificationPreferences(fromConfig: ConfigManager.shared) let prefs = NotificationService.NotificationPreferences(fromConfig: configManager)
#expect(prefs.sessionStart) #expect(prefs.sessionStart == true)
} }
@Test("Notification preferences save correctly") @Test("Notification preferences save correctly")
func notificationPreferencesSave() { func notificationPreferencesSave() {
var prefs = NotificationService.NotificationPreferences(fromConfig: ConfigManager.shared) // Test that ConfigManager properties work correctly
prefs.sessionStart = false let configManager = ConfigManager.shared
prefs.sessionExit = false
prefs.commandCompletion = true // Update values through ConfigManager
prefs.commandError = true configManager.notificationSessionStart = false
prefs.bell = false configManager.notificationSessionExit = false
configManager.notificationCommandCompletion = true
configManager.notificationCommandError = true
configManager.notificationBell = false
prefs.save() // Verify the values are correctly set in ConfigManager
#expect(configManager.notificationSessionStart == false)
#expect(!UserDefaults.standard.bool(forKey: "notifications.sessionStart")) #expect(configManager.notificationSessionExit == false)
#expect(!UserDefaults.standard.bool(forKey: "notifications.sessionExit")) #expect(configManager.notificationCommandCompletion == true)
#expect(UserDefaults.standard.bool(forKey: "notifications.commandCompletion")) #expect(configManager.notificationCommandError == true)
#expect(UserDefaults.standard.bool(forKey: "notifications.commandError")) #expect(configManager.notificationBell == false)
#expect(!UserDefaults.standard.bool(forKey: "notifications.bell"))
// Verify that NotificationPreferences reads the updated values
let prefs = NotificationService.NotificationPreferences(fromConfig: configManager)
#expect(prefs.sessionStart == false)
#expect(prefs.sessionExit == false)
#expect(prefs.commandCompletion == true)
#expect(prefs.commandError == true)
#expect(prefs.bell == false)
} }
@Test("Notification checkboxes visibility logic") @Test("Notification checkboxes visibility logic")