Skip to content

Commit 669360d

Browse files
test: fix up UI testa and format
1 parent 2a0dc03 commit 669360d

File tree

10 files changed

+242
-202
lines changed

10 files changed

+242
-202
lines changed

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample/App/ContentView.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
//
2121

2222
import AppTrackingTransparency
23+
import FirebaseAppleSwiftUI
2324
import FirebaseAuth
2425
import FirebaseAuthSwiftUI
2526
import FirebaseFacebookSwiftUI
2627
import FirebaseGoogleSwiftUI
28+
import FirebaseOAuthSwiftUI
2729
import FirebasePhoneAuthSwiftUI
2830
import FirebaseTwitterSwiftUI
29-
import FirebaseAppleSwiftUI
30-
import FirebaseOAuthSwiftUI
3131
import SwiftUI
3232

3333
struct ContentView: View {
@@ -44,7 +44,7 @@ struct ContentView: View {
4444
emailLinkSignInActionCodeSettings: actionCodeSettings,
4545
mfaEnabled: true
4646
)
47-
47+
4848
authService = AuthService(
4949
configuration: configuration
5050
)
@@ -67,16 +67,16 @@ struct ContentView: View {
6767
)
6868
.withEmailSignIn()
6969
}
70-
70+
7171
let authService: AuthService
72-
72+
7373
var body: some View {
7474
AuthPickerView {
7575
usersApp
7676
}
7777
.environment(authService)
7878
}
79-
79+
8080
var usersApp: some View {
8181
NavigationStack {
8282
VStack {
@@ -91,7 +91,7 @@ struct ContentView: View {
9191
} else {
9292
Text("Authenticated - \(authService.currentUser?.email ?? "")")
9393
Button {
94-
authService.isPresented = true // Reopen the sheet
94+
authService.isPresented = true // Reopen the sheet
9595
} label: {
9696
Text("Manage Account")
9797
}
@@ -111,7 +111,7 @@ struct ContentView: View {
111111
.onAppear {
112112
authService.isPresented = authService.authenticationState == .unauthenticated
113113
}
114-
.onChange(of: authService.authenticationState) { oldValue, newValue in
114+
.onChange(of: authService.authenticationState) { _, newValue in
115115
debugPrint("authService.authenticationState - \(newValue)")
116116
if newValue != .authenticating {
117117
authService.isPresented = newValue == .unauthenticated

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample/App/FirebaseSwiftUIExampleApp.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ struct FirebaseSwiftUIExampleApp: App {
7979

8080
var body: some Scene {
8181
WindowGroup {
82-
// ContentViewSheetExample()
8382
if testRunner {
8483
TestView()
8584
} else {

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample/TestView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
// Created by Russell Wheatley on 23/04/2025.
2020
//
2121

22+
import FirebaseAppleSwiftUI
2223
import FirebaseAuth
2324
import FirebaseAuthSwiftUI
2425
import FirebaseFacebookSwiftUI
2526
import FirebaseGoogleSwiftUI
27+
import FirebaseOAuthSwiftUI
2628
import FirebasePhoneAuthSwiftUI
27-
import FirebaseAppleSwiftUI
2829
import FirebaseTwitterSwiftUI
29-
import FirebaseOAuthSwiftUI
3030
import SwiftUI
3131

3232
struct TestView: View {

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample/UITestUtils.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ public let testRunner = CommandLine.arguments.contains("--test-view-enabled")
1313
func signOut() throws {
1414
try Auth.auth().signOut()
1515
}
16-

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleTests/FirebaseSwiftUIExampleTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct FirebaseSwiftUIExampleTests {
101101
let service = try await prepareFreshAuthService()
102102

103103
#expect(service.authenticationState == .unauthenticated)
104-
#expect(service.authView == .authPicker)
104+
#expect(service.authView == nil)
105105
#expect(service.currentError == nil)
106106
#expect(service.currentUser == nil)
107107
try await service.createUser(email: createEmail(), password: kPassword)
@@ -115,7 +115,7 @@ struct FirebaseSwiftUIExampleTests {
115115
service.currentUser != nil
116116
}
117117
#expect(service.currentUser != nil)
118-
#expect(service.authView == .authPicker)
118+
#expect(service.authView == nil)
119119
#expect(service.currentError == nil)
120120
}
121121

@@ -136,7 +136,7 @@ struct FirebaseSwiftUIExampleTests {
136136
service.currentUser == nil
137137
}
138138
#expect(service.currentUser == nil)
139-
#expect(service.authView == .authPicker)
139+
#expect(service.authView == nil)
140140
#expect(service.currentError == nil)
141141

142142
try await service.signIn(email: email, password: kPassword)
@@ -150,7 +150,7 @@ struct FirebaseSwiftUIExampleTests {
150150
service.currentUser != nil
151151
}
152152
#expect(service.currentUser != nil)
153-
#expect(service.authView == .authPicker)
153+
#expect(service.authView == nil)
154154
#expect(service.currentError == nil)
155155
}
156156
}

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleUITests/FirebaseSwiftUIExampleUITests.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ final class FirebaseSwiftUIExampleUITests: XCTestCase {
4747
func testSignInDisplaysSignedInView() async throws {
4848
let email = createEmail()
4949
let password = "123456"
50-
50+
5151
// Create user in test runner BEFORE launching app
5252
// User will exist in emulator, but app starts unauthenticated
5353
try await createTestUser(email: email, password: password)
54-
54+
5555
// Now launch the app - it connects to emulator but isn't signed in
5656
let app = createTestApp()
5757
app.launch()
@@ -94,13 +94,14 @@ final class FirebaseSwiftUIExampleUITests: XCTestCase {
9494
let passwordRecoveryButton = app.buttons["password-recovery-button"]
9595
XCTAssertTrue(passwordRecoveryButton.exists, "Password recovery button should exist")
9696
passwordRecoveryButton.tap()
97-
let passwordRecoveryText = app.staticTexts["password-recovery-text"]
97+
let passwordRecoveryText = app.staticTexts["Send a password recovery link to your email"]
98+
.firstMatch
9899
XCTAssertTrue(
99100
passwordRecoveryText.waitForExistence(timeout: 10),
100101
"Password recovery text should exist after routing to PasswordRecoveryView"
101102
)
102103

103-
let passwordRecoveryBackButton = app.buttons["password-recovery-back-button"]
104+
let passwordRecoveryBackButton = app.navigationBars.buttons.element(boundBy: 0)
104105
XCTAssertTrue(passwordRecoveryBackButton.exists, "Password back button should exist")
105106
passwordRecoveryBackButton.tap()
106107

@@ -114,14 +115,14 @@ final class FirebaseSwiftUIExampleUITests: XCTestCase {
114115
XCTAssertTrue(emailLinkSignInButton.exists, "Email link sign-in button should exist")
115116
emailLinkSignInButton.tap()
116117

117-
let emailLinkText = app.staticTexts["email-link-title-text"]
118+
let emailLinkText = app.staticTexts["Send a sign-in link to your email"].firstMatch
118119

119120
XCTAssertTrue(
120121
emailLinkText.waitForExistence(timeout: 10),
121122
"Email link text should exist after pressing email link button in AuthPickerView"
122123
)
123124

124-
let emailLinkBackButton = app.buttons["email-link-back-button"]
125+
let emailLinkBackButton = app.navigationBars.buttons.element(boundBy: 0)
125126
XCTAssertTrue(emailLinkBackButton.exists, "Email link back button should exist")
126127
emailLinkBackButton.tap()
127128

@@ -176,10 +177,12 @@ final class FirebaseSwiftUIExampleUITests: XCTestCase {
176177

177178
// Wait for the auth screen to disappear (email field should no longer exist)
178179
let emailFieldDisappeared = NSPredicate(format: "exists == false")
179-
let expectation = XCTNSPredicateExpectation(predicate: emailFieldDisappeared, object: emailField)
180+
let expectation = XCTNSPredicateExpectation(
181+
predicate: emailFieldDisappeared,
182+
object: emailField
183+
)
180184
let result = XCTWaiter().wait(for: [expectation], timeout: 10.0)
181185
XCTAssertEqual(result, .completed, "Email field should disappear after sign-up")
182-
183186

184187
// Wait for user creation and signed-in view to appear
185188
let signedInText = app.staticTexts["signed-in-text"]

0 commit comments

Comments
 (0)