mirror of
https://github.com/samsonjs/Peekaboo.git
synced 2026-04-27 15:07:41 +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")
|
XCTAssertEqual(command.app, "Finder")
|
||||||
XCTAssertFalse(command.jsonOutput)
|
XCTAssertFalse(command.jsonOutput)
|
||||||
XCTAssertFalse(command.includeOffScreen)
|
XCTAssertNil(command.includeDetails)
|
||||||
XCTAssertEqual(command.details, [])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testWindowsSubcommandWithDetails() throws {
|
func testWindowsSubcommandWithDetails() throws {
|
||||||
// Test windows subcommand with detail options
|
// Test windows subcommand with detail options
|
||||||
let command = try WindowsSubcommand.parse([
|
let command = try WindowsSubcommand.parse([
|
||||||
"--app", "Finder",
|
"--app", "Finder",
|
||||||
"--details", "bounds",
|
"--include-details", "bounds,ids"
|
||||||
"--details", "ids"
|
|
||||||
])
|
])
|
||||||
|
|
||||||
XCTAssertEqual(command.app, "Finder")
|
XCTAssertEqual(command.app, "Finder")
|
||||||
XCTAssertTrue(command.details.contains(.bounds))
|
XCTAssertEqual(command.includeDetails, "bounds,ids")
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Data Structure Tests
|
// MARK: - Data Structure Tests
|
||||||
|
|
|
||||||
|
|
@ -64,31 +64,24 @@ final class PermissionsCheckerTests: XCTestCase {
|
||||||
|
|
||||||
// MARK: - Permission State Tests
|
// MARK: - Permission State Tests
|
||||||
|
|
||||||
func testPermissionStateEncoding() throws {
|
func testPermissionErrors() {
|
||||||
// Test that permission states can be properly encoded to JSON
|
// Test permission error types
|
||||||
let serverStatus = ServerStatus(
|
let screenError = PermissionError.screenRecordingDenied
|
||||||
hasScreenRecordingPermission: true,
|
let accessError = PermissionError.accessibilityDenied
|
||||||
hasAccessibilityPermission: false
|
|
||||||
)
|
XCTAssertNotNil(screenError)
|
||||||
|
XCTAssertNotNil(accessError)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Error Handling Tests
|
// MARK: - Error Handling Tests
|
||||||
|
|
||||||
func testPermissionDeniedError() {
|
func testCaptureError() {
|
||||||
// Test error creation for permission denied
|
// Test error creation for permission denied
|
||||||
let error = CaptureError.capturePermissionDenied
|
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
|
// MARK: - Performance Tests
|
||||||
|
|
@ -101,33 +94,29 @@ final class PermissionsCheckerTests: XCTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Mock Tests (for CI/CD)
|
// MARK: - Require Permission Tests
|
||||||
|
|
||||||
func testMockPermissionScenarios() {
|
func testRequireScreenRecordingPermission() {
|
||||||
// Test various permission scenarios for error handling
|
// Test the require method - it should throw if permission is denied
|
||||||
|
do {
|
||||||
// Scenario 1: No permissions
|
try PermissionsChecker.requireScreenRecordingPermission()
|
||||||
var status = ServerStatus(
|
// If we get here, permission was granted
|
||||||
hasScreenRecordingPermission: false,
|
XCTAssertTrue(true)
|
||||||
hasAccessibilityPermission: false
|
} catch {
|
||||||
)
|
// If permission is denied, we should get CaptureError
|
||||||
XCTAssertFalse(status.hasScreenRecordingPermission)
|
XCTAssertTrue(error is CaptureError)
|
||||||
XCTAssertFalse(status.hasAccessibilityPermission)
|
}
|
||||||
|
}
|
||||||
// Scenario 2: Only screen recording
|
|
||||||
status = ServerStatus(
|
func testRequireAccessibilityPermission() {
|
||||||
hasScreenRecordingPermission: true,
|
// Test the require method - it should throw if permission is denied
|
||||||
hasAccessibilityPermission: false
|
do {
|
||||||
)
|
try PermissionsChecker.requireAccessibilityPermission()
|
||||||
XCTAssertTrue(status.hasScreenRecordingPermission)
|
// If we get here, permission was granted
|
||||||
XCTAssertFalse(status.hasAccessibilityPermission)
|
XCTAssertTrue(true)
|
||||||
|
} catch {
|
||||||
// Scenario 3: Both permissions
|
// If permission is denied, we should get CaptureError
|
||||||
status = ServerStatus(
|
XCTAssertTrue(error is CaptureError)
|
||||||
hasScreenRecordingPermission: true,
|
}
|
||||||
hasAccessibilityPermission: true
|
|
||||||
)
|
|
||||||
XCTAssertTrue(status.hasScreenRecordingPermission)
|
|
||||||
XCTAssertTrue(status.hasAccessibilityPermission)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue