trash
This commit is contained in:
@@ -1,94 +0,0 @@
|
|||||||
//
|
|
||||||
// AppDelegateTestabilityTests.swift
|
|
||||||
// GazeTests
|
|
||||||
//
|
|
||||||
// Tests demonstrating AppDelegate testability with dependency injection.
|
|
||||||
//
|
|
||||||
|
|
||||||
import XCTest
|
|
||||||
|
|
||||||
@testable import Gaze
|
|
||||||
|
|
||||||
@MainActor
|
|
||||||
final class AppDelegateTestabilityTests: XCTestCase {
|
|
||||||
|
|
||||||
var testEnv: TestEnvironment!
|
|
||||||
|
|
||||||
override func setUp() async throws {
|
|
||||||
testEnv = TestEnvironment(settings: .onboardingCompleted)
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tearDown() async throws {
|
|
||||||
testEnv = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAppDelegateCreationWithMocks() {
|
|
||||||
let appDelegate = testEnv.createAppDelegate()
|
|
||||||
|
|
||||||
XCTAssertNotNil(appDelegate)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testWindowManagerReceivesReminderEvents() async throws {
|
|
||||||
let appDelegate = testEnv.createAppDelegate()
|
|
||||||
|
|
||||||
let notification = Notification(name: NSApplication.didFinishLaunchingNotification)
|
|
||||||
appDelegate.applicationDidFinishLaunching(notification)
|
|
||||||
|
|
||||||
try await Task.sleep(for: .milliseconds(100))
|
|
||||||
|
|
||||||
if let timerEngine = appDelegate.timerEngine {
|
|
||||||
let timerId = TimerIdentifier.builtIn(.blink)
|
|
||||||
timerEngine.triggerReminder(for: timerId)
|
|
||||||
|
|
||||||
try await Task.sleep(for: .milliseconds(100))
|
|
||||||
|
|
||||||
// Verify window manager received the show command
|
|
||||||
XCTAssertTrue(testEnv.windowManager.didPerformOperation(.showSubtleReminder))
|
|
||||||
} else {
|
|
||||||
XCTFail("TimerEngine not initialized")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testSettingsChangesPropagate() async throws {
|
|
||||||
let appDelegate = testEnv.createAppDelegate()
|
|
||||||
|
|
||||||
// Change a setting
|
|
||||||
testEnv.settingsManager.settings.lookAwayEnabled = false
|
|
||||||
|
|
||||||
try await Task.sleep(for: .milliseconds(50))
|
|
||||||
|
|
||||||
// Verify the change propagated
|
|
||||||
XCTAssertFalse(testEnv.settingsManager.settings.lookAwayEnabled)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testOpenSettingsUsesWindowManager() {
|
|
||||||
let appDelegate = testEnv.createAppDelegate()
|
|
||||||
|
|
||||||
appDelegate.openSettings(tab: 2)
|
|
||||||
|
|
||||||
// Give time for async dispatch
|
|
||||||
let expectation = XCTestExpectation(description: "Settings opened")
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
|
|
||||||
XCTAssertTrue(
|
|
||||||
self.testEnv.windowManager.didPerformOperation(.showSettings(initialTab: 2)))
|
|
||||||
expectation.fulfill()
|
|
||||||
}
|
|
||||||
|
|
||||||
wait(for: [expectation], timeout: 1.0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testOpenOnboardingUsesWindowManager() {
|
|
||||||
let appDelegate = testEnv.createAppDelegate()
|
|
||||||
|
|
||||||
appDelegate.openOnboarding()
|
|
||||||
|
|
||||||
// Give time for async dispatch
|
|
||||||
let expectation = XCTestExpectation(description: "Onboarding opened")
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
|
|
||||||
XCTAssertTrue(self.testEnv.windowManager.didPerformOperation(.showOnboarding))
|
|
||||||
expectation.fulfill()
|
|
||||||
}
|
|
||||||
|
|
||||||
wait(for: [expectation], timeout: 1.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
//
|
|
||||||
// ExampleUnitTests.swift
|
|
||||||
// Gaze
|
|
||||||
//
|
|
||||||
// Created by AI Assistant on 1/15/26.
|
|
||||||
//
|
|
||||||
|
|
||||||
import Testing
|
|
||||||
@testable import Gaze
|
|
||||||
|
|
||||||
struct ExampleUnitTests {
|
|
||||||
|
|
||||||
@Test func exampleOfUnitTesting() async throws {
|
|
||||||
// This is a simple example of how to write unit tests using Swift's Testing framework
|
|
||||||
|
|
||||||
// Arrange - Set up test data and dependencies
|
|
||||||
let testValue = 42
|
|
||||||
let expectedValue = 42
|
|
||||||
|
|
||||||
// Act - Perform the operation being tested
|
|
||||||
let result = testValue
|
|
||||||
|
|
||||||
// Assert - Verify the result matches expectations
|
|
||||||
#expect(result == expectedValue, "The result should equal the expected value")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test func exampleWithMocking() async throws {
|
|
||||||
// This demonstrates how to mock dependencies in unit tests
|
|
||||||
|
|
||||||
// We would typically create a mock implementation of a protocol here
|
|
||||||
// For example:
|
|
||||||
// let mockSettingsManager = MockSettingsManager()
|
|
||||||
// let sut = SomeClass(settingsManager: mockSettingsManager)
|
|
||||||
|
|
||||||
// Then test the behavior without relying on real external dependencies
|
|
||||||
|
|
||||||
#expect(true, "Mocking demonstration - this would test with mocked dependencies")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
//
|
|
||||||
// MockWindowManagerTests.swift
|
|
||||||
// GazeTests
|
|
||||||
//
|
|
||||||
// Tests for MockWindowManager functionality.
|
|
||||||
//
|
|
||||||
|
|
||||||
import SwiftUI
|
|
||||||
import XCTest
|
|
||||||
@testable import Gaze
|
|
||||||
|
|
||||||
@MainActor
|
|
||||||
final class MockWindowManagerTests: XCTestCase {
|
|
||||||
|
|
||||||
var windowManager: MockWindowManager!
|
|
||||||
|
|
||||||
override func setUp() async throws {
|
|
||||||
windowManager = MockWindowManager()
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tearDown() async throws {
|
|
||||||
windowManager = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testShowOverlayReminder() {
|
|
||||||
XCTAssertFalse(windowManager.isOverlayReminderVisible)
|
|
||||||
|
|
||||||
let view = Text("Test Overlay")
|
|
||||||
windowManager.showReminderWindow(view, windowType: .overlay)
|
|
||||||
|
|
||||||
XCTAssertTrue(windowManager.isOverlayReminderVisible)
|
|
||||||
XCTAssertTrue(windowManager.didPerformOperation(.showOverlayReminder))
|
|
||||||
}
|
|
||||||
|
|
||||||
func testShowSubtleReminder() {
|
|
||||||
XCTAssertFalse(windowManager.isSubtleReminderVisible)
|
|
||||||
|
|
||||||
let view = Text("Test Subtle")
|
|
||||||
windowManager.showReminderWindow(view, windowType: .subtle)
|
|
||||||
|
|
||||||
XCTAssertTrue(windowManager.isSubtleReminderVisible)
|
|
||||||
XCTAssertTrue(windowManager.didPerformOperation(.showSubtleReminder))
|
|
||||||
}
|
|
||||||
|
|
||||||
func testDismissOverlayReminder() {
|
|
||||||
let view = Text("Test")
|
|
||||||
windowManager.showReminderWindow(view, windowType: .overlay)
|
|
||||||
XCTAssertTrue(windowManager.isOverlayReminderVisible)
|
|
||||||
|
|
||||||
windowManager.dismissOverlayReminder()
|
|
||||||
|
|
||||||
XCTAssertFalse(windowManager.isOverlayReminderVisible)
|
|
||||||
XCTAssertTrue(windowManager.didPerformOperation(.dismissOverlayReminder))
|
|
||||||
}
|
|
||||||
|
|
||||||
func testDismissAllReminders() {
|
|
||||||
let view = Text("Test")
|
|
||||||
windowManager.showReminderWindow(view, windowType: .overlay)
|
|
||||||
windowManager.showReminderWindow(view, windowType: .subtle)
|
|
||||||
|
|
||||||
XCTAssertTrue(windowManager.isOverlayReminderVisible)
|
|
||||||
XCTAssertTrue(windowManager.isSubtleReminderVisible)
|
|
||||||
|
|
||||||
windowManager.dismissAllReminders()
|
|
||||||
|
|
||||||
XCTAssertFalse(windowManager.isOverlayReminderVisible)
|
|
||||||
XCTAssertFalse(windowManager.isSubtleReminderVisible)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testOperationTracking() {
|
|
||||||
let view = Text("Test")
|
|
||||||
|
|
||||||
windowManager.showReminderWindow(view, windowType: .overlay)
|
|
||||||
windowManager.showReminderWindow(view, windowType: .overlay)
|
|
||||||
windowManager.dismissOverlayReminder()
|
|
||||||
|
|
||||||
XCTAssertEqual(windowManager.operationCount(.showOverlayReminder), 2)
|
|
||||||
XCTAssertEqual(windowManager.operationCount(.dismissOverlayReminder), 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testCallbacks() {
|
|
||||||
var overlayShown = false
|
|
||||||
windowManager.onShowOverlayReminder = {
|
|
||||||
overlayShown = true
|
|
||||||
}
|
|
||||||
|
|
||||||
let view = Text("Test")
|
|
||||||
windowManager.showReminderWindow(view, windowType: .overlay)
|
|
||||||
|
|
||||||
XCTAssertTrue(overlayShown)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testReset() {
|
|
||||||
let view = Text("Test")
|
|
||||||
windowManager.showReminderWindow(view, windowType: .overlay)
|
|
||||||
windowManager.onShowOverlayReminder = { }
|
|
||||||
|
|
||||||
windowManager.reset()
|
|
||||||
|
|
||||||
XCTAssertFalse(windowManager.isOverlayReminderVisible)
|
|
||||||
XCTAssertEqual(windowManager.operations.count, 0)
|
|
||||||
XCTAssertNil(windowManager.onShowOverlayReminder)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
//
|
|
||||||
// ServiceContainerTests.swift
|
|
||||||
// GazeTests
|
|
||||||
//
|
|
||||||
// Tests for the dependency injection infrastructure.
|
|
||||||
//
|
|
||||||
|
|
||||||
import XCTest
|
|
||||||
@testable import Gaze
|
|
||||||
|
|
||||||
@MainActor
|
|
||||||
final class ServiceContainerTests: XCTestCase {
|
|
||||||
|
|
||||||
func testProductionContainerCreation() {
|
|
||||||
let container = ServiceContainer.shared
|
|
||||||
|
|
||||||
XCTAssertNotNil(container.settingsManager)
|
|
||||||
XCTAssertNotNil(container.enforceModeService)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testTestContainerCreation() {
|
|
||||||
let settings = AppSettings.onlyLookAwayEnabled
|
|
||||||
let container = TestServiceContainer(settings: settings)
|
|
||||||
|
|
||||||
XCTAssertEqual(container.settingsManager.settings.lookAwayEnabled, true)
|
|
||||||
XCTAssertEqual(container.settingsManager.settings.blinkEnabled, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testTimerEngineCreation() {
|
|
||||||
let container = TestServiceContainer()
|
|
||||||
let timerEngine = container.timerEngine
|
|
||||||
|
|
||||||
XCTAssertNotNil(timerEngine)
|
|
||||||
// Second access should return the same instance
|
|
||||||
XCTAssertTrue(container.timerEngine === timerEngine)
|
|
||||||
XCTAssertTrue(container.timeProvider is MockTimeProvider)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testCustomTimerEngineInjection() {
|
|
||||||
let container = TestServiceContainer()
|
|
||||||
let mockSettings = EnhancedMockSettingsManager(settings: .shortIntervals)
|
|
||||||
let customEngine = TimerEngine(
|
|
||||||
settingsManager: mockSettings,
|
|
||||||
enforceModeService: nil,
|
|
||||||
timeProvider: MockTimeProvider()
|
|
||||||
)
|
|
||||||
|
|
||||||
container.setTimerEngine(customEngine)
|
|
||||||
XCTAssertTrue(container.timerEngine === customEngine)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testContainerReset() {
|
|
||||||
let container = TestServiceContainer()
|
|
||||||
|
|
||||||
// Access timer engine to create it
|
|
||||||
let existingEngine = container.timerEngine
|
|
||||||
|
|
||||||
// Reset should clear the timer engine
|
|
||||||
container.reset()
|
|
||||||
|
|
||||||
// Accessing again should create a new instance
|
|
||||||
let newEngine = container.timerEngine
|
|
||||||
XCTAssertNotNil(newEngine)
|
|
||||||
XCTAssertFalse(existingEngine === newEngine)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,211 +0,0 @@
|
|||||||
//
|
|
||||||
// EnforceModeServiceTests.swift
|
|
||||||
// GazeTests
|
|
||||||
//
|
|
||||||
// Unit tests for EnforceModeService.
|
|
||||||
//
|
|
||||||
|
|
||||||
import XCTest
|
|
||||||
@testable import Gaze
|
|
||||||
|
|
||||||
@MainActor
|
|
||||||
final class EnforceModeServiceTests: XCTestCase {
|
|
||||||
|
|
||||||
var service: EnforceModeService!
|
|
||||||
|
|
||||||
override func setUp() async throws {
|
|
||||||
service = EnforceModeService.shared
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tearDown() async throws {
|
|
||||||
service.disableEnforceMode()
|
|
||||||
service = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Initialization Tests
|
|
||||||
|
|
||||||
func testServiceInitialization() {
|
|
||||||
XCTAssertNotNil(service)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testInitialState() {
|
|
||||||
XCTAssertFalse(service.isEnforceModeEnabled)
|
|
||||||
XCTAssertFalse(service.isCameraActive)
|
|
||||||
XCTAssertFalse(service.userCompliedWithBreak)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Enable/Disable Tests
|
|
||||||
|
|
||||||
func testEnableEnforceMode() async {
|
|
||||||
await service.enableEnforceMode()
|
|
||||||
|
|
||||||
// May or may not be enabled depending on camera permissions
|
|
||||||
// Just verify the method doesn't crash
|
|
||||||
XCTAssertNotNil(service)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testDisableEnforceMode() {
|
|
||||||
service.disableEnforceMode()
|
|
||||||
|
|
||||||
XCTAssertFalse(service.isEnforceModeEnabled)
|
|
||||||
XCTAssertFalse(service.isCameraActive)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testEnableDisableCycle() async {
|
|
||||||
await service.enableEnforceMode()
|
|
||||||
service.disableEnforceMode()
|
|
||||||
|
|
||||||
XCTAssertFalse(service.isEnforceModeEnabled)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Timer Engine Integration Tests
|
|
||||||
|
|
||||||
func testSetTimerEngine() {
|
|
||||||
let testEnv = TestEnvironment()
|
|
||||||
let timerEngine = testEnv.container.timerEngine
|
|
||||||
|
|
||||||
service.setTimerEngine(timerEngine)
|
|
||||||
|
|
||||||
// Should not crash
|
|
||||||
XCTAssertNotNil(service)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Should Enforce Tests
|
|
||||||
|
|
||||||
func testShouldEnforceBreakWhenDisabled() {
|
|
||||||
service.disableEnforceMode()
|
|
||||||
|
|
||||||
let shouldEnforce = service.shouldEnforceBreak(for: .builtIn(.lookAway))
|
|
||||||
XCTAssertFalse(shouldEnforce)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testShouldEnforceLookAwayTimer() {
|
|
||||||
let shouldEnforce = service.shouldEnforce(timerIdentifier: .builtIn(.lookAway))
|
|
||||||
// Result depends on settings, but method should not crash
|
|
||||||
XCTAssertNotNil(shouldEnforce)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testShouldEnforceUserTimerNever() {
|
|
||||||
let shouldEnforce = service.shouldEnforce(timerIdentifier: .user(id: "test"))
|
|
||||||
XCTAssertFalse(shouldEnforce)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testShouldEnforceBuiltInPostureTimerNever() {
|
|
||||||
let shouldEnforce = service.shouldEnforce(timerIdentifier: .builtIn(.posture))
|
|
||||||
XCTAssertFalse(shouldEnforce)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testShouldEnforceBuiltInBlinkTimerNever() {
|
|
||||||
let shouldEnforce = service.shouldEnforce(timerIdentifier: .builtIn(.blink))
|
|
||||||
XCTAssertFalse(shouldEnforce)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Pre-activate Camera Tests
|
|
||||||
|
|
||||||
func testShouldPreActivateCameraWhenSecondsRemainingTooHigh() {
|
|
||||||
let shouldPreActivate = service.shouldPreActivateCamera(
|
|
||||||
timerIdentifier: .builtIn(.lookAway),
|
|
||||||
secondsRemaining: 5
|
|
||||||
)
|
|
||||||
XCTAssertFalse(shouldPreActivate)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testShouldPreActivateCameraForUserTimerNever() {
|
|
||||||
let shouldPreActivate = service.shouldPreActivateCamera(
|
|
||||||
timerIdentifier: .user(id: "test"),
|
|
||||||
secondsRemaining: 1
|
|
||||||
)
|
|
||||||
XCTAssertFalse(shouldPreActivate)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Compliance Evaluation Tests
|
|
||||||
|
|
||||||
func testEvaluateComplianceWhenLookingAtScreenAndFaceDetected() {
|
|
||||||
let result = service.evaluateCompliance(
|
|
||||||
isLookingAtScreen: true,
|
|
||||||
faceDetected: true
|
|
||||||
)
|
|
||||||
XCTAssertEqual(result, .notCompliant)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testEvaluateComplianceWhenNotLookingAtScreenAndFaceDetected() {
|
|
||||||
let result = service.evaluateCompliance(
|
|
||||||
isLookingAtScreen: false,
|
|
||||||
faceDetected: true
|
|
||||||
)
|
|
||||||
XCTAssertEqual(result, .compliant)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testEvaluateComplianceWhenFaceNotDetected() {
|
|
||||||
let result = service.evaluateCompliance(
|
|
||||||
isLookingAtScreen: true,
|
|
||||||
faceDetected: false
|
|
||||||
)
|
|
||||||
XCTAssertEqual(result, .faceNotDetected)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testEvaluateComplianceWhenFaceNotDetectedAndNotLookingAtScreen() {
|
|
||||||
let result = service.evaluateCompliance(
|
|
||||||
isLookingAtScreen: false,
|
|
||||||
faceDetected: false
|
|
||||||
)
|
|
||||||
XCTAssertEqual(result, .faceNotDetected)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Camera Tests
|
|
||||||
|
|
||||||
func testStopCamera() {
|
|
||||||
service.stopCamera()
|
|
||||||
|
|
||||||
XCTAssertFalse(service.isCameraActive)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Compliance Tests
|
|
||||||
|
|
||||||
func testCheckUserCompliance() {
|
|
||||||
service.checkUserCompliance()
|
|
||||||
|
|
||||||
// Should not crash
|
|
||||||
XCTAssertNotNil(service)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testHandleReminderDismissed() {
|
|
||||||
service.handleReminderDismissed()
|
|
||||||
|
|
||||||
// Should not crash
|
|
||||||
XCTAssertNotNil(service)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Test Mode Tests
|
|
||||||
|
|
||||||
func testStartTestMode() async {
|
|
||||||
await service.enableEnforceMode()
|
|
||||||
await service.startTestMode()
|
|
||||||
|
|
||||||
// Test mode requires enforce mode to be enabled and camera permissions
|
|
||||||
// Just verify it doesn't crash
|
|
||||||
XCTAssertNotNil(service)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testStopTestMode() {
|
|
||||||
service.stopTestMode()
|
|
||||||
|
|
||||||
XCTAssertFalse(service.isTestMode)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testTestModeCycle() async {
|
|
||||||
await service.enableEnforceMode()
|
|
||||||
await service.startTestMode()
|
|
||||||
|
|
||||||
service.stopTestMode()
|
|
||||||
XCTAssertFalse(service.isTestMode)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Protocol Conformance Tests
|
|
||||||
|
|
||||||
func testConformsToEnforceModeProviding() {
|
|
||||||
let providing: EnforceModeProviding = service
|
|
||||||
XCTAssertNotNil(providing)
|
|
||||||
XCTAssertFalse(providing.isEnforceModeEnabled)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
//
|
|
||||||
// FullscreenDetectionServiceTests.swift
|
|
||||||
// GazeTests
|
|
||||||
//
|
|
||||||
// Unit tests for FullscreenDetectionService.
|
|
||||||
//
|
|
||||||
|
|
||||||
import Combine
|
|
||||||
import XCTest
|
|
||||||
@testable import Gaze
|
|
||||||
|
|
||||||
@MainActor
|
|
||||||
final class FullscreenDetectionServiceTests: XCTestCase {
|
|
||||||
|
|
||||||
var service: FullscreenDetectionService!
|
|
||||||
var cancellables: Set<AnyCancellable>!
|
|
||||||
|
|
||||||
override func setUp() async throws {
|
|
||||||
service = FullscreenDetectionService()
|
|
||||||
cancellables = []
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tearDown() async throws {
|
|
||||||
cancellables = nil
|
|
||||||
service = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Initialization Tests
|
|
||||||
|
|
||||||
func testServiceInitialization() {
|
|
||||||
XCTAssertNotNil(service)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testInitialFullscreenState() {
|
|
||||||
// Initially should not be in fullscreen (unless actually in fullscreen)
|
|
||||||
XCTAssertNotNil(service.isFullscreenActive)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Publisher Tests
|
|
||||||
|
|
||||||
func testFullscreenStatePublisher() async throws {
|
|
||||||
let expectation = XCTestExpectation(description: "Fullscreen state published")
|
|
||||||
|
|
||||||
service.$isFullscreenActive
|
|
||||||
.sink { isFullscreen in
|
|
||||||
expectation.fulfill()
|
|
||||||
}
|
|
||||||
.store(in: &cancellables)
|
|
||||||
|
|
||||||
await fulfillment(of: [expectation], timeout: 0.1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Force Update Tests
|
|
||||||
|
|
||||||
func testForceUpdate() {
|
|
||||||
// Should not crash
|
|
||||||
service.forceUpdate()
|
|
||||||
XCTAssertNotNil(service.isFullscreenActive)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Protocol Conformance Tests
|
|
||||||
|
|
||||||
func testConformsToFullscreenDetectionProviding() {
|
|
||||||
let providing: FullscreenDetectionProviding = service
|
|
||||||
XCTAssertNotNil(providing)
|
|
||||||
XCTAssertNotNil(providing.isFullscreenActive)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
//
|
|
||||||
// IdleMonitoringServiceTests.swift
|
|
||||||
// GazeTests
|
|
||||||
//
|
|
||||||
// Unit tests for IdleMonitoringService.
|
|
||||||
//
|
|
||||||
|
|
||||||
import Combine
|
|
||||||
import XCTest
|
|
||||||
@testable import Gaze
|
|
||||||
|
|
||||||
@MainActor
|
|
||||||
final class IdleMonitoringServiceTests: XCTestCase {
|
|
||||||
|
|
||||||
var service: IdleMonitoringService!
|
|
||||||
var cancellables: Set<AnyCancellable>!
|
|
||||||
|
|
||||||
override func setUp() async throws {
|
|
||||||
service = IdleMonitoringService(idleThresholdMinutes: 5)
|
|
||||||
cancellables = []
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tearDown() async throws {
|
|
||||||
cancellables = nil
|
|
||||||
service = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Initialization Tests
|
|
||||||
|
|
||||||
func testServiceInitialization() {
|
|
||||||
XCTAssertNotNil(service)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testInitialIdleState() {
|
|
||||||
// Initially should not be idle
|
|
||||||
XCTAssertFalse(service.isIdle)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testInitializationWithCustomThreshold() {
|
|
||||||
let customService = IdleMonitoringService(idleThresholdMinutes: 10)
|
|
||||||
XCTAssertNotNil(customService)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Threshold Tests
|
|
||||||
|
|
||||||
func testUpdateThreshold() {
|
|
||||||
service.updateThreshold(minutes: 15)
|
|
||||||
|
|
||||||
// Should not crash
|
|
||||||
XCTAssertNotNil(service)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testUpdateThresholdMultipleTimes() {
|
|
||||||
service.updateThreshold(minutes: 5)
|
|
||||||
service.updateThreshold(minutes: 10)
|
|
||||||
service.updateThreshold(minutes: 3)
|
|
||||||
|
|
||||||
XCTAssertNotNil(service)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Publisher Tests
|
|
||||||
|
|
||||||
func testIdleStatePublisher() async throws {
|
|
||||||
let expectation = XCTestExpectation(description: "Idle state published")
|
|
||||||
|
|
||||||
service.$isIdle
|
|
||||||
.sink { isIdle in
|
|
||||||
expectation.fulfill()
|
|
||||||
}
|
|
||||||
.store(in: &cancellables)
|
|
||||||
|
|
||||||
await fulfillment(of: [expectation], timeout: 0.1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Force Update Tests
|
|
||||||
|
|
||||||
func testForceUpdate() {
|
|
||||||
service.forceUpdate()
|
|
||||||
XCTAssertNotNil(service.isIdle)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Protocol Conformance Tests
|
|
||||||
|
|
||||||
func testConformsToIdleMonitoringProviding() {
|
|
||||||
let providing: IdleMonitoringProviding = service
|
|
||||||
XCTAssertNotNil(providing)
|
|
||||||
XCTAssertNotNil(providing.isIdle)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
//
|
|
||||||
// LoggingManagerTests.swift
|
|
||||||
// GazeTests
|
|
||||||
//
|
|
||||||
// Unit tests for LoggingManager.
|
|
||||||
//
|
|
||||||
|
|
||||||
import os.log
|
|
||||||
import XCTest
|
|
||||||
@testable import Gaze
|
|
||||||
|
|
||||||
final class LoggingManagerTests: XCTestCase {
|
|
||||||
|
|
||||||
var loggingManager: LoggingManager!
|
|
||||||
|
|
||||||
override func setUp() {
|
|
||||||
loggingManager = LoggingManager.shared
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tearDown() {
|
|
||||||
loggingManager = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Initialization Tests
|
|
||||||
|
|
||||||
func testLoggingManagerInitialization() {
|
|
||||||
XCTAssertNotNil(loggingManager)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testLoggersExist() {
|
|
||||||
XCTAssertNotNil(loggingManager.appLogger)
|
|
||||||
XCTAssertNotNil(loggingManager.timerLogger)
|
|
||||||
XCTAssertNotNil(loggingManager.systemLogger)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Configuration Tests
|
|
||||||
|
|
||||||
func testConfigureLogging() {
|
|
||||||
// Should not crash
|
|
||||||
loggingManager.configureLogging()
|
|
||||||
XCTAssertNotNil(loggingManager)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Logger Usage Tests
|
|
||||||
|
|
||||||
func testAppLoggerLogging() {
|
|
||||||
// Should not crash
|
|
||||||
loggingManager.appLogger.info("Test app log")
|
|
||||||
XCTAssertNotNil(loggingManager.appLogger)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testTimerLoggerLogging() {
|
|
||||||
loggingManager.timerLogger.info("Test timer log")
|
|
||||||
XCTAssertNotNil(loggingManager.timerLogger)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testSystemLoggerLogging() {
|
|
||||||
loggingManager.systemLogger.info("Test system log")
|
|
||||||
XCTAssertNotNil(loggingManager.systemLogger)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
//
|
|
||||||
// UsageTrackingServiceTests.swift
|
|
||||||
// GazeTests
|
|
||||||
//
|
|
||||||
// Unit tests for UsageTrackingService.
|
|
||||||
//
|
|
||||||
|
|
||||||
import XCTest
|
|
||||||
@testable import Gaze
|
|
||||||
|
|
||||||
@MainActor
|
|
||||||
final class UsageTrackingServiceTests: XCTestCase {
|
|
||||||
|
|
||||||
var service: UsageTrackingService!
|
|
||||||
|
|
||||||
override func setUp() async throws {
|
|
||||||
service = UsageTrackingService(resetThresholdMinutes: 60)
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tearDown() async throws {
|
|
||||||
service = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Initialization Tests
|
|
||||||
|
|
||||||
func testServiceInitialization() {
|
|
||||||
XCTAssertNotNil(service)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testInitializationWithCustomThreshold() {
|
|
||||||
let customService = UsageTrackingService(resetThresholdMinutes: 120)
|
|
||||||
XCTAssertNotNil(customService)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Threshold Tests
|
|
||||||
|
|
||||||
func testUpdateResetThreshold() {
|
|
||||||
service.updateResetThreshold(minutes: 90)
|
|
||||||
|
|
||||||
// Should not crash
|
|
||||||
XCTAssertNotNil(service)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testUpdateThresholdMultipleTimes() {
|
|
||||||
service.updateResetThreshold(minutes: 30)
|
|
||||||
service.updateResetThreshold(minutes: 60)
|
|
||||||
service.updateResetThreshold(minutes: 120)
|
|
||||||
|
|
||||||
XCTAssertNotNil(service)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Idle Monitoring Integration Tests
|
|
||||||
|
|
||||||
func testSetupIdleMonitoring() {
|
|
||||||
let idleService = IdleMonitoringService(idleThresholdMinutes: 5)
|
|
||||||
|
|
||||||
service.setupIdleMonitoring(idleService)
|
|
||||||
|
|
||||||
// Should not crash
|
|
||||||
XCTAssertNotNil(service)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
//
|
|
||||||
// WindowManagerTests.swift
|
|
||||||
// GazeTests
|
|
||||||
//
|
|
||||||
// Unit tests for WindowManager service.
|
|
||||||
//
|
|
||||||
|
|
||||||
import SwiftUI
|
|
||||||
import XCTest
|
|
||||||
@testable import Gaze
|
|
||||||
|
|
||||||
@MainActor
|
|
||||||
final class WindowManagerTests: XCTestCase {
|
|
||||||
|
|
||||||
var windowManager: WindowManager!
|
|
||||||
|
|
||||||
override func setUp() async throws {
|
|
||||||
windowManager = WindowManager.shared
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tearDown() async throws {
|
|
||||||
windowManager.dismissAllReminders()
|
|
||||||
windowManager = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Initialization Tests
|
|
||||||
|
|
||||||
func testWindowManagerInitialization() {
|
|
||||||
XCTAssertNotNil(windowManager)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testInitialState() {
|
|
||||||
XCTAssertFalse(windowManager.isOverlayReminderVisible)
|
|
||||||
XCTAssertFalse(windowManager.isSubtleReminderVisible)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Window Visibility Tests
|
|
||||||
|
|
||||||
func testOverlayReminderVisibility() {
|
|
||||||
XCTAssertFalse(windowManager.isOverlayReminderVisible)
|
|
||||||
|
|
||||||
let view = Text("Test Overlay")
|
|
||||||
windowManager.showReminderWindow(view, windowType: .overlay)
|
|
||||||
|
|
||||||
XCTAssertTrue(windowManager.isOverlayReminderVisible)
|
|
||||||
|
|
||||||
windowManager.dismissOverlayReminder()
|
|
||||||
XCTAssertFalse(windowManager.isOverlayReminderVisible)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testSubtleReminderVisibility() {
|
|
||||||
XCTAssertFalse(windowManager.isSubtleReminderVisible)
|
|
||||||
|
|
||||||
let view = Text("Test Subtle")
|
|
||||||
windowManager.showReminderWindow(view, windowType: .subtle)
|
|
||||||
|
|
||||||
XCTAssertTrue(windowManager.isSubtleReminderVisible)
|
|
||||||
|
|
||||||
windowManager.dismissSubtleReminder()
|
|
||||||
XCTAssertFalse(windowManager.isSubtleReminderVisible)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Multiple Window Tests
|
|
||||||
|
|
||||||
func testShowBothWindowTypes() {
|
|
||||||
let overlayView = Text("Overlay")
|
|
||||||
let subtleView = Text("Subtle")
|
|
||||||
|
|
||||||
windowManager.showReminderWindow(overlayView, windowType: .overlay)
|
|
||||||
windowManager.showReminderWindow(subtleView, windowType: .subtle)
|
|
||||||
|
|
||||||
XCTAssertTrue(windowManager.isOverlayReminderVisible)
|
|
||||||
XCTAssertTrue(windowManager.isSubtleReminderVisible)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testDismissAllReminders() {
|
|
||||||
let overlayView = Text("Overlay")
|
|
||||||
let subtleView = Text("Subtle")
|
|
||||||
|
|
||||||
windowManager.showReminderWindow(overlayView, windowType: .overlay)
|
|
||||||
windowManager.showReminderWindow(subtleView, windowType: .subtle)
|
|
||||||
|
|
||||||
windowManager.dismissAllReminders()
|
|
||||||
|
|
||||||
XCTAssertFalse(windowManager.isOverlayReminderVisible)
|
|
||||||
XCTAssertFalse(windowManager.isSubtleReminderVisible)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Window Replacement Tests
|
|
||||||
|
|
||||||
func testReplaceOverlayWindow() {
|
|
||||||
let firstView = Text("First Overlay")
|
|
||||||
let secondView = Text("Second Overlay")
|
|
||||||
|
|
||||||
windowManager.showReminderWindow(firstView, windowType: .overlay)
|
|
||||||
XCTAssertTrue(windowManager.isOverlayReminderVisible)
|
|
||||||
|
|
||||||
// Showing a new overlay should replace the old one
|
|
||||||
windowManager.showReminderWindow(secondView, windowType: .overlay)
|
|
||||||
XCTAssertTrue(windowManager.isOverlayReminderVisible)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testReplaceSubtleWindow() {
|
|
||||||
let firstView = Text("First Subtle")
|
|
||||||
let secondView = Text("Second Subtle")
|
|
||||||
|
|
||||||
windowManager.showReminderWindow(firstView, windowType: .subtle)
|
|
||||||
XCTAssertTrue(windowManager.isSubtleReminderVisible)
|
|
||||||
|
|
||||||
windowManager.showReminderWindow(secondView, windowType: .subtle)
|
|
||||||
XCTAssertTrue(windowManager.isSubtleReminderVisible)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Integration with Settings Tests
|
|
||||||
|
|
||||||
func testShowSettingsWithSettingsManager() {
|
|
||||||
let settingsManager = SettingsManager.shared
|
|
||||||
|
|
||||||
// Should not crash
|
|
||||||
windowManager.showSettings(settingsManager: settingsManager, initialTab: 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testShowOnboardingWithSettingsManager() {
|
|
||||||
let settingsManager = SettingsManager.shared
|
|
||||||
|
|
||||||
// Should not crash
|
|
||||||
windowManager.showOnboarding(settingsManager: settingsManager)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
//
|
|
||||||
// TimerEngineTestabilityTests.swift
|
|
||||||
// GazeTests
|
|
||||||
//
|
|
||||||
// Tests demonstrating TimerEngine testability with dependency injection.
|
|
||||||
//
|
|
||||||
|
|
||||||
import Combine
|
|
||||||
import XCTest
|
|
||||||
|
|
||||||
@testable import Gaze
|
|
||||||
|
|
||||||
@MainActor
|
|
||||||
final class TimerEngineTestabilityTests: XCTestCase {
|
|
||||||
|
|
||||||
var testEnv: TestEnvironment!
|
|
||||||
var cancellables: Set<AnyCancellable>!
|
|
||||||
|
|
||||||
override func setUp() async throws {
|
|
||||||
testEnv = TestEnvironment(settings: .shortIntervals)
|
|
||||||
cancellables = []
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tearDown() async throws {
|
|
||||||
cancellables = nil
|
|
||||||
testEnv = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testTimerEngineCreationWithMocks() {
|
|
||||||
let timeProvider = MockTimeProvider()
|
|
||||||
let timerEngine = TimerEngine(
|
|
||||||
settingsManager: testEnv.settingsManager,
|
|
||||||
enforceModeService: nil,
|
|
||||||
timeProvider: timeProvider
|
|
||||||
)
|
|
||||||
|
|
||||||
XCTAssertNotNil(timerEngine)
|
|
||||||
XCTAssertEqual(timerEngine.timerStates.count, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testTimerEngineUsesInjectedSettings() {
|
|
||||||
var settings = AppSettings.defaults
|
|
||||||
settings.lookAwayEnabled = true
|
|
||||||
settings.blinkEnabled = false
|
|
||||||
settings.postureEnabled = false
|
|
||||||
|
|
||||||
testEnv.settingsManager.settings = settings
|
|
||||||
let timerEngine = testEnv.container.timerEngine
|
|
||||||
|
|
||||||
timerEngine.start()
|
|
||||||
|
|
||||||
// Only lookAway should be active
|
|
||||||
let lookAwayTimer = timerEngine.timerStates.first { $0.key == .builtIn(.lookAway) }
|
|
||||||
let blinkTimer = timerEngine.timerStates.first { $0.key == .builtIn(.blink) }
|
|
||||||
|
|
||||||
XCTAssertNotNil(lookAwayTimer)
|
|
||||||
XCTAssertNil(blinkTimer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testTimerEngineWithMockTimeProvider() {
|
|
||||||
let timeProvider = MockTimeProvider(startTime: Date())
|
|
||||||
let timerEngine = TimerEngine(
|
|
||||||
settingsManager: testEnv.settingsManager,
|
|
||||||
enforceModeService: nil,
|
|
||||||
timeProvider: timeProvider
|
|
||||||
)
|
|
||||||
|
|
||||||
// Start timers
|
|
||||||
timerEngine.start()
|
|
||||||
|
|
||||||
// Advance time
|
|
||||||
timeProvider.advance(by: 10)
|
|
||||||
|
|
||||||
// Timer engine should use the mocked time
|
|
||||||
XCTAssertNotNil(timerEngine.timerStates)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testPauseAndResumeWithMocks() {
|
|
||||||
let timerEngine = testEnv.container.timerEngine
|
|
||||||
timerEngine.start()
|
|
||||||
|
|
||||||
timerEngine.pause()
|
|
||||||
|
|
||||||
// Verify all timers are paused
|
|
||||||
for (_, state) in timerEngine.timerStates {
|
|
||||||
XCTAssertTrue(state.isPaused)
|
|
||||||
}
|
|
||||||
|
|
||||||
timerEngine.resume()
|
|
||||||
|
|
||||||
// Verify all timers are resumed
|
|
||||||
for (_, state) in timerEngine.timerStates {
|
|
||||||
XCTAssertFalse(state.isPaused)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testReminderEventPublishing() async throws {
|
|
||||||
let timerEngine = testEnv.container.timerEngine
|
|
||||||
|
|
||||||
var receivedReminder: ReminderEvent?
|
|
||||||
timerEngine.$activeReminder
|
|
||||||
.sink { reminder in
|
|
||||||
receivedReminder = reminder
|
|
||||||
}
|
|
||||||
.store(in: &cancellables)
|
|
||||||
|
|
||||||
let timerId = TimerIdentifier.builtIn(.lookAway)
|
|
||||||
timerEngine.triggerReminder(for: timerId)
|
|
||||||
|
|
||||||
try await Task.sleep(for: .milliseconds(10))
|
|
||||||
|
|
||||||
XCTAssertNotNil(receivedReminder)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
//
|
|
||||||
// BlinkSetupViewTests.swift
|
|
||||||
// GazeTests
|
|
||||||
//
|
|
||||||
// Tests for BlinkSetupView component.
|
|
||||||
//
|
|
||||||
|
|
||||||
import SwiftUI
|
|
||||||
import XCTest
|
|
||||||
@testable import Gaze
|
|
||||||
|
|
||||||
@MainActor
|
|
||||||
final class BlinkSetupViewTests: XCTestCase {
|
|
||||||
|
|
||||||
var testEnv: TestEnvironment!
|
|
||||||
|
|
||||||
override func setUp() async throws {
|
|
||||||
testEnv = TestEnvironment()
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tearDown() async throws {
|
|
||||||
testEnv = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testBlinkSetupInitialization() {
|
|
||||||
// Use real SettingsManager for view initialization test since @Bindable requires concrete type
|
|
||||||
let view = BlinkSetupView(settingsManager: SettingsManager.shared)
|
|
||||||
XCTAssertNotNil(view)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testBlinkTimerConfigurationChanges() {
|
|
||||||
XCTAssertFalse(testEnv.settingsManager.settings.blinkEnabled)
|
|
||||||
XCTAssertEqual(testEnv.settingsManager.settings.blinkIntervalMinutes, 7)
|
|
||||||
|
|
||||||
testEnv.settingsManager.settings.blinkEnabled = true
|
|
||||||
testEnv.settingsManager.settings.blinkIntervalMinutes = 5
|
|
||||||
|
|
||||||
XCTAssertTrue(testEnv.settingsManager.settings.blinkEnabled)
|
|
||||||
XCTAssertEqual(testEnv.settingsManager.settings.blinkIntervalMinutes, 5)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testBlinkTimerEnableDisable() {
|
|
||||||
var config = testEnv.settingsManager.settings
|
|
||||||
|
|
||||||
config.blinkEnabled = true
|
|
||||||
config.blinkIntervalMinutes = 4
|
|
||||||
testEnv.settingsManager.settings = config
|
|
||||||
XCTAssertTrue(testEnv.settingsManager.settings.blinkEnabled)
|
|
||||||
|
|
||||||
config.blinkEnabled = false
|
|
||||||
config.blinkIntervalMinutes = 3
|
|
||||||
testEnv.settingsManager.settings = config
|
|
||||||
XCTAssertFalse(testEnv.settingsManager.settings.blinkEnabled)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testBlinkIntervalValidation() {
|
|
||||||
var config = testEnv.settingsManager.settings
|
|
||||||
|
|
||||||
let intervals = [3, 4, 5, 6, 10]
|
|
||||||
for minutes in intervals {
|
|
||||||
config.blinkEnabled = true
|
|
||||||
config.blinkIntervalMinutes = minutes
|
|
||||||
testEnv.settingsManager.settings = config
|
|
||||||
|
|
||||||
let retrieved = testEnv.settingsManager.settings
|
|
||||||
XCTAssertEqual(retrieved.blinkIntervalMinutes, minutes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testBlinkAccessibilityIdentifier() {
|
|
||||||
XCTAssertEqual(
|
|
||||||
AccessibilityIdentifiers.Onboarding.blinkPage,
|
|
||||||
"onboarding.page.blink"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
//
|
|
||||||
// CompletionViewTests.swift
|
|
||||||
// GazeTests
|
|
||||||
//
|
|
||||||
// Tests for CompletionView component.
|
|
||||||
//
|
|
||||||
|
|
||||||
import SwiftUI
|
|
||||||
import XCTest
|
|
||||||
@testable import Gaze
|
|
||||||
|
|
||||||
@MainActor
|
|
||||||
final class CompletionViewTests: XCTestCase {
|
|
||||||
|
|
||||||
func testCompletionViewInitialization() {
|
|
||||||
let view = CompletionView()
|
|
||||||
XCTAssertNotNil(view)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testCompletionAccessibilityIdentifier() {
|
|
||||||
XCTAssertEqual(
|
|
||||||
AccessibilityIdentifiers.Onboarding.completionPage,
|
|
||||||
"onboarding.page.completion"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
//
|
|
||||||
// GeneralSetupViewTests.swift
|
|
||||||
// GazeTests
|
|
||||||
//
|
|
||||||
// Tests for GeneralSetupView component.
|
|
||||||
//
|
|
||||||
|
|
||||||
import SwiftUI
|
|
||||||
import XCTest
|
|
||||||
@testable import Gaze
|
|
||||||
|
|
||||||
@MainActor
|
|
||||||
final class GeneralSetupViewTests: XCTestCase {
|
|
||||||
|
|
||||||
var testEnv: TestEnvironment!
|
|
||||||
|
|
||||||
override func setUp() async throws {
|
|
||||||
testEnv = TestEnvironment()
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tearDown() async throws {
|
|
||||||
testEnv = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testGeneralSetupInitialization() {
|
|
||||||
// Use real SettingsManager for view initialization test since @Bindable requires concrete type
|
|
||||||
let view = GeneralSetupView(settingsManager: SettingsManager.shared, isOnboarding: true)
|
|
||||||
XCTAssertNotNil(view)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testPlaySoundsToggle() {
|
|
||||||
// Initial state
|
|
||||||
let initial = testEnv.settingsManager.settings.playSounds
|
|
||||||
|
|
||||||
// Toggle on
|
|
||||||
testEnv.settingsManager.settings.playSounds = true
|
|
||||||
XCTAssertTrue(testEnv.settingsManager.settings.playSounds)
|
|
||||||
|
|
||||||
// Toggle off
|
|
||||||
testEnv.settingsManager.settings.playSounds = false
|
|
||||||
XCTAssertFalse(testEnv.settingsManager.settings.playSounds)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testLaunchAtLoginToggle() {
|
|
||||||
// Toggle on
|
|
||||||
testEnv.settingsManager.settings.launchAtLogin = true
|
|
||||||
XCTAssertTrue(testEnv.settingsManager.settings.launchAtLogin)
|
|
||||||
|
|
||||||
// Toggle off
|
|
||||||
testEnv.settingsManager.settings.launchAtLogin = false
|
|
||||||
XCTAssertFalse(testEnv.settingsManager.settings.launchAtLogin)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testMultipleSettingsConfiguration() {
|
|
||||||
testEnv.settingsManager.settings.playSounds = true
|
|
||||||
testEnv.settingsManager.settings.launchAtLogin = true
|
|
||||||
|
|
||||||
XCTAssertTrue(testEnv.settingsManager.settings.playSounds)
|
|
||||||
XCTAssertTrue(testEnv.settingsManager.settings.launchAtLogin)
|
|
||||||
|
|
||||||
testEnv.settingsManager.settings.playSounds = false
|
|
||||||
XCTAssertFalse(testEnv.settingsManager.settings.playSounds)
|
|
||||||
XCTAssertTrue(testEnv.settingsManager.settings.launchAtLogin)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testGeneralAccessibilityIdentifier() {
|
|
||||||
XCTAssertEqual(
|
|
||||||
AccessibilityIdentifiers.Onboarding.generalPage,
|
|
||||||
"onboarding.page.general"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
//
|
|
||||||
// LookAwaySetupViewTests.swift
|
|
||||||
// GazeTests
|
|
||||||
//
|
|
||||||
// Tests for LookAwaySetupView component.
|
|
||||||
//
|
|
||||||
|
|
||||||
import SwiftUI
|
|
||||||
import XCTest
|
|
||||||
@testable import Gaze
|
|
||||||
|
|
||||||
@MainActor
|
|
||||||
final class LookAwaySetupViewTests: XCTestCase {
|
|
||||||
|
|
||||||
var testEnv: TestEnvironment!
|
|
||||||
|
|
||||||
override func setUp() async throws {
|
|
||||||
testEnv = TestEnvironment()
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tearDown() async throws {
|
|
||||||
testEnv = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testLookAwaySetupInitialization() {
|
|
||||||
// Use real SettingsManager for view initialization test since @Bindable requires concrete type
|
|
||||||
let view = LookAwaySetupView(settingsManager: SettingsManager.shared)
|
|
||||||
XCTAssertNotNil(view)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testLookAwayTimerConfigurationChanges() {
|
|
||||||
// Start with default
|
|
||||||
XCTAssertTrue(testEnv.settingsManager.settings.lookAwayEnabled)
|
|
||||||
XCTAssertEqual(testEnv.settingsManager.settings.lookAwayIntervalMinutes, 20)
|
|
||||||
|
|
||||||
// Modify configuration
|
|
||||||
testEnv.settingsManager.settings.lookAwayEnabled = true
|
|
||||||
testEnv.settingsManager.settings.lookAwayIntervalMinutes = 25
|
|
||||||
|
|
||||||
// Verify changes
|
|
||||||
XCTAssertTrue(testEnv.settingsManager.settings.lookAwayEnabled)
|
|
||||||
XCTAssertEqual(testEnv.settingsManager.settings.lookAwayIntervalMinutes, 25)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testLookAwayTimerEnableDisable() {
|
|
||||||
var config = testEnv.settingsManager.settings
|
|
||||||
|
|
||||||
// Enable
|
|
||||||
config.lookAwayEnabled = true
|
|
||||||
config.lookAwayIntervalMinutes = 15
|
|
||||||
testEnv.settingsManager.settings = config
|
|
||||||
XCTAssertTrue(testEnv.settingsManager.settings.lookAwayEnabled)
|
|
||||||
|
|
||||||
// Disable
|
|
||||||
config.lookAwayEnabled = false
|
|
||||||
config.lookAwayIntervalMinutes = 10
|
|
||||||
testEnv.settingsManager.settings = config
|
|
||||||
XCTAssertFalse(testEnv.settingsManager.settings.lookAwayEnabled)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testLookAwayIntervalValidation() {
|
|
||||||
var config = testEnv.settingsManager.settings
|
|
||||||
|
|
||||||
// Test various intervals (in minutes)
|
|
||||||
let intervals = [5, 10, 20, 30, 60]
|
|
||||||
for minutes in intervals {
|
|
||||||
config.lookAwayEnabled = true
|
|
||||||
config.lookAwayIntervalMinutes = minutes
|
|
||||||
testEnv.settingsManager.settings = config
|
|
||||||
|
|
||||||
let retrieved = testEnv.settingsManager.settings
|
|
||||||
XCTAssertEqual(retrieved.lookAwayIntervalMinutes, minutes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testLookAwayAccessibilityIdentifier() {
|
|
||||||
XCTAssertEqual(
|
|
||||||
AccessibilityIdentifiers.Onboarding.lookAwayPage,
|
|
||||||
"onboarding.page.lookAway"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
//
|
|
||||||
// PostureSetupViewTests.swift
|
|
||||||
// GazeTests
|
|
||||||
//
|
|
||||||
// Tests for PostureSetupView component.
|
|
||||||
//
|
|
||||||
|
|
||||||
import SwiftUI
|
|
||||||
import XCTest
|
|
||||||
@testable import Gaze
|
|
||||||
|
|
||||||
@MainActor
|
|
||||||
final class PostureSetupViewTests: XCTestCase {
|
|
||||||
|
|
||||||
var testEnv: TestEnvironment!
|
|
||||||
|
|
||||||
override func setUp() async throws {
|
|
||||||
testEnv = TestEnvironment()
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tearDown() async throws {
|
|
||||||
testEnv = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testPostureSetupInitialization() {
|
|
||||||
// Use real SettingsManager for view initialization test since @Bindable requires concrete type
|
|
||||||
let view = PostureSetupView(settingsManager: SettingsManager.shared)
|
|
||||||
XCTAssertNotNil(view)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testPostureTimerConfigurationChanges() {
|
|
||||||
// Start with default
|
|
||||||
XCTAssertTrue(testEnv.settingsManager.settings.postureEnabled)
|
|
||||||
XCTAssertEqual(testEnv.settingsManager.settings.postureIntervalMinutes, 30)
|
|
||||||
|
|
||||||
// Modify configuration
|
|
||||||
testEnv.settingsManager.settings.postureEnabled = true
|
|
||||||
testEnv.settingsManager.settings.postureIntervalMinutes = 45
|
|
||||||
|
|
||||||
// Verify changes
|
|
||||||
XCTAssertTrue(testEnv.settingsManager.settings.postureEnabled)
|
|
||||||
XCTAssertEqual(testEnv.settingsManager.settings.postureIntervalMinutes, 45)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testPostureTimerEnableDisable() {
|
|
||||||
var config = testEnv.settingsManager.settings
|
|
||||||
|
|
||||||
// Enable
|
|
||||||
config.postureEnabled = true
|
|
||||||
config.postureIntervalMinutes = 25
|
|
||||||
testEnv.settingsManager.settings = config
|
|
||||||
XCTAssertTrue(testEnv.settingsManager.settings.postureEnabled)
|
|
||||||
|
|
||||||
// Disable
|
|
||||||
config.postureEnabled = false
|
|
||||||
config.postureIntervalMinutes = 20
|
|
||||||
testEnv.settingsManager.settings = config
|
|
||||||
XCTAssertFalse(testEnv.settingsManager.settings.postureEnabled)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testPostureIntervalValidation() {
|
|
||||||
var config = testEnv.settingsManager.settings
|
|
||||||
|
|
||||||
// Test various intervals (in minutes)
|
|
||||||
let intervals = [15, 20, 30, 45, 60]
|
|
||||||
for minutes in intervals {
|
|
||||||
config.postureEnabled = true
|
|
||||||
config.postureIntervalMinutes = minutes
|
|
||||||
testEnv.settingsManager.settings = config
|
|
||||||
|
|
||||||
let retrieved = testEnv.settingsManager.settings
|
|
||||||
XCTAssertEqual(retrieved.postureIntervalMinutes, minutes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testPostureAccessibilityIdentifier() {
|
|
||||||
XCTAssertEqual(
|
|
||||||
AccessibilityIdentifiers.Onboarding.posturePage,
|
|
||||||
"onboarding.page.posture"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
//
|
|
||||||
// WelcomeViewTests.swift
|
|
||||||
// GazeTests
|
|
||||||
//
|
|
||||||
// Tests for WelcomeView component.
|
|
||||||
//
|
|
||||||
|
|
||||||
import SwiftUI
|
|
||||||
import XCTest
|
|
||||||
@testable import Gaze
|
|
||||||
|
|
||||||
@MainActor
|
|
||||||
final class WelcomeViewTests: XCTestCase {
|
|
||||||
|
|
||||||
func testWelcomeViewInitialization() {
|
|
||||||
let view = WelcomeView()
|
|
||||||
XCTAssertNotNil(view)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testWelcomeViewHasAccessibilityIdentifier() {
|
|
||||||
// Welcome view should have proper accessibility identifier
|
|
||||||
// This is a structural test - in real app, verify the view has the identifier
|
|
||||||
XCTAssertEqual(
|
|
||||||
AccessibilityIdentifiers.Onboarding.welcomePage,
|
|
||||||
"onboarding.page.welcome"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user