mirror of
https://github.com/samsonjs/Peekaboo.git
synced 2026-04-09 11:55:48 +00:00
Final fixes for Swift tests to compile
- Remove references to non-existent ServerStatus type - Fix ListCommandTests to use actual WindowsSubcommand properties - Update PermissionsCheckerTests to test actual error types - Remove tests for properties that don't exist in the implementation
This commit is contained in:
parent
803e43cc6b
commit
cd4e8b5d52
2 changed files with 38 additions and 63 deletions
|
|
@ -30,32 +30,18 @@ final class ListCommandTests: XCTestCase {
|
|||
|
||||
XCTAssertEqual(command.app, "Finder")
|
||||
XCTAssertFalse(command.jsonOutput)
|
||||
XCTAssertFalse(command.includeOffScreen)
|
||||
XCTAssertEqual(command.details, [])
|
||||
XCTAssertNil(command.includeDetails)
|
||||
}
|
||||
|
||||
func testWindowsSubcommandWithDetails() throws {
|
||||
// Test windows subcommand with detail options
|
||||
let command = try WindowsSubcommand.parse([
|
||||
"--app", "Finder",
|
||||
"--details", "bounds",
|
||||
"--details", "ids"
|
||||
"--include-details", "bounds,ids"
|
||||
])
|
||||
|
||||
XCTAssertEqual(command.app, "Finder")
|
||||
XCTAssertTrue(command.details.contains(.bounds))
|
||||
XCTAssertTrue(command.details.contains(.ids))
|
||||
}
|
||||
|
||||
func testWindowsSubcommandWithOffScreen() throws {
|
||||
// Test windows subcommand with off-screen option
|
||||
let command = try WindowsSubcommand.parse([
|
||||
"--app", "Safari",
|
||||
"--include-off-screen"
|
||||
])
|
||||
|
||||
XCTAssertEqual(command.app, "Safari")
|
||||
XCTAssertTrue(command.includeOffScreen)
|
||||
XCTAssertEqual(command.includeDetails, "bounds,ids")
|
||||
}
|
||||
|
||||
// MARK: - Data Structure Tests
|
||||
|
|
|
|||
|
|
@ -64,31 +64,24 @@ final class PermissionsCheckerTests: XCTestCase {
|
|||
|
||||
// MARK: - Permission State Tests
|
||||
|
||||
func testPermissionStateEncoding() throws {
|
||||
// Test that permission states can be properly encoded to JSON
|
||||
let serverStatus = ServerStatus(
|
||||
hasScreenRecordingPermission: true,
|
||||
hasAccessibilityPermission: false
|
||||
)
|
||||
|
||||
let encoder = JSONEncoder()
|
||||
encoder.keyEncodingStrategy = .convertToSnakeCase
|
||||
|
||||
let data = try encoder.encode(serverStatus)
|
||||
let json = try JSONSerialization.jsonObject(with: data) as? [String: Any]
|
||||
|
||||
XCTAssertNotNil(json)
|
||||
XCTAssertEqual(json?["has_screen_recording_permission"] as? Bool, true)
|
||||
XCTAssertEqual(json?["has_accessibility_permission"] as? Bool, false)
|
||||
func testPermissionErrors() {
|
||||
// Test permission error types
|
||||
let screenError = PermissionError.screenRecordingDenied
|
||||
let accessError = PermissionError.accessibilityDenied
|
||||
|
||||
XCTAssertNotNil(screenError)
|
||||
XCTAssertNotNil(accessError)
|
||||
}
|
||||
|
||||
// MARK: - Error Handling Tests
|
||||
|
||||
func testPermissionDeniedError() {
|
||||
func testCaptureError() {
|
||||
// Test error creation for permission denied
|
||||
let error = CaptureError.capturePermissionDenied
|
||||
|
||||
XCTAssertEqual(error.description, "Screen recording permission is required")
|
||||
// CaptureError conforms to LocalizedError, so it has errorDescription
|
||||
XCTAssertNotNil(error.errorDescription)
|
||||
XCTAssertTrue(error.errorDescription?.contains("permission") ?? false)
|
||||
}
|
||||
|
||||
// MARK: - Performance Tests
|
||||
|
|
@ -101,33 +94,29 @@ final class PermissionsCheckerTests: XCTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: - Mock Tests (for CI/CD)
|
||||
|
||||
func testMockPermissionScenarios() {
|
||||
// Test various permission scenarios for error handling
|
||||
|
||||
// Scenario 1: No permissions
|
||||
var status = ServerStatus(
|
||||
hasScreenRecordingPermission: false,
|
||||
hasAccessibilityPermission: false
|
||||
)
|
||||
XCTAssertFalse(status.hasScreenRecordingPermission)
|
||||
XCTAssertFalse(status.hasAccessibilityPermission)
|
||||
|
||||
// Scenario 2: Only screen recording
|
||||
status = ServerStatus(
|
||||
hasScreenRecordingPermission: true,
|
||||
hasAccessibilityPermission: false
|
||||
)
|
||||
XCTAssertTrue(status.hasScreenRecordingPermission)
|
||||
XCTAssertFalse(status.hasAccessibilityPermission)
|
||||
|
||||
// Scenario 3: Both permissions
|
||||
status = ServerStatus(
|
||||
hasScreenRecordingPermission: true,
|
||||
hasAccessibilityPermission: true
|
||||
)
|
||||
XCTAssertTrue(status.hasScreenRecordingPermission)
|
||||
XCTAssertTrue(status.hasAccessibilityPermission)
|
||||
// MARK: - Require Permission Tests
|
||||
|
||||
func testRequireScreenRecordingPermission() {
|
||||
// Test the require method - it should throw if permission is denied
|
||||
do {
|
||||
try PermissionsChecker.requireScreenRecordingPermission()
|
||||
// If we get here, permission was granted
|
||||
XCTAssertTrue(true)
|
||||
} catch {
|
||||
// If permission is denied, we should get CaptureError
|
||||
XCTAssertTrue(error is CaptureError)
|
||||
}
|
||||
}
|
||||
|
||||
func testRequireAccessibilityPermission() {
|
||||
// Test the require method - it should throw if permission is denied
|
||||
do {
|
||||
try PermissionsChecker.requireAccessibilityPermission()
|
||||
// If we get here, permission was granted
|
||||
XCTAssertTrue(true)
|
||||
} catch {
|
||||
// If permission is denied, we should get CaptureError
|
||||
XCTAssertTrue(error is CaptureError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue