general: working through bugs and maintainability
This commit is contained in:
@@ -6,15 +6,13 @@
|
||||
//
|
||||
|
||||
import Combine
|
||||
import CoreGraphics
|
||||
import XCTest
|
||||
@testable import Gaze
|
||||
|
||||
@MainActor
|
||||
final class FullscreenDetectionServiceTests: XCTestCase {
|
||||
func testPermissionDeniedKeepsStateFalse() {
|
||||
let mockManager = MockPermissionManager(status: ScreenCaptureAuthorizationStatus.denied)
|
||||
let service = FullscreenDetectionService(permissionManager: mockManager)
|
||||
let service = FullscreenDetectionService(permissionManager: MockPermissionManager(status: .denied))
|
||||
|
||||
let expectation = expectation(description: "No change")
|
||||
expectation.isInverted = true
|
||||
@@ -30,77 +28,6 @@ final class FullscreenDetectionServiceTests: XCTestCase {
|
||||
wait(for: [expectation], timeout: 0.5)
|
||||
cancellable.cancel()
|
||||
}
|
||||
|
||||
func testFullscreenStateBecomesTrueWhenWindowMatchesScreen() {
|
||||
let mockManager = MockPermissionManager(status: ScreenCaptureAuthorizationStatus.authorized)
|
||||
let environment = MockFullscreenEnvironment(
|
||||
frontmostPID: 42,
|
||||
windowDescriptors: [
|
||||
FullscreenWindowDescriptor(
|
||||
ownerPID: 42,
|
||||
layer: 0,
|
||||
bounds: CGRect(x: 0, y: 0, width: 1920, height: 1080)
|
||||
)
|
||||
],
|
||||
screenFrames: [CGRect(x: 0, y: 0, width: 1920, height: 1080)]
|
||||
)
|
||||
|
||||
let service = FullscreenDetectionService(
|
||||
permissionManager: mockManager,
|
||||
environmentProvider: environment
|
||||
)
|
||||
|
||||
let expectation = expectation(description: "Fullscreen detected")
|
||||
|
||||
let cancellable = service.$isFullscreenActive
|
||||
.dropFirst()
|
||||
.sink { isActive in
|
||||
if isActive {
|
||||
expectation.fulfill()
|
||||
}
|
||||
}
|
||||
|
||||
service.forceUpdate()
|
||||
|
||||
wait(for: [expectation], timeout: 0.5)
|
||||
cancellable.cancel()
|
||||
}
|
||||
|
||||
func testFullscreenStateStaysFalseWhenWindowDoesNotMatchScreen() {
|
||||
let mockManager = MockPermissionManager(status: ScreenCaptureAuthorizationStatus.authorized)
|
||||
let environment = MockFullscreenEnvironment(
|
||||
frontmostPID: 42,
|
||||
windowDescriptors: [
|
||||
FullscreenWindowDescriptor(
|
||||
ownerPID: 42,
|
||||
layer: 0,
|
||||
bounds: CGRect(x: 100, y: 100, width: 800, height: 600)
|
||||
)
|
||||
],
|
||||
screenFrames: [CGRect(x: 0, y: 0, width: 1920, height: 1080)]
|
||||
)
|
||||
|
||||
let service = FullscreenDetectionService(
|
||||
permissionManager: mockManager,
|
||||
environmentProvider: environment
|
||||
)
|
||||
|
||||
let expectation = expectation(description: "No fullscreen")
|
||||
expectation.isInverted = true
|
||||
|
||||
let cancellable = service.$isFullscreenActive
|
||||
.dropFirst()
|
||||
.sink { isActive in
|
||||
if isActive {
|
||||
expectation.fulfill()
|
||||
}
|
||||
}
|
||||
|
||||
service.forceUpdate()
|
||||
|
||||
wait(for: [expectation], timeout: 0.5)
|
||||
cancellable.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
||||
Reference in New Issue
Block a user