Skip to content

Commit be2a093

Browse files
test: SignedInView UI when signing-in
1 parent f1b7396 commit be2a093

File tree

5 files changed

+39
-16
lines changed

5 files changed

+39
-16
lines changed

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/EmailAuthView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ extension EmailAuthView: View {
6565
.padding(.vertical, 6)
6666
.background(Divider(), alignment: .bottom)
6767
.padding(.bottom, 4)
68+
.accessibilityIdentifier("email-field")
6869

6970
LabeledContent {
7071
SecureField(authService.string.passwordInputLabel, text: $password)
@@ -79,6 +80,7 @@ extension EmailAuthView: View {
7980
.padding(.vertical, 6)
8081
.background(Divider(), alignment: .bottom)
8182
.padding(.bottom, 8)
83+
.accessibilityIdentifier("password-field")
8284

8385
if authService.authenticationFlow == .login {
8486
Button(action: {
@@ -126,6 +128,7 @@ extension EmailAuthView: View {
126128
.padding([.top, .bottom], 8)
127129
.frame(maxWidth: .infinity)
128130
.buttonStyle(.borderedProminent)
131+
.accessibilityIdentifier("sign-in-button")
129132
Button(action: {
130133
authService.authView = .emailLink
131134
}) {

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/SignedInView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extension SignedInView: View {
2323
.font(.largeTitle)
2424
.fontWeight(.bold)
2525
.padding()
26+
.accessibilityIdentifier("signed-in-text")
2627
Text(authService.string.accountSettingsEmailLabel)
2728
Text("\(authService.currentUser?.email ?? "Unknown")")
2829

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample/ContentView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ struct ContentView: View {
2525
actionCodeSettings.linkDomain = "flutterfire-e2e-tests.firebaseapp.com"
2626
actionCodeSettings.setIOSBundleID(Bundle.main.bundleIdentifier!)
2727
let configuration = AuthConfiguration(
28-
shouldAutoUpgradeAnonymousUsers: true,
28+
shouldAutoUpgradeAnonymousUsers: isUITestRunner ? false : true,
2929
tosUrl: URL(string: "https://example.com/tos"),
3030
privacyPolicyUrl: URL(string: "https://example.com/privacy"),
3131
emailLinkSignInActionCodeSettings: actionCodeSettings
3232
)
33+
3334
authService = AuthService(
3435
configuration: configuration
3536
)

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample/FirebaseSwiftUIExampleApp.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ import FirebaseCore
1010
import GoogleSignIn
1111
import SwiftUI
1212

13+
public let isUITestRunner = CommandLine.arguments.contains("--ui-test-runner")
14+
1315
class AppDelegate: NSObject, UIApplicationDelegate {
1416
func application(_ application: UIApplication,
1517
didFinishLaunchingWithOptions launchOptions: [
1618
UIApplication.LaunchOptionsKey: Any
1719
]?) -> Bool {
1820
FirebaseApp.configure()
21+
if isUITestRunner {
22+
Auth.auth().useEmulator(withHost: "localhost", port: 9099)
23+
}
1924
ApplicationDelegate.shared.application(
2025
application,
2126
didFinishLaunchingWithOptions: launchOptions

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleUITests/FirebaseSwiftUIExampleUITests.swift

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,50 @@ import XCTest
99

1010
final class FirebaseSwiftUIExampleUITests: XCTestCase {
1111
override func setUpWithError() throws {
12-
// Put setup code here. This method is called before the invocation of each test method in the
13-
// class.
14-
15-
// In UI tests it is usually best to stop immediately when a failure occurs.
1612
continueAfterFailure = false
17-
18-
// In UI tests it’s important to set the initial state - such as interface orientation -
19-
// required for your tests before they run. The setUp method is a good place to do this.
2013
}
2114

22-
override func tearDownWithError() throws {
23-
// Put teardown code here. This method is called after the invocation of each test method in the
24-
// class.
25-
}
15+
override func tearDownWithError() throws {}
2616

2717
@MainActor
2818
func testExample() throws {
29-
// UI tests must launch the application that they test.
3019
let app = XCUIApplication()
3120
app.launch()
32-
33-
// Use XCTAssert and related functions to verify your tests produce the correct results.
3421
}
3522

3623
@MainActor
3724
func testLaunchPerformance() throws {
3825
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) {
39-
// This measures how long it takes to launch your application.
4026
measure(metrics: [XCTApplicationLaunchMetric()]) {
4127
XCUIApplication().launch()
4228
}
4329
}
4430
}
31+
32+
@MainActor
33+
func testSignInDisplaysSignedInView() throws {
34+
let app = XCUIApplication()
35+
app.launchArguments.append("--ui-test-runner")
36+
app.launch()
37+
38+
let emailField = app.textFields["email-field"]
39+
XCTAssertTrue(emailField.waitForExistence(timeout: 2), "Email field should exist")
40+
emailField.tap()
41+
emailField.typeText("[email protected]")
42+
43+
let passwordField = app.secureTextFields["password-field"]
44+
XCTAssertTrue(passwordField.exists, "Password field should exist")
45+
passwordField.tap()
46+
passwordField.typeText("123456")
47+
48+
let signInButton = app.buttons["sign-in-button"]
49+
XCTAssertTrue(signInButton.exists, "Sign-In button should exist")
50+
signInButton.tap()
51+
52+
let signedInText = app.staticTexts["signed-in-text"]
53+
XCTAssertTrue(
54+
signedInText.waitForExistence(timeout: 10),
55+
"SignedInView should be visible after login"
56+
)
57+
}
4558
}

0 commit comments

Comments
 (0)