Skip to content

Commit

Permalink
Merge pull request #33 from SwEnt-Group13/feature/loginScreen
Browse files Browse the repository at this point in the history
feat(ui/welcomeScreen): create welcome screen before authentication
  • Loading branch information
Romainhir authored Oct 10, 2024
2 parents 067494f + bdeb2c6 commit f7a05d5
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 17 deletions.
35 changes: 35 additions & 0 deletions app/src/androidTest/java/com/android/unio/ui/AuthenticationTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.android.unio.ui

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import com.android.unio.ui.authentication.WelcomeScreen
import com.android.unio.ui.navigation.NavigationAction
import com.android.unio.ui.navigation.Screen
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify

class AuthenticationTest {

private lateinit var navigationAction: NavigationAction

@get:Rule val composeTestRule = createComposeRule()

@Before
fun setUp() {
navigationAction = mock { NavigationAction::class.java }
composeTestRule.setContent { WelcomeScreen(navigationAction) }
}

@Test
fun testNavigationWelcomeToLogin() {
composeTestRule.onNodeWithTag("LoginButton").assertIsDisplayed()
composeTestRule.onNodeWithTag("LoginButton").performClick()
verify(navigationAction).navigateTo(eq(Screen.AUTH))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.ui.test.onNodeWithText
import androidx.navigation.NavHostController
import com.android.unio.ui.association.AssociationProfile
import com.android.unio.ui.authentication.LoginScreen
import com.android.unio.ui.authentication.WelcomeScreen
import com.android.unio.ui.event.EventCreationScreen
import com.android.unio.ui.event.EventScreen
import com.android.unio.ui.explore.ExploreScreen
Expand All @@ -24,15 +25,19 @@ import org.mockito.kotlin.mock

class ScreenDisplayingTest() {

private lateinit var navHostController: NavHostController
private lateinit var navigationAction: NavigationAction

@get:Rule val composeTestRule = createComposeRule()

@Before
fun setUp() {
navHostController = mock { NavHostController::class.java }
navigationAction = NavigationAction(navHostController)
navigationAction = mock { NavHostController::class.java }
}

@Test
fun testWelcomeDisplayed() {
composeTestRule.setContent { WelcomeScreen(navigationAction) }
composeTestRule.onNodeWithTag("WelcomeScreen").assertIsDisplayed()
}

@Test
Expand Down Expand Up @@ -72,9 +77,8 @@ class ScreenDisplayingTest() {

@Test
fun testLoginDisplayed() {
composeTestRule.setContent { LoginScreen() }
composeTestRule.setContent { LoginScreen(navigationAction) }
composeTestRule.onNodeWithTag("LoginScreen").assertIsDisplayed()
composeTestRule.onNodeWithText("Login screen").assertIsDisplayed()
}

@Test
Expand Down
11 changes: 7 additions & 4 deletions app/src/main/java/com/android/unio/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navigation
import com.android.unio.ui.association.AssociationProfile
import com.android.unio.ui.authentication.LoginScreen
import com.android.unio.ui.authentication.WelcomeScreen
import com.android.unio.ui.explore.ExploreScreen
import com.android.unio.ui.home.HomeScreen
import com.android.unio.ui.navigation.NavigationAction
Expand All @@ -34,10 +36,11 @@ fun UnioApp() {

// start destination should be Route.AUTH, but for now, we let it be Route.HOME for testing
// purposes

// Remember that the route corresponds to the parent screen. The children screen should not
// have a route, and their composable should be initialized under their parent's NavGraph.
NavHost(navController = navController, startDestination = Route.HOME) {
NavHost(navController = navController, startDestination = Route.AUTH) {
navigation(startDestination = Screen.WELCOME, route = Route.AUTH) {
composable(Screen.WELCOME) { WelcomeScreen(navigationActions) }
composable(Screen.AUTH) { LoginScreen(navigationActions) }
}
navigation(startDestination = Screen.HOME, route = Route.HOME) {
composable(Screen.HOME) { HomeScreen(navigationActions) }
}
Expand Down
49 changes: 44 additions & 5 deletions app/src/main/java/com/android/unio/ui/authentication/Login.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,53 @@
package com.android.unio.ui.authentication

import android.annotation.SuppressLint
import androidx.compose.material.Scaffold
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import com.android.unio.ui.navigation.NavigationAction
import com.android.unio.ui.navigation.Screen

@SuppressLint("UnusedMaterialScaffoldPaddingParameter")
@Composable
fun LoginScreen() {
Scaffold(content = { Text("Login screen") }, modifier = Modifier.testTag("LoginScreen"))
fun LoginScreen(navigationAction: NavigationAction) {
var email by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") }
Scaffold(
modifier = Modifier.testTag("LoginScreen").fillMaxSize(),
content = { padding ->
Column(
modifier = Modifier.padding(padding).padding(vertical = 200.dp, horizontal = 50.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally) {
OutlinedTextField(
modifier = Modifier.padding(16.dp),
label = { Text("Enter your university address") },
onValueChange = { email = it },
value = email)
OutlinedTextField(
modifier = Modifier.padding(16.dp),
label = { Text("And your password") },
onValueChange = { password = it },
value = password)
Button(
onClick = {
/* TODO Handle login with Tequila/Microsoft if possible */
navigationAction.navigateTo(Screen.HOME)
}) {
Text("Continue")
}
}
})
}
45 changes: 45 additions & 0 deletions app/src/main/java/com/android/unio/ui/authentication/Welcome.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.android.unio.ui.authentication

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.android.unio.ui.navigation.NavigationAction
import com.android.unio.ui.navigation.Screen

@Composable
fun WelcomeScreen(navigationAction: NavigationAction) {
Scaffold(modifier = Modifier.fillMaxSize().testTag("WelcomeScreen")) {
Column(
modifier = Modifier.padding(it).padding(vertical = 200.dp, horizontal = 100.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally) {
// Image(
// // Placeholder for the Unio logo
// painter = painterResource(id = R.drawable.ic_launcher_foreground),
// contentDescription = "Unio logo",
// modifier = Modifier.padding(16.dp))
Text(
"The world’s largest campus life platform !",
textAlign = TextAlign.Center,
modifier = Modifier.padding(16.dp))
Button(
onClick = { navigationAction.navigateTo(Screen.AUTH) },
modifier = Modifier.testTag("LoginButton").padding(16.dp)) {
Text("Login")
}
Button(onClick = { navigationAction.navigateTo(Screen.HOME) }) {
Text("<Debug> Skip to Home")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavHostController

class NavigationAction(private val navController: NavHostController) {
open class NavigationAction(private val navController: NavHostController) {

/**
* Navigate to the specified screen.
*
* @param screen The screen to navigate to
*/
fun navigateTo(screen: String) {
open fun navigateTo(screen: String) {
navController.navigate(screen)
}

Expand All @@ -27,7 +27,7 @@ class NavigationAction(private val navController: NavHostController) {
* @param tld Main destination to navigate to, clearing the back stack when navigating to a new
* one.
*/
fun navigateTo(tld: TopLevelDestination) {
open fun navigateTo(tld: TopLevelDestination) {
navController.navigate(tld.route) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
Expand Down Expand Up @@ -89,6 +89,7 @@ object Route {

object Screen {
const val AUTH = "Auth Screen"
const val WELCOME = "Welcome Screen"
const val HOME = "Home Screen"
const val MAP = "Map Screen"
const val EXPLORE = "Explore Screen"
Expand Down

0 comments on commit f7a05d5

Please sign in to comment.