Skip to content

Commit 354f734

Browse files
Merge pull request #1300 from firebase/improve-tests
2 parents 4a52b73 + a0c9add commit 354f734

File tree

18 files changed

+96
-45
lines changed

18 files changed

+96
-45
lines changed

.github/workflows/swiftui-auth.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ permissions:
2424
contents: read
2525

2626
jobs:
27+
format-check:
28+
name: Swift Format Check
29+
runs-on: macos-26
30+
timeout-minutes: 10
31+
steps:
32+
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
33+
34+
- name: Install swiftformat
35+
run: brew install swiftformat
36+
37+
- name: Check Swift formatting
38+
run: bash lint-swift.sh
39+
2740
# Package Unit Tests (standalone, no emulator needed)
2841
unit-tests:
2942
name: Package Unit Tests
@@ -192,4 +205,4 @@ jobs:
192205
uses: actions/upload-artifact@v4
193206
with:
194207
name: FirebaseSwiftUIExampleUITests.xcresult
195-
path: e2eTest/FirebaseSwiftUIExample/FirebaseSwiftUIExampleUITests.xcresult
208+
path: e2eTest/FirebaseSwiftUIExample/FirebaseSwiftUIExampleUITests.xcresult

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/AuthPickerView.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public struct AuthPickerView<Content: View> {
3333
extension AuthPickerView: View {
3434
public var body: some View {
3535
@Bindable var authService = authService
36+
@Bindable var passwordPrompt = authService.passwordPrompt
3637
content()
3738
.sheet(isPresented: $authService.isPresented) {
3839
@Bindable var navigator = authService.navigator
@@ -79,6 +80,10 @@ extension AuthPickerView: View {
7980
// Apply MFA handling at NavigationStack level
8081
.mfaHandler()
8182
}
83+
// Centralized password prompt sheet to prevent conflicts
84+
.sheet(isPresented: $passwordPrompt.isPromptingPassword) {
85+
PasswordPromptSheet(coordinator: authService.passwordPrompt)
86+
}
8287
}
8388

8489
/// Closure for reporting errors from child views

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/EnterVerificationCodeView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct EnterVerificationCodeView: View {
106106
return NavigationStack {
107107
EnterVerificationCodeView(
108108
verificationID: "mock-id",
109-
fullPhoneNumber: "+1 5551234567",
109+
fullPhoneNumber: "+1 5551234567"
110110
)
111111
.environment(AuthService())
112112
}

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/MFAManagementView.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public struct MFAManagementView {
5757

5858
extension MFAManagementView: View {
5959
public var body: some View {
60-
@Bindable var passwordPrompt = authService.passwordPrompt
6160
VStack(spacing: 20) {
6261
// Title section
6362
VStack {
@@ -135,10 +134,7 @@ extension MFAManagementView: View {
135134
.onAppear {
136135
loadEnrolledFactors()
137136
}
138-
// Present password prompt when required for reauthentication
139-
.sheet(isPresented: $passwordPrompt.isPromptingPassword) {
140-
PasswordPromptSheet(coordinator: authService.passwordPrompt)
141-
}
137+
// Password prompt sheet now centralized in AuthPickerView
142138
}
143139

144140
@ViewBuilder

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/PrivacyTOCsView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct PrivacyTOCsView {
3030

3131
let displayMode: DisplayMode
3232

33-
public init(displayMode: DisplayMode = .full) {
33+
init(displayMode: DisplayMode = .full) {
3434
self.displayMode = displayMode
3535
}
3636

@@ -61,7 +61,7 @@ struct PrivacyTOCsView {
6161
}
6262

6363
extension PrivacyTOCsView: View {
64-
public var body: some View {
64+
var body: some View {
6565
Group {
6666
if let tosURL = authService.configuration.tosUrl,
6767
let privacyURL = authService.configuration.privacyPolicyUrl {

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/SignedInView.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public struct SignedInView {
3838

3939
extension SignedInView: View {
4040
public var body: some View {
41-
@Bindable var passwordPrompt = authService.passwordPrompt
4241
VStack {
4342
Text(authService.string.signedInTitle)
4443
.font(.largeTitle)
@@ -144,9 +143,7 @@ extension SignedInView: View {
144143
)
145144
.presentationDetents([.medium])
146145
}
147-
.sheet(isPresented: $passwordPrompt.isPromptingPassword) {
148-
PasswordPromptSheet(coordinator: authService.passwordPrompt)
149-
}
146+
// Password prompt sheet now centralized in AuthPickerView
150147
.sheet(isPresented: $showEmailVerificationSent) {
151148
VStack(spacing: 24) {
152149
Text(authService.string.verifyEmailSheetMessage)

FirebaseSwiftUI/FirebaseAuthSwiftUI/Tests/FirebaseAuthSwiftUITests/MFAEnrolmentUnitTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import Testing
2929
@Suite("TOTPEnrollmentInfo Tests")
3030
struct TOTPEnrollmentInfoTests {
3131
@Test("Initialization with shared secret key")
32-
func testInitializationWithSharedSecretKey() {
32+
func initializationWithSharedSecretKey() {
3333
let validSecrets = [
3434
"JBSWY3DPEHPK3PXP",
3535
"GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
@@ -47,7 +47,7 @@ struct TOTPEnrollmentInfoTests {
4747
}
4848

4949
@Test("Initialization with all parameters")
50-
func testInitializationWithAllParameters() throws {
50+
func initializationWithAllParameters() throws {
5151
let totpInfo = TOTPEnrollmentInfo(
5252
sharedSecretKey: "JBSWY3DPEHPK3PXP",
5353
qrCodeURL: URL(
@@ -71,7 +71,7 @@ struct TOTPEnrollmentInfoTests {
7171
}
7272

7373
@Test("Verification status transitions")
74-
func testVerificationStatusTransitions() {
74+
func verificationStatusTransitions() {
7575
// Default status is pending
7676
var totpInfo = TOTPEnrollmentInfo(sharedSecretKey: "JBSWY3DPEHPK3PXP")
7777
#expect(totpInfo.verificationStatus == .pending)

FirebaseSwiftUI/FirebaseAuthUIComponents/Sources/Components/AuthTextField.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public struct AuthTextField<Leading: View>: View {
2424
let prompt: String
2525
var textAlignment: TextAlignment = .leading
2626
var keyboardType: UIKeyboardType = .default
27-
var contentType: UITextContentType? = nil
27+
var contentType: UITextContentType?
2828
var isSecureTextField: Bool = false
2929
var validations: [FormValidator] = []
3030
var maintainsValidationMessage: Bool = false
31-
var formState: ((Bool) -> Void)? = nil
32-
var onSubmit: ((String) -> Void)? = nil
33-
var onChange: ((String) -> Void)? = nil
31+
var formState: ((Bool) -> Void)?
32+
var onSubmit: ((String) -> Void)?
33+
var onChange: ((String) -> Void)?
3434
private let leading: () -> Leading?
3535

3636
public init(text: Binding<String>,

FirebaseSwiftUI/FirebaseAuthUIComponents/Sources/Components/CountrySelector.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public struct CountryData: Equatable {
4444
public struct CountrySelector: View {
4545
@Binding var selectedCountry: CountryData
4646
var enabled: Bool = true
47-
var allowedCountries: Set<String>? = nil
47+
var allowedCountries: Set<String>?
4848

4949
public init(selectedCountry: Binding<CountryData>,
5050
enabled: Bool = true,

FirebaseSwiftUI/FirebaseAuthUIComponents/Sources/Components/VerificationCodeInputField.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public struct VerificationCodeInputField: View {
145145
commitCodeChange(truncated)
146146
}
147147

148-
if shouldUpdateFocus && (fieldsChanged || forceFocus) {
148+
if shouldUpdateFocus, fieldsChanged || forceFocus {
149149
let newFocus = truncated.count < codeLength ? truncated.count : nil
150150
DispatchQueue.main.async {
151151
withAnimation(.easeInOut(duration: 0.2)) {
@@ -154,7 +154,7 @@ public struct VerificationCodeInputField: View {
154154
}
155155
}
156156

157-
if fieldsChanged && truncated.count == codeLength {
157+
if fieldsChanged, truncated.count == codeLength {
158158
DispatchQueue.main.async {
159159
onCodeComplete(truncated)
160160
}
@@ -198,8 +198,7 @@ public struct VerificationCodeInputField: View {
198198
commitCodeChange(newCode)
199199
onCodeChange(newCode)
200200

201-
if !digit.isEmpty,
202-
let nextIndex = findNextEmptyField(startingFrom: index) {
201+
if !digit.isEmpty, let nextIndex = findNextEmptyField(startingFrom: index) {
203202
DispatchQueue.main.async {
204203
if focusedIndex != nextIndex {
205204
withAnimation(.easeInOut(duration: 0.2)) {
@@ -218,7 +217,7 @@ public struct VerificationCodeInputField: View {
218217

219218
private func handleBackspace(at index: Int) {
220219
// If current field is empty, move to previous field and clear it
221-
if digitFields[index].isEmpty && index > 0 {
220+
if digitFields[index].isEmpty, index > 0 {
222221
digitFields[index - 1] = ""
223222
DispatchQueue.main.async {
224223
let previousIndex = index - 1

0 commit comments

Comments
 (0)