Skip to content

Commit 2977922

Browse files
test: error modal pops up for email + FB sign-in failure/cancel
1 parent 8a9019b commit 2977922

File tree

2 files changed

+151
-62
lines changed

2 files changed

+151
-62
lines changed

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleUITests/FirebaseSwiftUIExampleUITests.swift

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -43,68 +43,6 @@ final class FirebaseSwiftUIExampleUITests: XCTestCase {
4343
}
4444
}
4545

46-
@MainActor
47-
func testSignInButtonsExist() throws {
48-
let app = createTestApp()
49-
app.launch()
50-
51-
// Check for Twitter/X sign-in button
52-
let twitterButton = app.buttons["sign-in-with-twitter-button"]
53-
XCTAssertTrue(
54-
twitterButton.waitForExistence(timeout: 5),
55-
"Twitter/X sign-in button should exist"
56-
)
57-
58-
// Check for Apple sign-in button
59-
let appleButton = app.buttons["sign-in-with-apple-button"]
60-
XCTAssertTrue(
61-
appleButton.waitForExistence(timeout: 5),
62-
"Apple sign-in button should exist"
63-
)
64-
65-
// Check for Github sign-in button
66-
let githubButton = app.buttons["sign-in-with-github.com-button"]
67-
XCTAssertTrue(
68-
githubButton.waitForExistence(timeout: 5),
69-
"Github sign-in button should exist"
70-
)
71-
72-
// Check for Microsoft sign-in button
73-
let microsoftButton = app.buttons["sign-in-with-microsoft.com-button"]
74-
XCTAssertTrue(
75-
microsoftButton.waitForExistence(timeout: 5),
76-
"Microsoft sign-in button should exist"
77-
)
78-
79-
// Check for Yahoo sign-in button
80-
let yahooButton = app.buttons["sign-in-with-yahoo.com-button"]
81-
XCTAssertTrue(
82-
yahooButton.waitForExistence(timeout: 5),
83-
"Yahoo sign-in button should exist"
84-
)
85-
86-
// Check for Google sign-in button
87-
let googleButton = app.buttons["sign-in-with-google-button"]
88-
XCTAssertTrue(
89-
googleButton.waitForExistence(timeout: 5),
90-
"Google sign-in button should exist"
91-
)
92-
93-
// Check for Facebook sign-in button
94-
let facebookButton = app.buttons["sign-in-with-facebook-button"]
95-
XCTAssertTrue(
96-
facebookButton.waitForExistence(timeout: 5),
97-
"Facebook sign-in button should exist"
98-
)
99-
100-
// Check for Phone sign-in button
101-
let phoneButton = app.buttons["sign-in-with-phone-button"]
102-
XCTAssertTrue(
103-
phoneButton.waitForExistence(timeout: 5),
104-
"Phone sign-in button should exist"
105-
)
106-
}
107-
10846
@MainActor
10947
func testSignInDisplaysSignedInView() async throws {
11048
let email = createEmail()
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//
16+
// FirebaseSwiftUIExampleUITests.swift
17+
// FirebaseSwiftUIExampleUITests
18+
//
19+
// Created by Russell Wheatley on 18/02/2025.
20+
//
21+
22+
import XCTest
23+
24+
final class ProviderUITests: XCTestCase {
25+
override func setUpWithError() throws {
26+
continueAfterFailure = false
27+
}
28+
29+
override func tearDownWithError() throws {}
30+
31+
@MainActor
32+
func testProviderButtons() throws {
33+
let app = createTestApp()
34+
app.launch()
35+
36+
// MARK: - Check existence of provider buttons
37+
38+
// Check for Twitter/X sign-in button
39+
let twitterButton = app.buttons["sign-in-with-twitter-button"]
40+
XCTAssertTrue(
41+
twitterButton.waitForExistence(timeout: 5),
42+
"Twitter/X sign-in button should exist"
43+
)
44+
45+
// Check for Apple sign-in button
46+
let appleButton = app.buttons["sign-in-with-apple-button"]
47+
XCTAssertTrue(
48+
appleButton.waitForExistence(timeout: 5),
49+
"Apple sign-in button should exist"
50+
)
51+
52+
// Check for Github sign-in button
53+
let githubButton = app.buttons["sign-in-with-github.com-button"]
54+
XCTAssertTrue(
55+
githubButton.waitForExistence(timeout: 5),
56+
"Github sign-in button should exist"
57+
)
58+
59+
// Check for Microsoft sign-in button
60+
let microsoftButton = app.buttons["sign-in-with-microsoft.com-button"]
61+
XCTAssertTrue(
62+
microsoftButton.waitForExistence(timeout: 5),
63+
"Microsoft sign-in button should exist"
64+
)
65+
66+
// Check for Yahoo sign-in button
67+
let yahooButton = app.buttons["sign-in-with-yahoo.com-button"]
68+
XCTAssertTrue(
69+
yahooButton.waitForExistence(timeout: 5),
70+
"Yahoo sign-in button should exist"
71+
)
72+
73+
// Check for Google sign-in button
74+
let googleButton = app.buttons["sign-in-with-google-button"]
75+
XCTAssertTrue(
76+
googleButton.waitForExistence(timeout: 5),
77+
"Google sign-in button should exist"
78+
)
79+
80+
// Check for Facebook sign-in button
81+
let facebookButton = app.buttons["sign-in-with-facebook-button"]
82+
XCTAssertTrue(
83+
facebookButton.waitForExistence(timeout: 5),
84+
"Facebook sign-in button should exist"
85+
)
86+
87+
// Check for Phone sign-in button
88+
let phoneButton = app.buttons["sign-in-with-phone-button"]
89+
XCTAssertTrue(
90+
phoneButton.waitForExistence(timeout: 5),
91+
"Phone sign-in button should exist"
92+
)
93+
}
94+
95+
@MainActor
96+
func testErrorModal() throws {
97+
let app = createTestApp()
98+
app.launch()
99+
// Just test email + external provider for error modal on failure to ensure provider button sign-in flow fails along with failures within AuthPickerView
100+
let emailField = app.textFields["email-field"]
101+
XCTAssertTrue(emailField.waitForExistence(timeout: 6), "Email field should exist")
102+
emailField.tap()
103+
emailField.typeText("fake-email@example.com")
104+
105+
let passwordField = app.secureTextFields["password-field"]
106+
XCTAssertTrue(passwordField.exists, "Password field should exist")
107+
passwordField.tap()
108+
passwordField.typeText("12345678")
109+
110+
let signInButton = app.buttons["sign-in-button"]
111+
XCTAssertTrue(signInButton.exists, "Sign-In button should exist")
112+
signInButton.tap()
113+
114+
// Wait for the alert to appear
115+
let alert1 = app.alerts.firstMatch
116+
XCTAssertTrue(
117+
alert1.waitForExistence(timeout: 5),
118+
"Alert should appear after canceling Facebook sign-in"
119+
)
120+
121+
alert1.buttons["OK"].firstMatch.tap()
122+
123+
124+
let facebookButton = app.buttons["sign-in-with-facebook-button"]
125+
XCTAssertTrue(
126+
facebookButton.waitForExistence(timeout: 5),
127+
"Facebook sign-in button should exist"
128+
)
129+
130+
facebookButton.tap()
131+
132+
// Wait for Facebook modal to appear and tap Cancel
133+
// The Facebook SDK modal is presented by the system/Safari
134+
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
135+
136+
// Access the Cancel button from Springboard
137+
let cancelButton = springboard.buttons["Cancel"]
138+
XCTAssertTrue(
139+
cancelButton.waitForExistence(timeout: 10),
140+
"Cancel button should appear in Springboard authentication modal"
141+
)
142+
cancelButton.tap()
143+
144+
// Wait for the alert to appear
145+
let alert2 = app.alerts.firstMatch
146+
XCTAssertTrue(
147+
alert2.waitForExistence(timeout: 5),
148+
"Alert should appear after canceling Facebook sign-in"
149+
)
150+
}
151+
}

0 commit comments

Comments
 (0)