Skip to content

Commit 610ba54

Browse files
authored
Merge pull request #43 from GRACENOBLE/37-feat-mobile-auth
feat(mobile): onboarding and Firebase authentication
2 parents a9940c6 + 2ed6425 commit 610ba54

23 files changed

Lines changed: 1814 additions & 12 deletions

‎mobile/app/build.gradle.kts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ android {
2828

2929
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3030
buildConfigField("String", "SENTRY_DSN", "\"${localProps.getProperty("SENTRY_DSN", "")}\"")
31+
buildConfigField("String", "GOOGLE_WEB_CLIENT_ID", "\"${localProps.getProperty("GOOGLE_WEB_CLIENT_ID", "")}\"")
3132
}
3233

3334
buildTypes {
@@ -39,6 +40,23 @@ android {
3940
)
4041
}
4142
}
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+
}
4260
compileOptions {
4361
sourceCompatibility = JavaVersion.VERSION_11
4462
targetCompatibility = JavaVersion.VERSION_11
@@ -61,10 +79,19 @@ dependencies {
6179
implementation(libs.sentry.android)
6280
implementation(platform(libs.firebase.bom))
6381
implementation(libs.firebase.messaging.ktx)
82+
implementation(libs.firebase.auth.ktx)
83+
implementation(libs.androidx.navigation.compose)
84+
implementation(libs.androidx.credentials)
85+
implementation(libs.androidx.credentials.play.services)
86+
implementation(libs.googleid)
87+
implementation(libs.datastore.preferences)
88+
implementation(libs.coil.compose)
6489
implementation(libs.okhttp)
6590
implementation(libs.kotlinx.coroutines.android)
6691
implementation(libs.kotlinx.serialization.json)
6792
implementation(libs.androidx.lifecycle.viewmodel.ktx)
93+
implementation(libs.androidx.lifecycle.viewmodel.compose)
94+
implementation(libs.androidx.lifecycle.runtime.compose)
6895
testImplementation(libs.junit)
6996
testImplementation(libs.kotlinx.coroutines.test)
7097
testImplementation(libs.okhttp.mockwebserver)
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package com.company.template.auth
2+
3+
import androidx.compose.ui.test.assertIsDisplayed
4+
import androidx.compose.ui.test.junit4.createComposeRule
5+
import androidx.compose.ui.test.onNodeWithTag
6+
import androidx.compose.ui.test.onNodeWithText
7+
import androidx.compose.ui.test.performClick
8+
import androidx.compose.ui.test.performTextInput
9+
import androidx.test.ext.junit.runners.AndroidJUnit4
10+
import com.company.template.ui.theme.TemplateTheme
11+
import org.junit.Assert.assertTrue
12+
import org.junit.Rule
13+
import org.junit.Test
14+
import org.junit.runner.RunWith
15+
16+
@RunWith(AndroidJUnit4::class)
17+
class LoginScreenTest {
18+
19+
@get:Rule
20+
val composeTestRule = createComposeRule()
21+
22+
private var capturedEmail = ""
23+
private var capturedPassword = ""
24+
25+
private fun setContent(
26+
loginForm: LoginFormState = LoginFormState(),
27+
uiState: AuthUiState = AuthUiState.Idle,
28+
onEmailChange: (String) -> Unit = { capturedEmail = it },
29+
onPasswordChange: (String) -> Unit = { capturedPassword = it },
30+
onSignIn: () -> Unit = {},
31+
onSignInWithGoogle: () -> Unit = {},
32+
onNavigateToRegister: () -> Unit = {},
33+
) {
34+
composeTestRule.setContent {
35+
TemplateTheme {
36+
LoginScreen(
37+
loginForm = loginForm,
38+
uiState = uiState,
39+
onEmailChange = onEmailChange,
40+
onPasswordChange = onPasswordChange,
41+
onSignIn = onSignIn,
42+
onSignInWithGoogle = onSignInWithGoogle,
43+
onNavigateToRegister = onNavigateToRegister,
44+
)
45+
}
46+
}
47+
}
48+
49+
@Test
50+
fun loginScreen_displaysSignInHeading() {
51+
setContent()
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()
54+
}
55+
56+
@Test
57+
fun loginScreen_displaysGoogleSignInButton() {
58+
setContent()
59+
composeTestRule.onNodeWithText("Continue with Google").assertIsDisplayed()
60+
}
61+
62+
@Test
63+
fun loginScreen_googleButton_invokesCallback() {
64+
var called = false
65+
setContent(onSignInWithGoogle = { called = true })
66+
composeTestRule.onNodeWithText("Continue with Google").performClick()
67+
assertTrue(called)
68+
}
69+
70+
@Test
71+
fun loginScreen_displaysErrorMessage() {
72+
setContent(uiState = AuthUiState.Error("Invalid credentials"))
73+
composeTestRule.onNodeWithText("Invalid credentials").assertIsDisplayed()
74+
}
75+
76+
@Test
77+
fun loginScreen_displaysRegisterLink() {
78+
setContent()
79+
composeTestRule.onNodeWithText("Register").assertIsDisplayed()
80+
}
81+
82+
@Test
83+
fun loginScreen_clickRegister_invokesCallback() {
84+
var navigateCalled = false
85+
setContent(onNavigateToRegister = { navigateCalled = true })
86+
composeTestRule.onNodeWithText("Register").performClick()
87+
assertTrue(navigateCalled)
88+
}
89+
90+
@Test
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 })
106+
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 })
114+
composeTestRule.onNodeWithText("Password").performTextInput("secret123")
115+
assertTrue(updated.isNotEmpty())
116+
}
117+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.company.template.auth
2+
3+
import androidx.compose.ui.test.assertIsDisplayed
4+
import androidx.compose.ui.test.junit4.createComposeRule
5+
import androidx.compose.ui.test.onNodeWithTag
6+
import androidx.compose.ui.test.onNodeWithText
7+
import androidx.compose.ui.test.performClick
8+
import androidx.test.ext.junit.runners.AndroidJUnit4
9+
import com.company.template.ui.theme.TemplateTheme
10+
import org.junit.Assert.assertTrue
11+
import org.junit.Rule
12+
import org.junit.Test
13+
import org.junit.runner.RunWith
14+
15+
@RunWith(AndroidJUnit4::class)
16+
class RegisterScreenTest {
17+
18+
@get:Rule
19+
val composeTestRule = createComposeRule()
20+
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+
) {
31+
composeTestRule.setContent {
32+
TemplateTheme {
33+
RegisterScreen(
34+
registerForm = registerForm,
35+
uiState = uiState,
36+
onNameChange = onNameChange,
37+
onEmailChange = onEmailChange,
38+
onPasswordChange = onPasswordChange,
39+
onConfirmPasswordChange = onConfirmPasswordChange,
40+
onRegister = onRegister,
41+
onNavigateToLogin = onNavigateToLogin,
42+
)
43+
}
44+
}
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()
52+
}
53+
54+
@Test
55+
fun registerScreen_displaysNameField() {
56+
setContent()
57+
composeTestRule.onNodeWithText("Full Name").assertIsDisplayed()
58+
}
59+
60+
@Test
61+
fun registerScreen_displaysErrorMessage() {
62+
setContent(uiState = AuthUiState.Error("Email already in use"))
63+
composeTestRule.onNodeWithText("Email already in use").assertIsDisplayed()
64+
}
65+
66+
@Test
67+
fun registerScreen_displaysSignInLink() {
68+
setContent()
69+
composeTestRule.onNodeWithText("Sign In").assertIsDisplayed()
70+
}
71+
72+
@Test
73+
fun registerScreen_clickSignIn_invokesCallback() {
74+
var navigateCalled = false
75+
setContent(onNavigateToLogin = { navigateCalled = true })
76+
composeTestRule.onNodeWithText("Sign In").performClick()
77+
assertTrue(navigateCalled)
78+
}
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+
}
96+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.company.template.home
2+
3+
import androidx.compose.ui.test.assertDoesNotExist
4+
import androidx.compose.ui.test.assertIsDisplayed
5+
import androidx.compose.ui.test.junit4.createComposeRule
6+
import androidx.compose.ui.test.onNodeWithText
7+
import androidx.compose.ui.test.performClick
8+
import androidx.test.ext.junit.runners.AndroidJUnit4
9+
import com.company.template.ui.theme.TemplateTheme
10+
import org.junit.Assert.assertTrue
11+
import org.junit.Rule
12+
import org.junit.Test
13+
import org.junit.runner.RunWith
14+
15+
@RunWith(AndroidJUnit4::class)
16+
class HomeScreenTest {
17+
18+
@get:Rule
19+
val composeTestRule = createComposeRule()
20+
21+
@Test
22+
fun homeScreen_displaysWelcomeHeading() {
23+
composeTestRule.setContent {
24+
TemplateTheme {
25+
HomeScreen(displayName = "Alice", onSignOut = {})
26+
}
27+
}
28+
composeTestRule.onNodeWithText("Welcome back!").assertIsDisplayed()
29+
}
30+
31+
@Test
32+
fun homeScreen_displaysDisplayName() {
33+
composeTestRule.setContent {
34+
TemplateTheme {
35+
HomeScreen(displayName = "Alice", onSignOut = {})
36+
}
37+
}
38+
composeTestRule.onNodeWithText("Alice").assertIsDisplayed()
39+
}
40+
41+
@Test
42+
fun homeScreen_displaysSignOutButton() {
43+
composeTestRule.setContent {
44+
TemplateTheme {
45+
HomeScreen(displayName = "Alice", onSignOut = {})
46+
}
47+
}
48+
composeTestRule.onNodeWithText("Sign Out").assertIsDisplayed()
49+
}
50+
51+
@Test
52+
fun homeScreen_clickSignOut_invokesCallback() {
53+
var signOutCalled = false
54+
composeTestRule.setContent {
55+
TemplateTheme {
56+
HomeScreen(displayName = "Alice", onSignOut = { signOutCalled = true })
57+
}
58+
}
59+
composeTestRule.onNodeWithText("Sign Out").performClick()
60+
assertTrue(signOutCalled)
61+
}
62+
63+
@Test
64+
fun homeScreen_emptyDisplayName_doesNotShowNameText() {
65+
composeTestRule.setContent {
66+
TemplateTheme {
67+
HomeScreen(displayName = "", onSignOut = {})
68+
}
69+
}
70+
composeTestRule.onNodeWithText("Welcome back!").assertIsDisplayed()
71+
// An empty string should not produce a visible name node
72+
composeTestRule.onNodeWithText("").assertDoesNotExist()
73+
}
74+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.company.template.onboarding
2+
3+
import androidx.compose.ui.test.assertIsDisplayed
4+
import androidx.compose.ui.test.junit4.createComposeRule
5+
import androidx.compose.ui.test.onNodeWithText
6+
import androidx.compose.ui.test.performClick
7+
import androidx.test.ext.junit.runners.AndroidJUnit4
8+
import com.company.template.ui.theme.TemplateTheme
9+
import org.junit.Assert.assertTrue
10+
import org.junit.Rule
11+
import org.junit.Test
12+
import org.junit.runner.RunWith
13+
14+
@RunWith(AndroidJUnit4::class)
15+
class OnboardingScreenTest {
16+
17+
@get:Rule
18+
val composeTestRule = createComposeRule()
19+
20+
@Test
21+
fun onboardingScreen_displaysWelcomeHeading() {
22+
composeTestRule.setContent {
23+
TemplateTheme {
24+
OnboardingScreen(onGetStarted = {})
25+
}
26+
}
27+
composeTestRule.onNodeWithText("Welcome").assertIsDisplayed()
28+
}
29+
30+
@Test
31+
fun onboardingScreen_displaysGetStartedButton() {
32+
composeTestRule.setContent {
33+
TemplateTheme {
34+
OnboardingScreen(onGetStarted = {})
35+
}
36+
}
37+
composeTestRule.onNodeWithText("Get Started").assertIsDisplayed()
38+
}
39+
40+
@Test
41+
fun onboardingScreen_clickGetStarted_invokesCallback() {
42+
var callbackInvoked = false
43+
composeTestRule.setContent {
44+
TemplateTheme {
45+
OnboardingScreen(onGetStarted = { callbackInvoked = true })
46+
}
47+
}
48+
composeTestRule.onNodeWithText("Get Started").performClick()
49+
assertTrue(callbackInvoked)
50+
}
51+
}

0 commit comments

Comments
 (0)