Skip to content

Commit dfdbf44

Browse files
test: fix more tests after UI refactor
1 parent eb6291a commit dfdbf44

File tree

3 files changed

+28
-42
lines changed

3 files changed

+28
-42
lines changed

FirebaseSwiftUI/FirebaseAuthUIComponents/Sources/Components/CountrySelector.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public struct CountrySelector: View {
8888
} label: {
8989
Text("\(country.flag) \(country.name) (\(country.dialCode))")
9090
}
91+
.accessibilityIdentifier("country-option-\(country.code)")
9192
}
9293
} label: {
9394
HStack(spacing: 4) {
@@ -101,6 +102,7 @@ public struct CountrySelector: View {
101102
.foregroundStyle(.secondary)
102103
}
103104
}
105+
.accessibilityIdentifier("country-selector")
104106
.disabled(!enabled)
105107
}
106108
}

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleUITests/MFAEnrolmentUITests.swift

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,24 @@ final class MFAEnrollmentUITests: XCTestCase {
193193
XCTAssertTrue(startButton.waitForExistence(timeout: 10))
194194
startButton.tap()
195195

196-
// 6) Enter phone number and display name, then press "Send Code"
196+
// 6) Select UK country code and enter phone number (without dial code)
197+
// Find and tap the country selector - try multiple approaches since it's embedded in the TextField
198+
let countrySelector = app.buttons["🇺🇸 +1"]
199+
XCTAssertTrue(countrySelector.waitForExistence(timeout: 5))
200+
201+
countrySelector.tap()
202+
203+
// Select United Kingdom (+44) - try multiple element types
204+
let ukOption = app.buttons["country-option-GB"]
205+
XCTAssertTrue(ukOption.waitForExistence(timeout: 5))
206+
207+
ukOption.tap()
208+
209+
// Enter phone number (without dial code)
197210
let phoneField = app.textFields["phone-number-field"]
198211
XCTAssertTrue(phoneField.waitForExistence(timeout: 10))
199-
let phoneNumber = "+447444555666"
200-
UIPasteboard.general.string = phoneNumber
212+
let phoneNumberWithoutDialCode = "7444555666"
213+
UIPasteboard.general.string = phoneNumberWithoutDialCode
201214
phoneField.tap()
202215
phoneField.press(forDuration: 1.2)
203216
app.menuItems["Paste"].tap()
@@ -219,7 +232,9 @@ final class MFAEnrollmentUITests: XCTestCase {
219232
XCTAssertTrue(verificationCodeField.waitForExistence(timeout: 15))
220233

221234
// Fetch the latest SMS verification code generated by the emulator for this phone number
222-
let code = try await getLastSmsCode(specificPhone: phoneNumber)
235+
// The emulator stores the full phone number with dial code
236+
let fullPhoneNumber = "+44\(phoneNumberWithoutDialCode)"
237+
let code = try await getLastSmsCode(specificPhone: fullPhoneNumber)
223238

224239
UIPasteboard.general.string = code
225240
verificationCodeField.tap()
@@ -356,48 +371,17 @@ final class MFAEnrollmentUITests: XCTestCase {
356371
try navigateToMFAEnrollment(app: app)
357372

358373
// Test back button exists
359-
let cancelButton = app.buttons["mfa-back-button"]
360-
XCTAssertTrue(cancelButton.exists, "Back button should exist")
361-
XCTAssertTrue(cancelButton.isEnabled, "Back button should be enabled")
374+
let backButton = app.navigationBars.buttons.element(boundBy: 0)
375+
XCTAssertTrue(backButton.exists, "Back button should exist")
362376

363377
// Tap cancel button
364-
cancelButton.tap()
365-
366-
// Should navigate back to signed in view
367-
let signedInText = app.staticTexts["signed-in-text"]
368-
XCTAssertTrue(
369-
signedInText.waitForExistence(timeout: 5),
370-
"Should navigate back to signed in view"
371-
)
372-
}
373-
374-
@MainActor
375-
func testBackButtonFromMFAManagement() async throws {
376-
let email = createEmail()
377-
378-
// Create user in test runner before launching app
379-
try await createTestUser(email: email)
380-
381-
let app = createTestApp(mfaEnabled: true)
382-
app.launch()
383-
384-
// Sign in and navigate to MFA management
385-
try signInToApp(app: app, email: email)
386-
app.buttons["mfa-management-button"].tap()
387-
388-
// Test back button exists
389-
let backButton = app.buttons["back-button"]
390-
XCTAssertTrue(backButton.waitForExistence(timeout: 5), "Back button should exist")
391-
XCTAssertTrue(backButton.isEnabled, "Back button should be enabled")
392-
393-
// Tap back button
394378
backButton.tap()
395379

396-
// Should navigate back to signed in view
397-
let signedInText = app.staticTexts["signed-in-text"]
380+
// Should navigate back to manage MFA View
381+
let signedInText = app.buttons["setup-mfa-button"]
398382
XCTAssertTrue(
399383
signedInText.waitForExistence(timeout: 5),
400-
"Should navigate back to signed in view"
384+
"Should navigate back to setup MFA view"
401385
)
402386
}
403387

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleUITests/MFAResolutionUITests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ final class MFAResolutionUITests: XCTestCase {
417417
}
418418
}
419419

420-
private func signInUser(app: XCUIApplication, email: String, password: String = "123456") throws {
420+
@MainActor private func signInUser(app: XCUIApplication, email: String, password: String = "123456") throws {
421421
// Ensure we're in sign in flow
422422
let switchFlowButton = app.buttons["switch-auth-flow"]
423423
if switchFlowButton.exists && switchFlowButton.label.contains("Sign In") {
@@ -440,7 +440,7 @@ final class MFAResolutionUITests: XCTestCase {
440440
signInButton.tap()
441441
}
442442

443-
private func enrollSMSMFA(app: XCUIApplication) throws {
443+
@MainActor private func enrollSMSMFA(app: XCUIApplication) throws {
444444
// Navigate to MFA management
445445
let mfaManagementButton = app.buttons["mfa-management-button"]
446446
XCTAssertTrue(mfaManagementButton.waitForExistence(timeout: 5))

0 commit comments

Comments
 (0)