-
Notifications
You must be signed in to change notification settings - Fork 0
feat(mobile): onboarding and Firebase authentication #43
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fefd49c
feat(mobile): onboarding and Firebase authentication (closes #37)
GRACENOBLE 079668d
feat(mobile): add Google Sign-In button to LoginScreen
GRACENOBLE 006f504
fix(mobile): resolve Google Sign-In web client ID from google-service…
GRACENOBLE 927650d
fix(mobile): switch from GetGoogleIdOption to GetSignInWithGoogleOption
GRACENOBLE 2ed6425
fix(mobile): address CodeRabbit review findings on PR #43
GRACENOBLE 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
117 changes: 117 additions & 0 deletions
117
mobile/app/src/androidTest/java/com/company/template/auth/LoginScreenTest.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,117 @@ | ||
| package com.company.template.auth | ||
|
|
||
| import androidx.compose.ui.test.assertIsDisplayed | ||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import androidx.compose.ui.test.onNodeWithTag | ||
| import androidx.compose.ui.test.onNodeWithText | ||
| import androidx.compose.ui.test.performClick | ||
| import androidx.compose.ui.test.performTextInput | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import com.company.template.ui.theme.TemplateTheme | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class LoginScreenTest { | ||
|
|
||
| @get:Rule | ||
| val composeTestRule = createComposeRule() | ||
|
|
||
| private var capturedEmail = "" | ||
| private var capturedPassword = "" | ||
|
|
||
| private fun setContent( | ||
| loginForm: LoginFormState = LoginFormState(), | ||
| uiState: AuthUiState = AuthUiState.Idle, | ||
| onEmailChange: (String) -> Unit = { capturedEmail = it }, | ||
| onPasswordChange: (String) -> Unit = { capturedPassword = it }, | ||
| onSignIn: () -> Unit = {}, | ||
| onSignInWithGoogle: () -> Unit = {}, | ||
| onNavigateToRegister: () -> Unit = {}, | ||
| ) { | ||
| composeTestRule.setContent { | ||
| TemplateTheme { | ||
| LoginScreen( | ||
| loginForm = loginForm, | ||
| uiState = uiState, | ||
| onEmailChange = onEmailChange, | ||
| onPasswordChange = onPasswordChange, | ||
| onSignIn = onSignIn, | ||
| onSignInWithGoogle = onSignInWithGoogle, | ||
| onNavigateToRegister = onNavigateToRegister, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun loginScreen_displaysSignInHeading() { | ||
| setContent() | ||
| // The heading "Sign In" is displayed (there may also be a button with the same label) | ||
| composeTestRule.onNodeWithText("Sign In", useUnmergedTree = false).assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun loginScreen_displaysGoogleSignInButton() { | ||
| setContent() | ||
| composeTestRule.onNodeWithText("Continue with Google").assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun loginScreen_googleButton_invokesCallback() { | ||
| var called = false | ||
| setContent(onSignInWithGoogle = { called = true }) | ||
| composeTestRule.onNodeWithText("Continue with Google").performClick() | ||
| assertTrue(called) | ||
| } | ||
|
|
||
| @Test | ||
| fun loginScreen_displaysErrorMessage() { | ||
| setContent(uiState = AuthUiState.Error("Invalid credentials")) | ||
| composeTestRule.onNodeWithText("Invalid credentials").assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun loginScreen_displaysRegisterLink() { | ||
| setContent() | ||
| composeTestRule.onNodeWithText("Register").assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun loginScreen_clickRegister_invokesCallback() { | ||
| var navigateCalled = false | ||
| setContent(onNavigateToRegister = { navigateCalled = true }) | ||
| composeTestRule.onNodeWithText("Register").performClick() | ||
| assertTrue(navigateCalled) | ||
| } | ||
|
|
||
| @Test | ||
| fun loginScreen_clickSignIn_invokesCallback() { | ||
| var signInCalled = false | ||
| setContent( | ||
| loginForm = LoginFormState(email = "test@example.com", password = "secret"), | ||
| onSignIn = { signInCalled = true }, | ||
| ) | ||
| // Use the test tag to target the button specifically, not the heading | ||
| composeTestRule.onNodeWithTag(LoginTestTags.SIGN_IN_BUTTON).performClick() | ||
| assertTrue(signInCalled) | ||
| } | ||
|
|
||
| @Test | ||
| fun loginScreen_typingEmail_updatesCallback() { | ||
| var updated = "" | ||
| setContent(onEmailChange = { updated = it }) | ||
| composeTestRule.onNodeWithText("Email").performTextInput("test@example.com") | ||
| assertTrue(updated.isNotEmpty()) | ||
| } | ||
|
|
||
| @Test | ||
| fun loginScreen_typingPassword_updatesCallback() { | ||
| var updated = "" | ||
| setContent(onPasswordChange = { updated = it }) | ||
| composeTestRule.onNodeWithText("Password").performTextInput("secret123") | ||
| assertTrue(updated.isNotEmpty()) | ||
| } | ||
| } |
96 changes: 96 additions & 0 deletions
96
mobile/app/src/androidTest/java/com/company/template/auth/RegisterScreenTest.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,96 @@ | ||
| package com.company.template.auth | ||
|
|
||
| import androidx.compose.ui.test.assertIsDisplayed | ||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import androidx.compose.ui.test.onNodeWithTag | ||
| import androidx.compose.ui.test.onNodeWithText | ||
| import androidx.compose.ui.test.performClick | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import com.company.template.ui.theme.TemplateTheme | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class RegisterScreenTest { | ||
|
|
||
| @get:Rule | ||
| val composeTestRule = createComposeRule() | ||
|
|
||
| private fun setContent( | ||
| registerForm: RegisterFormState = RegisterFormState(), | ||
| uiState: AuthUiState = AuthUiState.Idle, | ||
| onNameChange: (String) -> Unit = {}, | ||
| onEmailChange: (String) -> Unit = {}, | ||
| onPasswordChange: (String) -> Unit = {}, | ||
| onConfirmPasswordChange: (String) -> Unit = {}, | ||
| onRegister: () -> Unit = {}, | ||
| onNavigateToLogin: () -> Unit = {}, | ||
| ) { | ||
| composeTestRule.setContent { | ||
| TemplateTheme { | ||
| RegisterScreen( | ||
| registerForm = registerForm, | ||
| uiState = uiState, | ||
| onNameChange = onNameChange, | ||
| onEmailChange = onEmailChange, | ||
| onPasswordChange = onPasswordChange, | ||
| onConfirmPasswordChange = onConfirmPasswordChange, | ||
| onRegister = onRegister, | ||
| onNavigateToLogin = onNavigateToLogin, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun registerScreen_displaysCreateAccountHeading() { | ||
| setContent() | ||
| // Heading text (there may also be a button with the same label; use useUnmergedTree if needed) | ||
| composeTestRule.onNodeWithText("Create Account", useUnmergedTree = false).assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun registerScreen_displaysNameField() { | ||
| setContent() | ||
| composeTestRule.onNodeWithText("Full Name").assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun registerScreen_displaysErrorMessage() { | ||
| setContent(uiState = AuthUiState.Error("Email already in use")) | ||
| composeTestRule.onNodeWithText("Email already in use").assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun registerScreen_displaysSignInLink() { | ||
| setContent() | ||
| composeTestRule.onNodeWithText("Sign In").assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun registerScreen_clickSignIn_invokesCallback() { | ||
| var navigateCalled = false | ||
| setContent(onNavigateToLogin = { navigateCalled = true }) | ||
| composeTestRule.onNodeWithText("Sign In").performClick() | ||
| assertTrue(navigateCalled) | ||
| } | ||
|
|
||
| @Test | ||
| fun registerScreen_clickCreateAccount_invokesCallback() { | ||
| var registerCalled = false | ||
| setContent( | ||
| registerForm = RegisterFormState( | ||
| name = "Alice", | ||
| email = "alice@example.com", | ||
| password = "pass", | ||
| confirmPassword = "pass", | ||
| ), | ||
| onRegister = { registerCalled = true }, | ||
| ) | ||
| // Use the test tag to target the button specifically, not the heading | ||
| composeTestRule.onNodeWithTag(RegisterTestTags.CREATE_ACCOUNT_BUTTON).performClick() | ||
| assertTrue(registerCalled) | ||
| } | ||
| } |
74 changes: 74 additions & 0 deletions
74
mobile/app/src/androidTest/java/com/company/template/home/HomeScreenTest.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,74 @@ | ||
| package com.company.template.home | ||
|
|
||
| import androidx.compose.ui.test.assertDoesNotExist | ||
| import androidx.compose.ui.test.assertIsDisplayed | ||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import androidx.compose.ui.test.onNodeWithText | ||
| import androidx.compose.ui.test.performClick | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import com.company.template.ui.theme.TemplateTheme | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class HomeScreenTest { | ||
|
|
||
| @get:Rule | ||
| val composeTestRule = createComposeRule() | ||
|
|
||
| @Test | ||
| fun homeScreen_displaysWelcomeHeading() { | ||
| composeTestRule.setContent { | ||
| TemplateTheme { | ||
| HomeScreen(displayName = "Alice", onSignOut = {}) | ||
| } | ||
| } | ||
| composeTestRule.onNodeWithText("Welcome back!").assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun homeScreen_displaysDisplayName() { | ||
| composeTestRule.setContent { | ||
| TemplateTheme { | ||
| HomeScreen(displayName = "Alice", onSignOut = {}) | ||
| } | ||
| } | ||
| composeTestRule.onNodeWithText("Alice").assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun homeScreen_displaysSignOutButton() { | ||
| composeTestRule.setContent { | ||
| TemplateTheme { | ||
| HomeScreen(displayName = "Alice", onSignOut = {}) | ||
| } | ||
| } | ||
| composeTestRule.onNodeWithText("Sign Out").assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun homeScreen_clickSignOut_invokesCallback() { | ||
| var signOutCalled = false | ||
| composeTestRule.setContent { | ||
| TemplateTheme { | ||
| HomeScreen(displayName = "Alice", onSignOut = { signOutCalled = true }) | ||
| } | ||
| } | ||
| composeTestRule.onNodeWithText("Sign Out").performClick() | ||
| assertTrue(signOutCalled) | ||
| } | ||
|
|
||
| @Test | ||
| fun homeScreen_emptyDisplayName_doesNotShowNameText() { | ||
| composeTestRule.setContent { | ||
| TemplateTheme { | ||
| HomeScreen(displayName = "", onSignOut = {}) | ||
| } | ||
| } | ||
| composeTestRule.onNodeWithText("Welcome back!").assertIsDisplayed() | ||
| // An empty string should not produce a visible name node | ||
| composeTestRule.onNodeWithText("").assertDoesNotExist() | ||
| } | ||
|
GRACENOBLE marked this conversation as resolved.
|
||
| } | ||
51 changes: 51 additions & 0 deletions
51
mobile/app/src/androidTest/java/com/company/template/onboarding/OnboardingScreenTest.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,51 @@ | ||
| package com.company.template.onboarding | ||
|
|
||
| import androidx.compose.ui.test.assertIsDisplayed | ||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import androidx.compose.ui.test.onNodeWithText | ||
| import androidx.compose.ui.test.performClick | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import com.company.template.ui.theme.TemplateTheme | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class OnboardingScreenTest { | ||
|
|
||
| @get:Rule | ||
| val composeTestRule = createComposeRule() | ||
|
|
||
| @Test | ||
| fun onboardingScreen_displaysWelcomeHeading() { | ||
| composeTestRule.setContent { | ||
| TemplateTheme { | ||
| OnboardingScreen(onGetStarted = {}) | ||
| } | ||
| } | ||
| composeTestRule.onNodeWithText("Welcome").assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun onboardingScreen_displaysGetStartedButton() { | ||
| composeTestRule.setContent { | ||
| TemplateTheme { | ||
| OnboardingScreen(onGetStarted = {}) | ||
| } | ||
| } | ||
| composeTestRule.onNodeWithText("Get Started").assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun onboardingScreen_clickGetStarted_invokesCallback() { | ||
| var callbackInvoked = false | ||
| composeTestRule.setContent { | ||
| TemplateTheme { | ||
| OnboardingScreen(onGetStarted = { callbackInvoked = true }) | ||
| } | ||
| } | ||
| composeTestRule.onNodeWithText("Get Started").performClick() | ||
| assertTrue(callbackInvoked) | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.