Skip to content

Commit 9fd6444

Browse files
committed
Fix iPhone horizontal test runs
1 parent 6947107 commit 9fd6444

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

Test Runner/Test Runner/TestViews/AttachmentCameraControllerTestView.swift

+25-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ 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 {
2426
Color.clear
2527
.fullScreenCover(isPresented: .constant(true)) {
@@ -28,13 +30,34 @@ struct AttachmentCameraControllerTestView: View {
2830
self.captureMode = captureMode
2931
}
3032
.overlay {
31-
Text(captureMode?.name ?? "None")
32-
.accessibilityIdentifier("Camera Capture Mode")
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+
}
3345
}
3446
}
3547
}
3648
}
3749

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+
}
59+
}
60+
3861
extension UIImagePickerController.CameraCaptureMode {
3962
var name: String {
4063
switch self {

Test Runner/UI Tests/AttachmentCameraControllerTests.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ final class AttachmentCameraControllerTests: XCTestCase {
2929
let app = XCUIApplication()
3030
let cameraModeController = app.otherElements["CameraMode"]
3131
let cameraModeLabel = app.staticTexts["Camera Capture Mode"]
32-
let deviceOrientation = XCUIDevice.shared.orientation
33-
let deviceType = UIDevice.current.userInterfaceIdiom
32+
let device = UIDevice.current.userInterfaceIdiom
33+
let orientation = app.staticTexts["Device Orientation"]
3434

3535
app.launch()
3636

@@ -55,21 +55,21 @@ final class AttachmentCameraControllerTests: XCTestCase {
5555
cameraModeController.waitForExistence(timeout: 5)
5656
)
5757

58-
if deviceType == .pad {
58+
if device == .pad || (device == .phone && orientation.label == "Landscape Right") {
5959
cameraModeController.swipeDown()
60-
} else if deviceOrientation.isLandscape && deviceType == .phone {
60+
} else if orientation.label == "Landscape Left" {
6161
cameraModeController.swipeUp()
62-
} else {
62+
} else /* iPhone - portrait */ {
6363
cameraModeController.swipeRight()
6464
}
6565

6666
XCTAssertEqual(cameraModeLabel.label, "Video")
6767

68-
if deviceType == .pad {
68+
if device == .pad || (device == .phone && orientation.label == "Landscape Right") {
6969
cameraModeController.swipeUp()
70-
} else if deviceOrientation.isLandscape && deviceType == .phone {
70+
} else if orientation.label == "Landscape Left" {
7171
cameraModeController.swipeDown()
72-
} else {
72+
} else /* iPhone - portrait */ {
7373
cameraModeController.swipeLeft()
7474
}
7575

0 commit comments

Comments
 (0)