-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[camera_avfoundation] Pigeon swift migration - part 2 #10980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,18 +57,17 @@ final class CameraPermissionManagerTests: XCTestCase { | |
| let (permissionManager, mockPermissionService) = createSutAndMocks() | ||
| let expectation = self.expectation( | ||
| description: "Must complete with error if camera access was previously denied.") | ||
| let expectedError = FlutterError( | ||
| code: "CameraAccessDeniedWithoutPrompt", | ||
| message: | ||
| "User has previously denied the camera access request. Go to Settings to enable camera access.", | ||
| details: nil) | ||
|
|
||
| mockPermissionService.authorizationStatusStub = { mediaType in | ||
| XCTAssertEqual(mediaType, .video) | ||
| return .denied | ||
| } | ||
| permissionManager.requestCameraPermission { error in | ||
| XCTAssertEqual(error, expectedError) | ||
| XCTAssertEqual(error?.code, "CameraAccessDeniedWithoutPrompt") | ||
| XCTAssertEqual( | ||
| error?.message, | ||
| "User has previously denied the camera access request. Go to Settings to enable camera access." | ||
| ) | ||
| expectation.fulfill() | ||
| } | ||
|
Comment on lines
65
to
72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a lot of repeated code for asserting error properties across this test file. To improve maintainability and reduce duplication, consider adding a helper function to assert the properties of a For example: private func assertPermissionError(
_ error: PigeonError?,
hasCode expectedCode: String,
hasMessage expectedMessage: String,
file: StaticString = #file,
line: UInt = #line
) {
XCTAssertNotNil(error, "Expected a permission error, but got nil", file: file, line: line)
XCTAssertEqual(error?.code, expectedCode, file: file, line: line)
XCTAssertEqual(error?.message, expectedMessage, file: file, line: line)
}You could then simplify this test case and others like it: permissionManager.requestCameraPermission { error in
assertPermissionError(
error,
hasCode: "CameraAccessDeniedWithoutPrompt",
hasMessage: "User has previously denied the camera access request. Go to Settings to enable camera access."
)
expectation.fulfill()
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pls let me know if you're in favor or agains a helper in those cases. I remember that you were against in an earlier PR but it would be a much simpler helper here
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm ok with either approach. Both seem readable to me. |
||
|
|
||
|
|
@@ -79,17 +78,14 @@ final class CameraPermissionManagerTests: XCTestCase { | |
| let (permissionManager, mockPermissionService) = createSutAndMocks() | ||
| let expectation = self.expectation( | ||
| description: "Must complete with error if camera access is restricted.") | ||
| let expectedError = FlutterError( | ||
| code: "CameraAccessRestricted", | ||
| message: "Camera access is restricted.", | ||
| details: nil) | ||
|
|
||
| mockPermissionService.authorizationStatusStub = { mediaType in | ||
| XCTAssertEqual(mediaType, .video) | ||
| return .restricted | ||
| } | ||
| permissionManager.requestCameraPermission { error in | ||
| XCTAssertEqual(error, expectedError) | ||
| XCTAssertEqual(error?.code, "CameraAccessRestricted") | ||
| XCTAssertEqual(error?.message, "Camera access is restricted.") | ||
| expectation.fulfill() | ||
| } | ||
|
|
||
|
|
@@ -122,10 +118,6 @@ final class CameraPermissionManagerTests: XCTestCase { | |
| let (permissionManager, mockPermissionService) = createSutAndMocks() | ||
| let expectation = self.expectation( | ||
| description: "Must complete with error if user denied access.") | ||
| let expectedError = FlutterError( | ||
| code: "CameraAccessDenied", | ||
| message: "User denied the camera access request.", | ||
| details: nil) | ||
|
|
||
| mockPermissionService.authorizationStatusStub = { mediaType in | ||
| XCTAssertEqual(mediaType, .video) | ||
|
|
@@ -137,7 +129,8 @@ final class CameraPermissionManagerTests: XCTestCase { | |
| handler(false) | ||
| } | ||
| permissionManager.requestCameraPermission { error in | ||
| XCTAssertEqual(error, expectedError) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious why are we changing this? I don't see any problem with this approach. Is it related to equatable? |
||
| XCTAssertEqual(error?.code, "CameraAccessDenied") | ||
| XCTAssertEqual(error?.message, "User denied the camera access request.") | ||
| expectation.fulfill() | ||
| } | ||
|
|
||
|
|
@@ -167,18 +160,17 @@ final class CameraPermissionManagerTests: XCTestCase { | |
| let (permissionManager, mockPermissionService) = createSutAndMocks() | ||
| let expectation = self.expectation( | ||
| description: "Must complete with error if audio access was previously denied.") | ||
| let expectedError = FlutterError( | ||
| code: "AudioAccessDeniedWithoutPrompt", | ||
| message: | ||
| "User has previously denied the audio access request. Go to Settings to enable audio access.", | ||
| details: nil) | ||
|
|
||
| mockPermissionService.authorizationStatusStub = { mediaType in | ||
| XCTAssertEqual(mediaType, .audio) | ||
| return .denied | ||
| } | ||
| permissionManager.requestAudioPermission { error in | ||
| XCTAssertEqual(error, expectedError) | ||
| XCTAssertEqual(error?.code, "AudioAccessDeniedWithoutPrompt") | ||
| XCTAssertEqual( | ||
| error?.message, | ||
| "User has previously denied the audio access request. Go to Settings to enable audio access." | ||
| ) | ||
| expectation.fulfill() | ||
| } | ||
|
|
||
|
|
@@ -189,17 +181,14 @@ final class CameraPermissionManagerTests: XCTestCase { | |
| let (permissionManager, mockPermissionService) = createSutAndMocks() | ||
| let expectation = self.expectation( | ||
| description: "Must complete with error if audio access is restricted.") | ||
| let expectedError = FlutterError( | ||
| code: "AudioAccessRestricted", | ||
| message: "Audio access is restricted.", | ||
| details: nil) | ||
|
|
||
| mockPermissionService.authorizationStatusStub = { mediaType in | ||
| XCTAssertEqual(mediaType, .audio) | ||
| return .restricted | ||
| } | ||
| permissionManager.requestAudioPermission { error in | ||
| XCTAssertEqual(error, expectedError) | ||
| XCTAssertEqual(error?.code, "AudioAccessRestricted") | ||
| XCTAssertEqual(error?.message, "Audio access is restricted.") | ||
| expectation.fulfill() | ||
| } | ||
|
|
||
|
|
@@ -232,10 +221,6 @@ final class CameraPermissionManagerTests: XCTestCase { | |
| let (permissionManager, mockPermissionService) = createSutAndMocks() | ||
| let expectation = self.expectation( | ||
| description: "Must complete with error if user denied access") | ||
| let expectedError = FlutterError( | ||
| code: "AudioAccessDenied", | ||
| message: "User denied the audio access request.", | ||
| details: nil) | ||
|
|
||
| mockPermissionService.authorizationStatusStub = { mediaType in | ||
| XCTAssertEqual(mediaType, .audio) | ||
|
|
@@ -247,7 +232,8 @@ final class CameraPermissionManagerTests: XCTestCase { | |
| handler(false) | ||
| } | ||
| permissionManager.requestAudioPermission { error in | ||
| XCTAssertEqual(error, expectedError) | ||
| XCTAssertEqual(error?.code, "AudioAccessDenied") | ||
| XCTAssertEqual(error?.message, "User denied the audio access request.") | ||
| expectation.fulfill() | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can infer type