Skip to content

Commit ba6d0bc

Browse files
test: further UI View tests
1 parent 03d50d1 commit ba6d0bc

File tree

6 files changed

+107
-43
lines changed

6 files changed

+107
-43
lines changed

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/AuthPickerView.swift

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,48 @@ public struct AuthPickerView {
1616
extension AuthPickerView: View {
1717
public var body: some View {
1818
VStack {
19-
Text(authService.string.authPickerTitle)
20-
.font(.largeTitle)
21-
.fontWeight(.bold)
22-
.padding()
23-
if authService.authenticationState == .authenticated {
24-
SignedInView()
25-
} else if authService.authView == .passwordRecovery {
26-
PasswordRecoveryView()
27-
} else if authService.authView == .emailLink {
28-
EmailLinkView()
29-
} else {
30-
if authService.emailSignInEnabled {
31-
Text(authService.authenticationFlow == .login ? authService.string
32-
.emailLoginFlowLabel : authService.string.emailSignUpFlowLabel)
33-
Divider()
34-
EmailAuthView()
35-
}
36-
VStack {
37-
authService.renderButtons()
38-
}.padding(.horizontal)
39-
if authService.emailSignInEnabled {
40-
Divider()
41-
HStack {
42-
Text(authService
43-
.authenticationFlow == .login ? authService.string.dontHaveAnAccountYetLabel :
44-
authService.string.alreadyHaveAnAccountLabel)
45-
Button(action: {
46-
withAnimation {
47-
switchFlow()
48-
}
49-
}) {
50-
Text(authService.authenticationFlow == .signUp ? authService.string
51-
.emailLoginFlowLabel : authService.string.emailSignUpFlowLabel)
52-
.fontWeight(.semibold)
53-
.foregroundColor(.blue)
54-
}.accessibilityIdentifier("switch-auth-flow")
19+
ScrollView {
20+
Text(authService.string.authPickerTitle)
21+
.font(.largeTitle)
22+
.fontWeight(.bold)
23+
.padding()
24+
if authService.authenticationState == .authenticated {
25+
SignedInView()
26+
} else if authService.authView == .passwordRecovery {
27+
PasswordRecoveryView()
28+
} else if authService.authView == .emailLink {
29+
EmailLinkView()
30+
} else {
31+
if authService.emailSignInEnabled {
32+
Text(authService.authenticationFlow == .login ? authService.string
33+
.emailLoginFlowLabel : authService.string.emailSignUpFlowLabel)
34+
Divider()
35+
EmailAuthView()
36+
}
37+
VStack {
38+
authService.renderButtons()
39+
}.padding(.horizontal)
40+
if authService.emailSignInEnabled {
41+
Divider()
42+
HStack {
43+
Text(authService
44+
.authenticationFlow == .login ? authService.string.dontHaveAnAccountYetLabel :
45+
authService.string.alreadyHaveAnAccountLabel)
46+
Button(action: {
47+
withAnimation {
48+
switchFlow()
49+
}
50+
}) {
51+
Text(authService.authenticationFlow == .signUp ? authService.string
52+
.emailLoginFlowLabel : authService.string.emailSignUpFlowLabel)
53+
.fontWeight(.semibold)
54+
.foregroundColor(.blue)
55+
}.accessibilityIdentifier("switch-auth-flow")
56+
}
5557
}
58+
PrivacyTOCsView(displayMode: .footer)
59+
Text(authService.errorMessage).foregroundColor(.red)
5660
}
57-
PrivacyTOCsView(displayMode: .footer)
58-
Text(authService.errorMessage).foregroundColor(.red)
5961
}
6062
}
6163
}

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/EmailAuthView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ extension EmailAuthView: View {
8989
authService.authView = .passwordRecovery
9090
}) {
9191
Text(authService.string.passwordButtonLabel)
92-
}
92+
}.accessibilityIdentifier("password-recovery-button")
9393
}
9494

9595
if authService.authenticationFlow == .signUp {
@@ -138,7 +138,7 @@ extension EmailAuthView: View {
138138
authService.authView = .emailLink
139139
}) {
140140
Text(authService.string.signUpWithEmailLinkButtonLabel)
141-
}
141+
}.accessibilityIdentifier("sign-in-with-email-link-button")
142142
}
143143
}
144144
}

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/EmailLinkView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extension EmailLinkView: View {
2121
public var body: some View {
2222
VStack {
2323
Text(authService.string.signInWithEmailLinkViewTitle)
24+
.accessibilityIdentifier("email-link-title-text")
2425
LabeledContent {
2526
TextField(authService.string.emailInputLabel, text: $email)
2627
.textInputAutocapitalization(.never)
@@ -70,7 +71,7 @@ extension EmailLinkView: View {
7071
.foregroundColor(.blue)
7172
Text(authService.string.backButtonLabel)
7273
.foregroundColor(.blue)
73-
})
74+
}.accessibilityIdentifier("email-link-back-button"))
7475
}
7576
}
7677

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/PasswordRecoveryView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extension PasswordRecoveryView: View {
2323
.font(.largeTitle)
2424
.fontWeight(.bold)
2525
.padding()
26+
.accessibilityIdentifier("password-recovery-text")
2627

2728
Divider()
2829

@@ -78,7 +79,7 @@ extension PasswordRecoveryView: View {
7879
.foregroundColor(.blue)
7980
Text(authService.string.backButtonLabel)
8081
.foregroundColor(.blue)
81-
})
82+
}.accessibilityIdentifier("password-recovery-back-button"))
8283
}
8384
}
8485

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/SignedInView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension SignedInView: View {
4141
try await authService.signOut()
4242
} catch {}
4343
}
44-
}
44+
}.accessibilityIdentifier("sign-out-button")
4545
Divider()
4646
Button(authService.string.deleteAccountButtonLabel) {
4747
Task {

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleUITests/FirebaseSwiftUIExampleUITests.swift

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ func createEmail() -> String {
1515
return "\(before)@\(after).com"
1616
}
1717

18+
func dismissAlert(app: XCUIApplication) {
19+
if app.scrollViews.otherElements.buttons["Not Now"].waitForExistence(timeout: 2) {
20+
app.scrollViews.otherElements.buttons["Not Now"].tap()
21+
}
22+
}
23+
1824
final class FirebaseSwiftUIExampleUITests: XCTestCase {
1925
override func setUpWithError() throws {
2026
continueAfterFailure = false
@@ -65,6 +71,60 @@ final class FirebaseSwiftUIExampleUITests: XCTestCase {
6571
signedInText.waitForExistence(timeout: 10),
6672
"SignedInView should be visible after login"
6773
)
74+
75+
dismissAlert(app: app)
76+
// Check the Views are updated
77+
let signOutButton = app.buttons["sign-out-button"]
78+
XCTAssertTrue(
79+
signOutButton.waitForExistence(timeout: 10),
80+
"Sign-Out button should exist and be visible"
81+
)
82+
83+
signOutButton.tap()
84+
XCTAssertTrue(
85+
signInButton.waitForExistence(timeout: 10),
86+
"Sign-In button should exist after logout"
87+
)
88+
89+
let passwordRecoveryButton = app.buttons["password-recovery-button"]
90+
XCTAssertTrue(passwordRecoveryButton.exists, "Password recovery button should exist")
91+
passwordRecoveryButton.tap()
92+
let passwordRecoveryText = app.staticTexts["password-recovery-text"]
93+
XCTAssertTrue(
94+
passwordRecoveryText.waitForExistence(timeout: 10),
95+
"Password recovery text should exist after routing to PasswordRecoveryView"
96+
)
97+
98+
let passwordRecoveryBackButton = app.buttons["password-recovery-back-button"]
99+
XCTAssertTrue(passwordRecoveryBackButton.exists, "Password back button should exist")
100+
passwordRecoveryBackButton.tap()
101+
102+
let signInButton2 = app.buttons["sign-in-button"]
103+
XCTAssertTrue(
104+
signInButton2.waitForExistence(timeout: 10),
105+
"Sign-In button should exist after pressing password recovery back button"
106+
)
107+
108+
let emailLinkSignInButton = app.buttons["sign-in-with-email-link-button"]
109+
XCTAssertTrue(emailLinkSignInButton.exists, "Email link sign-in button should exist")
110+
emailLinkSignInButton.tap()
111+
112+
let emailLinkText = app.staticTexts["email-link-title-text"]
113+
114+
XCTAssertTrue(
115+
emailLinkText.waitForExistence(timeout: 10),
116+
"Email link text should exist after pressing email link button in AuthPickerView"
117+
)
118+
119+
let emailLinkBackButton = app.buttons["email-link-back-button"]
120+
XCTAssertTrue(emailLinkBackButton.exists, "Email link back button should exist")
121+
emailLinkBackButton.tap()
122+
123+
let signInButton3 = app.buttons["sign-in-button"]
124+
XCTAssertTrue(
125+
signInButton3.waitForExistence(timeout: 10),
126+
"Sign-In button should exist after pressing password recovery back button"
127+
)
68128
}
69129

70130
@MainActor

0 commit comments

Comments
 (0)