Skip to content

Commit 2ed6425

Browse files
GRACENOBLEclaude
andcommitted
fix(mobile): address CodeRabbit review findings on PR #43
- Introduce User domain type so authStateFlow emits User? instead of FirebaseUser?, enabling JVM-only tests without Android framework deps - Remove Activity from AuthRepository interface; move CredentialManager and Google token fetching into AuthViewModel.signInWithGoogle() - FirebaseAuthRepository.signOut() now clears CredentialManager state to prevent stale Google account reuse on next sign-in - AuthViewModel.signOut() resets _uiState to Idle (was leaving AuthUiState.Success latched, causing nav loop back to Home) - Hoist LoginScreen/RegisterScreen form state to AuthViewModel via LoginFormState/RegisterFormState; screens receive state + callbacks - AppNavGraph calls appViewModel.markOnboardingSeen() before navigating away from onboarding so sign-out does not re-show onboarding - AppViewModel.markOnboardingSeen() added for nav graph to call - DataStoreOnboardingRepository.hasSeenOnboarding() catches IOException and emits emptyPreferences() as a safe fallback - OnboardingViewModel.markSeen() uses runCatching so onComplete is not silently skipped on DataStore failure - build.gradle.kts: release assembleRelease/bundleRelease tasks fail fast if GOOGLE_WEB_CLIENT_ID is absent from local.properties - Add LoginTestTags.SIGN_IN_BUTTON and RegisterTestTags.CREATE_ACCOUNT_BUTTON test tags to disambiguate nodes that share text with headings - Fix AppViewModelTest HOME branch: was setting user=null and asserting LOGIN — now sets a real User object and asserts HOME - HomeScreenTest: assert empty displayName does not render a name node Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 927650d commit 2ed6425

17 files changed

Lines changed: 512 additions & 347 deletions

File tree

‎mobile/app/build.gradle.kts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ android {
4040
)
4141
}
4242
}
43+
44+
// Fail fast: GOOGLE_WEB_CLIENT_ID must be set in local.properties for release builds.
45+
// (The resource default_web_client_id from google-services.json is preferred at runtime,
46+
// but BuildConfig is the fallback and must not be empty in production.)
47+
tasks.configureEach {
48+
if (name.contains("Release", ignoreCase = true) &&
49+
(name.startsWith("assemble") || name.startsWith("bundle"))
50+
) {
51+
doFirst {
52+
val webClientId = localProps.getProperty("GOOGLE_WEB_CLIENT_ID", "")
53+
check(webClientId.isNotEmpty()) {
54+
"GOOGLE_WEB_CLIENT_ID must be set in local.properties for release builds. " +
55+
"Add: GOOGLE_WEB_CLIENT_ID=<your-oauth2-web-client-id>"
56+
}
57+
}
58+
}
59+
}
4360
compileOptions {
4461
sourceCompatibility = JavaVersion.VERSION_11
4562
targetCompatibility = JavaVersion.VERSION_11

‎mobile/app/src/androidTest/java/com/company/template/auth/LoginScreenTest.kt‎

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.company.template.auth
22

33
import androidx.compose.ui.test.assertIsDisplayed
44
import androidx.compose.ui.test.junit4.createComposeRule
5+
import androidx.compose.ui.test.onNodeWithTag
56
import androidx.compose.ui.test.onNodeWithText
67
import androidx.compose.ui.test.performClick
78
import androidx.compose.ui.test.performTextInput
@@ -18,21 +19,28 @@ class LoginScreenTest {
1819
@get:Rule
1920
val composeTestRule = createComposeRule()
2021

22+
private var capturedEmail = ""
23+
private var capturedPassword = ""
24+
2125
private fun setContent(
26+
loginForm: LoginFormState = LoginFormState(),
2227
uiState: AuthUiState = AuthUiState.Idle,
23-
onSignIn: (String, String) -> Unit = { _, _ -> },
28+
onEmailChange: (String) -> Unit = { capturedEmail = it },
29+
onPasswordChange: (String) -> Unit = { capturedPassword = it },
30+
onSignIn: () -> Unit = {},
2431
onSignInWithGoogle: () -> Unit = {},
2532
onNavigateToRegister: () -> Unit = {},
26-
onClearError: () -> Unit = {}
2733
) {
2834
composeTestRule.setContent {
2935
TemplateTheme {
3036
LoginScreen(
37+
loginForm = loginForm,
3138
uiState = uiState,
39+
onEmailChange = onEmailChange,
40+
onPasswordChange = onPasswordChange,
3241
onSignIn = onSignIn,
3342
onSignInWithGoogle = onSignInWithGoogle,
3443
onNavigateToRegister = onNavigateToRegister,
35-
onClearError = onClearError
3644
)
3745
}
3846
}
@@ -41,7 +49,8 @@ class LoginScreenTest {
4149
@Test
4250
fun loginScreen_displaysSignInHeading() {
4351
setContent()
44-
composeTestRule.onNodeWithText("Sign In").assertIsDisplayed()
52+
// The heading "Sign In" is displayed (there may also be a button with the same label)
53+
composeTestRule.onNodeWithText("Sign In", useUnmergedTree = false).assertIsDisplayed()
4554
}
4655

4756
@Test
@@ -79,14 +88,30 @@ class LoginScreenTest {
7988
}
8089

8190
@Test
82-
fun loginScreen_typingEmailAndPassword_thenSignInInvoked() {
83-
var signInEmail = ""
84-
var signInPassword = ""
85-
setContent(onSignIn = { e, p -> signInEmail = e; signInPassword = p })
91+
fun loginScreen_clickSignIn_invokesCallback() {
92+
var signInCalled = false
93+
setContent(
94+
loginForm = LoginFormState(email = "test@example.com", password = "secret"),
95+
onSignIn = { signInCalled = true },
96+
)
97+
// Use the test tag to target the button specifically, not the heading
98+
composeTestRule.onNodeWithTag(LoginTestTags.SIGN_IN_BUTTON).performClick()
99+
assertTrue(signInCalled)
100+
}
101+
102+
@Test
103+
fun loginScreen_typingEmail_updatesCallback() {
104+
var updated = ""
105+
setContent(onEmailChange = { updated = it })
86106
composeTestRule.onNodeWithText("Email").performTextInput("test@example.com")
107+
assertTrue(updated.isNotEmpty())
108+
}
109+
110+
@Test
111+
fun loginScreen_typingPassword_updatesCallback() {
112+
var updated = ""
113+
setContent(onPasswordChange = { updated = it })
87114
composeTestRule.onNodeWithText("Password").performTextInput("secret123")
88-
composeTestRule.onNodeWithText("Sign In").performClick()
89-
assertTrue(signInEmail == "test@example.com")
90-
assertTrue(signInPassword == "secret123")
115+
assertTrue(updated.isNotEmpty())
91116
}
92117
}

‎mobile/app/src/androidTest/java/com/company/template/auth/RegisterScreenTest.kt‎

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.company.template.auth
22

33
import androidx.compose.ui.test.assertIsDisplayed
44
import androidx.compose.ui.test.junit4.createComposeRule
5+
import androidx.compose.ui.test.onNodeWithTag
56
import androidx.compose.ui.test.onNodeWithText
67
import androidx.compose.ui.test.performClick
78
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -17,80 +18,79 @@ class RegisterScreenTest {
1718
@get:Rule
1819
val composeTestRule = createComposeRule()
1920

20-
@Test
21-
fun registerScreen_displaysCreateAccountHeading() {
21+
private fun setContent(
22+
registerForm: RegisterFormState = RegisterFormState(),
23+
uiState: AuthUiState = AuthUiState.Idle,
24+
onNameChange: (String) -> Unit = {},
25+
onEmailChange: (String) -> Unit = {},
26+
onPasswordChange: (String) -> Unit = {},
27+
onConfirmPasswordChange: (String) -> Unit = {},
28+
onRegister: () -> Unit = {},
29+
onNavigateToLogin: () -> Unit = {},
30+
) {
2231
composeTestRule.setContent {
2332
TemplateTheme {
2433
RegisterScreen(
25-
uiState = AuthUiState.Idle,
26-
onRegister = { _, _, _, _ -> },
27-
onNavigateToLogin = {},
28-
onClearError = {}
34+
registerForm = registerForm,
35+
uiState = uiState,
36+
onNameChange = onNameChange,
37+
onEmailChange = onEmailChange,
38+
onPasswordChange = onPasswordChange,
39+
onConfirmPasswordChange = onConfirmPasswordChange,
40+
onRegister = onRegister,
41+
onNavigateToLogin = onNavigateToLogin,
2942
)
3043
}
3144
}
32-
composeTestRule.onNodeWithText("Create Account").assertIsDisplayed()
45+
}
46+
47+
@Test
48+
fun registerScreen_displaysCreateAccountHeading() {
49+
setContent()
50+
// Heading text (there may also be a button with the same label; use useUnmergedTree if needed)
51+
composeTestRule.onNodeWithText("Create Account", useUnmergedTree = false).assertIsDisplayed()
3352
}
3453

3554
@Test
3655
fun registerScreen_displaysNameField() {
37-
composeTestRule.setContent {
38-
TemplateTheme {
39-
RegisterScreen(
40-
uiState = AuthUiState.Idle,
41-
onRegister = { _, _, _, _ -> },
42-
onNavigateToLogin = {},
43-
onClearError = {}
44-
)
45-
}
46-
}
56+
setContent()
4757
composeTestRule.onNodeWithText("Full Name").assertIsDisplayed()
4858
}
4959

5060
@Test
5161
fun registerScreen_displaysErrorMessage() {
52-
composeTestRule.setContent {
53-
TemplateTheme {
54-
RegisterScreen(
55-
uiState = AuthUiState.Error("Email already in use"),
56-
onRegister = { _, _, _, _ -> },
57-
onNavigateToLogin = {},
58-
onClearError = {}
59-
)
60-
}
61-
}
62+
setContent(uiState = AuthUiState.Error("Email already in use"))
6263
composeTestRule.onNodeWithText("Email already in use").assertIsDisplayed()
6364
}
6465

6566
@Test
6667
fun registerScreen_displaysSignInLink() {
67-
composeTestRule.setContent {
68-
TemplateTheme {
69-
RegisterScreen(
70-
uiState = AuthUiState.Idle,
71-
onRegister = { _, _, _, _ -> },
72-
onNavigateToLogin = {},
73-
onClearError = {}
74-
)
75-
}
76-
}
68+
setContent()
7769
composeTestRule.onNodeWithText("Sign In").assertIsDisplayed()
7870
}
7971

8072
@Test
8173
fun registerScreen_clickSignIn_invokesCallback() {
8274
var navigateCalled = false
83-
composeTestRule.setContent {
84-
TemplateTheme {
85-
RegisterScreen(
86-
uiState = AuthUiState.Idle,
87-
onRegister = { _, _, _, _ -> },
88-
onNavigateToLogin = { navigateCalled = true },
89-
onClearError = {}
90-
)
91-
}
92-
}
75+
setContent(onNavigateToLogin = { navigateCalled = true })
9376
composeTestRule.onNodeWithText("Sign In").performClick()
9477
assertTrue(navigateCalled)
9578
}
79+
80+
@Test
81+
fun registerScreen_clickCreateAccount_invokesCallback() {
82+
var registerCalled = false
83+
setContent(
84+
registerForm = RegisterFormState(
85+
name = "Alice",
86+
email = "alice@example.com",
87+
password = "pass",
88+
confirmPassword = "pass",
89+
),
90+
onRegister = { registerCalled = true },
91+
)
92+
// Use the test tag to target the button specifically, not the heading
93+
composeTestRule.onNodeWithTag(RegisterTestTags.CREATE_ACCOUNT_BUTTON).performClick()
94+
assertTrue(registerCalled)
95+
}
9696
}

‎mobile/app/src/androidTest/java/com/company/template/home/HomeScreenTest.kt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.company.template.home
22

3+
import androidx.compose.ui.test.assertDoesNotExist
34
import androidx.compose.ui.test.assertIsDisplayed
45
import androidx.compose.ui.test.junit4.createComposeRule
56
import androidx.compose.ui.test.onNodeWithText
@@ -66,7 +67,8 @@ class HomeScreenTest {
6667
HomeScreen(displayName = "", onSignOut = {})
6768
}
6869
}
69-
// Heading still shows
7070
composeTestRule.onNodeWithText("Welcome back!").assertIsDisplayed()
71+
// An empty string should not produce a visible name node
72+
composeTestRule.onNodeWithText("").assertDoesNotExist()
7173
}
7274
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package com.company.template.auth
22

3-
import android.app.Activity
4-
import com.google.firebase.auth.FirebaseUser
53
import kotlinx.coroutines.flow.StateFlow
64

75
interface AuthRepository {
8-
val authStateFlow: StateFlow<FirebaseUser?>
6+
val authStateFlow: StateFlow<User?>
97
suspend fun signInWithEmail(email: String, password: String): Result<Unit>
108
suspend fun registerWithEmail(name: String, email: String, password: String): Result<Unit>
11-
suspend fun signInWithGoogle(activity: Activity): Result<Unit>
9+
suspend fun signInWithGoogle(googleIdToken: String): Result<Unit>
1210
suspend fun signOut()
1311
}

0 commit comments

Comments
 (0)