Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public struct SignedInView {
@State private var showEmailVerificationSent = false
@State private var reauthCoordinator = ReauthenticationCoordinator()

private var showsMfaManagementButton: Bool {
Self.showsMfaManagementButton(configuration: authService.configuration)
}

static func showsMfaManagementButton(configuration: AuthConfiguration) -> Bool {
configuration.mfaEnabled
}

private func sendEmailVerification() async throws {
do {
try await authService.sendEmailVerification()
Expand Down Expand Up @@ -75,17 +83,19 @@ extension SignedInView: View {
.frame(maxWidth: .infinity)
.accessibilityIdentifier("update-password-button")

Button {
authService.navigator.push(.mfaManagement)
} label: {
Text(authService.string.manageTwoFactorAuthenticationLabel)
.padding(.vertical, 8)
.frame(maxWidth: .infinity)
if showsMfaManagementButton {
Button {
authService.navigator.push(.mfaManagement)
} label: {
Text(authService.string.manageTwoFactorAuthenticationLabel)
.padding(.vertical, 8)
.frame(maxWidth: .infinity)
}
.buttonStyle(.borderedProminent)
.padding([.top, .bottom], 8)
.frame(maxWidth: .infinity)
.accessibilityIdentifier("mfa-management-button")
}
.buttonStyle(.borderedProminent)
.padding([.top, .bottom], 8)
.frame(maxWidth: .infinity)
.accessibilityIdentifier("mfa-management-button")

Button {
showDeleteConfirmation = true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

@testable import FirebaseAuthSwiftUI
import Testing

@Suite("SignedInView Tests")
struct SignedInViewTests {
@Test("MFA management button is hidden when MFA is disabled")
func mfaManagementButtonHiddenWhenMfaDisabled() {
let configuration = AuthConfiguration(mfaEnabled: false)

#expect(SignedInView.showsMfaManagementButton(configuration: configuration) == false)
}

@Test("MFA management button is shown when MFA is enabled")
func mfaManagementButtonShownWhenMfaEnabled() {
let configuration = AuthConfiguration(mfaEnabled: true)

#expect(SignedInView.showsMfaManagementButton(configuration: configuration) == true)
}
Comment on lines +20 to +32
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The PR description mentions adding a UI test, but the implementation provides unit tests for a helper method. While testing the logic is a good practice, these tests do not verify that the button is actually hidden or shown in the view hierarchy. Consider adding a UI test or a view-level test (e.g., using ViewInspector) to verify the actual presence of the mfa-management-button based on the configuration.

}