Skip to content

Commit e49d18a

Browse files
authored
Merge pull request #811 from Esri/df/stabilizeAttachmentCameraControllerTests.testOnCameraCaptureModeChanged()
Stabilize `AttachmentCameraControllerTests.testOnCameraCaptureModeChanged()`
2 parents 3deb902 + 9fd6444 commit e49d18a

File tree

2 files changed

+59
-16
lines changed

2 files changed

+59
-16
lines changed

Test Runner/Test Runner/TestViews/AttachmentCameraControllerTestView.swift

+33-6
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,42 @@ import SwiftUI
2020
struct AttachmentCameraControllerTestView: View {
2121
@State private var captureMode: UIImagePickerController.CameraCaptureMode?
2222

23+
@State private var orientation = UIDeviceOrientation.unknown
24+
2325
var body: some View {
24-
Text(captureMode?.name ?? "None")
25-
.accessibilityIdentifier("Camera Capture Mode")
26-
AttachmentCameraController(importState: .constant(.none))
27-
.onCameraCaptureModeChanged { captureMode in
28-
self.captureMode = captureMode
26+
Color.clear
27+
.fullScreenCover(isPresented: .constant(true)) {
28+
AttachmentCameraController(importState: .constant(.none))
29+
.onCameraCaptureModeChanged { captureMode in
30+
self.captureMode = captureMode
31+
}
32+
.overlay {
33+
VStack {
34+
Text(captureMode?.name ?? "None")
35+
.accessibilityIdentifier("Camera Capture Mode")
36+
Text(orientation.name)
37+
.accessibilityIdentifier("Device Orientation")
38+
.onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in
39+
orientation = UIDevice.current.orientation
40+
}
41+
.task {
42+
orientation = UIDevice.current.orientation
43+
}
44+
}
45+
}
2946
}
3047
}
31-
48+
}
49+
50+
extension UIDeviceOrientation {
51+
var name: String {
52+
switch self {
53+
case .portrait: "Portrait"
54+
case .landscapeLeft: "Landscape Left"
55+
case .landscapeRight: "Landscape Right"
56+
default: "Other"
57+
}
58+
}
3259
}
3360

3461
extension UIImagePickerController.CameraCaptureMode {

Test Runner/UI Tests/AttachmentCameraControllerTests.swift

+26-10
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,19 @@ final class AttachmentCameraControllerTests: XCTestCase {
2929
let app = XCUIApplication()
3030
let cameraModeController = app.otherElements["CameraMode"]
3131
let cameraModeLabel = app.staticTexts["Camera Capture Mode"]
32+
let device = UIDevice.current.userInterfaceIdiom
33+
let orientation = app.staticTexts["Device Orientation"]
34+
3235
app.launch()
3336

37+
let attachmentCameraControllerTestsButton = app.buttons["AttachmentCameraController Tests"]
38+
39+
XCTAssertTrue(
40+
attachmentCameraControllerTestsButton.exists,
41+
"The AttachmentCameraController Tests button wasn't found."
42+
)
43+
attachmentCameraControllerTestsButton.tap()
44+
3445
addUIInterruptionMonitor(withDescription: "Camera access alert") { (alert) -> Bool in
3546
alert.buttons["Allow"].tap()
3647
return true
@@ -40,22 +51,27 @@ final class AttachmentCameraControllerTests: XCTestCase {
4051
return true
4152
}
4253

43-
let attachmentCameraControllerTestsButton = app.buttons["AttachmentCameraController Tests"]
44-
45-
XCTAssertTrue(
46-
attachmentCameraControllerTestsButton.exists,
47-
"The AttachmentCameraController Tests button wasn't found."
48-
)
49-
attachmentCameraControllerTestsButton.tap()
50-
5154
XCTAssertTrue(
5255
cameraModeController.waitForExistence(timeout: 5)
5356
)
54-
cameraModeController.swipeDown()
57+
58+
if device == .pad || (device == .phone && orientation.label == "Landscape Right") {
59+
cameraModeController.swipeDown()
60+
} else if orientation.label == "Landscape Left" {
61+
cameraModeController.swipeUp()
62+
} else /* iPhone - portrait */ {
63+
cameraModeController.swipeRight()
64+
}
5565

5666
XCTAssertEqual(cameraModeLabel.label, "Video")
5767

58-
cameraModeController.swipeUp()
68+
if device == .pad || (device == .phone && orientation.label == "Landscape Right") {
69+
cameraModeController.swipeUp()
70+
} else if orientation.label == "Landscape Left" {
71+
cameraModeController.swipeDown()
72+
} else /* iPhone - portrait */ {
73+
cameraModeController.swipeLeft()
74+
}
5975

6076
XCTAssertEqual(cameraModeLabel.label, "Photo")
6177
}

0 commit comments

Comments
 (0)