-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Version 10.0.0 beta04 #2384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
demolaf
wants to merge
1
commit into
master
Choose a base branch
from
version-10.0.0-beta04
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Version 10.0.0 beta04 #2384
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
auth/src/test/java/com/firebase/ui/auth/ui/screens/email/SignUpUITest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| * Copyright 2025 Google Inc. All Rights Reserved. | ||
| * | ||
| * 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. | ||
| */ | ||
|
|
||
| package com.firebase.ui.auth.ui.screens.email | ||
|
|
||
| import android.content.Context | ||
| import androidx.compose.runtime.CompositionLocalProvider | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.test.assertIsEnabled | ||
| import androidx.compose.ui.test.hasClickAction | ||
| import androidx.compose.ui.test.hasText | ||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import androidx.compose.ui.test.onNodeWithText | ||
| import androidx.compose.ui.test.performTextInput | ||
| import androidx.test.core.app.ApplicationProvider | ||
| import com.firebase.ui.auth.configuration.authUIConfiguration | ||
| import com.firebase.ui.auth.configuration.auth_provider.AuthProvider | ||
| import com.firebase.ui.auth.configuration.string_provider.AuthUIStringProvider | ||
| import com.firebase.ui.auth.configuration.string_provider.DefaultAuthUIStringProvider | ||
| import com.firebase.ui.auth.configuration.string_provider.LocalAuthUIStringProvider | ||
| import org.junit.Before | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.RobolectricTestRunner | ||
| import org.robolectric.annotation.Config | ||
|
|
||
| /** | ||
| * Unit tests for [SignUpUI], covering form validity logic. | ||
| * | ||
| * @suppress Internal test class | ||
| */ | ||
| @Config(sdk = [34]) | ||
| @RunWith(RobolectricTestRunner::class) | ||
| class SignUpUITest { | ||
|
|
||
| @get:Rule | ||
| val composeTestRule = createComposeRule() | ||
|
|
||
| private lateinit var applicationContext: Context | ||
| private lateinit var stringProvider: AuthUIStringProvider | ||
|
|
||
| @Before | ||
| fun setUp() { | ||
| applicationContext = ApplicationProvider.getApplicationContext() | ||
| stringProvider = DefaultAuthUIStringProvider(applicationContext) | ||
| } | ||
|
|
||
| @Test | ||
| fun `sign up button becomes enabled when display name is not required and hidden`() { | ||
| val provider = AuthProvider.Email( | ||
| isDisplayNameRequired = false, | ||
| emailLinkActionCodeSettings = null, | ||
| passwordValidationRules = emptyList() | ||
| ) | ||
| val configuration = authUIConfiguration { | ||
| context = applicationContext | ||
| providers { provider(provider) } | ||
| } | ||
|
|
||
| composeTestRule.setContent { | ||
| CompositionLocalProvider(LocalAuthUIStringProvider provides stringProvider) { | ||
| var email by remember { mutableStateOf("") } | ||
| var password by remember { mutableStateOf("") } | ||
| var confirmPassword by remember { mutableStateOf("") } | ||
|
|
||
| SignUpUI( | ||
| configuration = configuration, | ||
| isLoading = false, | ||
| displayName = "", | ||
| email = email, | ||
| password = password, | ||
| confirmPassword = confirmPassword, | ||
| onDisplayNameChange = { }, | ||
| onEmailChange = { email = it }, | ||
| onPasswordChange = { password = it }, | ||
| onConfirmPasswordChange = { confirmPassword = it }, | ||
| onGoToSignIn = { }, | ||
| onSignUpClick = { } | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| // Name field should not be rendered since it isn't required. | ||
| composeTestRule.onNodeWithText(stringProvider.nameHint).assertDoesNotExist() | ||
|
|
||
| composeTestRule.onNodeWithText(stringProvider.emailHint) | ||
| .performTextInput("test@example.com") | ||
| composeTestRule.onNodeWithText(stringProvider.passwordHint) | ||
| .performTextInput("Password123") | ||
| composeTestRule.onNodeWithText(stringProvider.confirmPasswordHint) | ||
| .performTextInput("Password123") | ||
|
|
||
| composeTestRule.waitForIdle() | ||
|
|
||
| // With email/password/confirmPassword all valid and no display name required, | ||
| // the sign up button should be enabled even though displayName is still "". | ||
| composeTestRule.onNode(hasText(stringProvider.signupPageTitle.uppercase()) and hasClickAction()) | ||
| .assertIsEnabled() | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary
derivedStateOfand Side-Effects during CompositionThere are two main issues with the current implementation of
isFormValid:derivedStateOfAnti-Pattern:derivedStateOfis designed to derive state from other ComposeStateobjects (likeMutableState). Here, the inputs (displayName,email,password,confirmPassword) are plainStringparameters, not ComposeStates. Because they are plain values, Compose cannot track them inside thederivedStateOfblock. To make it work, they are passed as keys toremember. However, when any of these keys change, the entirerememberblock is re-executed, creating a brand newderivedStateOfinstance on every keystroke. This completely defeats the purpose ofderivedStateOfand adds unnecessary allocation and registration overhead.Side-Effects during Composition:
Inside the
derivedStateOfblock,validate()is called on the validators (e.g.,displayNameValidator.validate(displayName)). Thevalidate()function is not pure; it mutates the internal state (_validationStatus) of the validator. Running side-effects inside a composition/calculation block is highly discouraged in Compose as it can lead to inconsistent UI states or unexpected behavior.Recommended Solution
Simplify
isFormValidto a plainBooleanusingrememberwith keys, and update its usage in theButtonto remove.value: