Skip to content

Commit 947f2d1

Browse files
test: show email/password upgrades when anonymous user is signed in
1 parent 46cfaaa commit 947f2d1

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample/TestView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ struct TestView: View {
3434

3535
init() {
3636
Auth.auth().useEmulator(withHost: "localhost", port: 9099)
37+
3738
Auth.auth().settings?.isAppVerificationDisabledForTesting = true
3839
Task {
3940
try signOut()
4041
}
42+
if anonymousSignInEnabled {
43+
Auth.auth().signInAnonymously()
44+
}
4145

4246
let isMfaEnabled = ProcessInfo.processInfo.arguments.contains("--mfa-enabled")
4347

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample/UITestUtils.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import SwiftUI
1010
// UI Test Runner keys
1111
public let testRunner = CommandLine.arguments.contains("--test-view-enabled")
1212

13+
public let anonymousSignInEnabled = CommandLine.arguments.contains("--anonymous-sign-in-enabled")
14+
1315
func signOut() throws {
1416
try Auth.auth().signOut()
1517
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
// UpgradeAccountUITests.swift
17+
// UpgradeAccountUITests
18+
//
19+
// Created by Russell Wheatley on 05/11/2025.
20+
//
21+
22+
import XCTest
23+
24+
final class UpgradeAccountUITests: XCTestCase {
25+
override func setUpWithError() throws {
26+
continueAfterFailure = false
27+
}
28+
29+
override func tearDownWithError() throws {}
30+
31+
@MainActor
32+
func testUpgradeAnonymousAccountWithEmailPassword() async throws {
33+
// Create a test user first
34+
let email = createEmail()
35+
let password = "123456"
36+
try await createTestUser(email: email, password: password)
37+
38+
// Launch app with anonymous sign-in enabled
39+
let app = createTestApp()
40+
app.launchArguments.append("--anonymous-sign-in-enabled")
41+
app.launch()
42+
43+
// Wait for sign-in screen to appear
44+
let emailField = app.textFields["email-field"]
45+
XCTAssertTrue(emailField.waitForExistence(timeout: 6), "Email field should exist")
46+
emailField.tap()
47+
emailField.typeText(email)
48+
49+
let passwordField = app.secureTextFields["password-field"]
50+
XCTAssertTrue(passwordField.exists, "Password field should exist")
51+
passwordField.tap()
52+
passwordField.typeText(password)
53+
54+
let signInButton = app.buttons["sign-in-button"]
55+
XCTAssertTrue(signInButton.exists, "Sign-In button should exist")
56+
signInButton.tap()
57+
58+
let signedInText = app.staticTexts["signed-in-text"]
59+
60+
// Wait for authentication to complete and signed-in view to appear
61+
XCTAssertTrue(
62+
signedInText.waitForExistence(timeout: 30),
63+
"SignedInView should be visible after signing in with email/password"
64+
)
65+
}
66+
}

0 commit comments

Comments
 (0)