|
| 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