Skip to content

Commit

Permalink
Merge pull request #18 from snuhcs-course/frontend_api_finish
Browse files Browse the repository at this point in the history
Frontend api finish
  • Loading branch information
mechanicjo authored Nov 16, 2023
2 parents 958021c + 22d109d commit d0f0b90
Show file tree
Hide file tree
Showing 25 changed files with 718 additions and 112 deletions.
14 changes: 6 additions & 8 deletions frontend/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -94,32 +94,30 @@ dependencies {
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.3.3")
debugImplementation("androidx.compose.ui:ui-tooling:1.3.3")
debugImplementation("androidx.compose.ui:ui-test-manifest:1.3.3")

// Navigation
implementation("androidx.navigation:navigation-compose:2.4.0-alpha10")

implementation("androidx.navigation:navigation-compose:2.5.3")
androidTestImplementation("androidx.navigation:navigation-testing:2.5.3")
// Gogle Places
implementation("com.google.android.libraries.places:places:3.1.0")

// Retrofit
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
implementation ("com.squareup.okhttp3:okhttp:4.9.0")
//
//Lifecycle
implementation ("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1")
implementation ("androidx.lifecycle:lifecycle-runtime-compose:2.6.1")

// Testing Navigation
androidTestImplementation ("androidx.navigation:navigation-testing:2.4.0-alpha10")
// JUnit
testImplementation ("junit:junit:4.+")
// MockK (Kotlin-friendly mocking library)
testImplementation ("io.mockk:mockk:1.12.0")

androidTestImplementation ("androidx.compose.ui:ui-test-junit4:1.7.0")
// coil: image upload
implementation ("io.coil-kt:coil-compose:1.4.0")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.team13.fooriend

import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertIsFocused
import androidx.compose.ui.test.assertIsNotSelected
import androidx.compose.ui.test.assertIsOn
import androidx.compose.ui.test.assertIsSelected
import androidx.compose.ui.test.assertIsToggleable
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.navigation.compose.ComposeNavigator
import androidx.navigation.testing.TestNavHostController
import com.team13.fooriend.core.graph.AuthScreen
import com.team13.fooriend.core.graph.RootNavigationGraph
import com.team13.fooriend.ui.component.BottomBar
import com.team13.fooriend.ui.component.BottomNavigation
import com.team13.fooriend.ui.navigation.BottomNavItem
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test

class BottomBarTest {
@get:Rule
val composeTestRule = createComposeRule()
lateinit var navController: TestNavHostController

@Before
fun setUpNavHost(){
composeTestRule.setContent {
navController = TestNavHostController(LocalContext.current)
navController.navigatorProvider.addNavigator(ComposeNavigator())
BottomBar(navController = navController, context = LocalContext.current, showBottomBar = true)
}
}

@Test
fun verify_StartDestinationIsHomeScreen(){
composeTestRule
.onNodeWithText("Home")
.assertIsSelected()
composeTestRule
.onNodeWithText("Social")
.assertIsNotSelected()
composeTestRule
.onNodeWithText("MyPage")
.assertIsNotSelected()
}
// 이후부터는 스마트폰 필요
@Test
fun performClick_OnSocialIcon_navigatesToSocialScreen(){
composeTestRule
.onNodeWithText("Social")
.performClick()
}

@Test
fun performClick_OnMyPageIcon_navigatesToMyPageScreen(){
composeTestRule
.onNodeWithText("MyPage")
.assertIsNotSelected()
}

@Test
fun test3(){
composeTestRule
.onNodeWithText("MyPage")
.assertIsNotSelected()
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.team13.fooriend

import androidx.compose.ui.platform.LocalContext
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.compose.ui.test.performTextInput
import androidx.navigation.compose.ComposeNavigator
import androidx.navigation.testing.TestNavHostController
import com.team13.fooriend.core.graph.AuthScreen
import com.team13.fooriend.core.graph.Graph
import com.team13.fooriend.core.graph.RootNavigationGraph
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test

class LogInScreenTest {

@get:Rule
val composeTestRule = createComposeRule()
lateinit var navController: TestNavHostController

@Before
fun setUpNavHost(){
composeTestRule.setContent {
navController = TestNavHostController(LocalContext.current)
navController.navigatorProvider.addNavigator(ComposeNavigator())
RootNavigationGraph(navController = navController, context = LocalContext.current)
}
}

@Test
fun verify_StartDestinationIsLoginScreen(){
composeTestRule
.onNodeWithText("LOGIN")
.assertIsDisplayed()
}

@Test
fun performClick_OnSignUpButton_navigatesToSignUpScreen(){
composeTestRule
.onNodeWithText("SIGN UP")
.performClick()
val route = navController.currentBackStackEntry?.destination?.route
Assert.assertEquals(route, AuthScreen.SignUp.route)
}

@Test
fun performClick_OnLogInButton_withEmptyIDandPWD(){
composeTestRule
.onNodeWithText("LOGIN")
.performClick()
val route = navController.currentBackStackEntry?.destination?.route
Assert.assertEquals(route, AuthScreen.Login.route)
}

@Test
fun performClick_OnLogInButton_withWrongIDorPWD(){
composeTestRule
.onNodeWithText("ID")
.performTextInput("admin")
composeTestRule
.onNodeWithText("PASSWORD")
.performTextInput("admin") // please change wrong pwd
composeTestRule
.onNodeWithText("LOGIN")
.performClick()
val route = navController.currentBackStackEntry?.destination?.route
Assert.assertEquals(route, AuthScreen.Login.route)
}

@Test
fun performClick_OnLogInButton_withCorrectIDandPWD(){
composeTestRule
.onNodeWithText("ID")
.performTextInput("admin")
composeTestRule
.onNodeWithText("PASSWORD")
.performTextInput("admin")
composeTestRule
.onNodeWithText("LOGIN")
.performClick()
val route = navController.currentBackStackEntry?.destination?.route
Assert.assertEquals(route, Graph.HOME)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.team13.fooriend

import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.hasParent
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.printToLog
import androidx.navigation.compose.ComposeNavigator
import androidx.navigation.testing.TestNavHostController
import com.team13.fooriend.core.graph.AuthScreen
import com.team13.fooriend.core.graph.HomeNavGraph
import com.team13.fooriend.core.graph.RootNavigationGraph
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test

class MyPageScreenTest {
@get:Rule
val composeTestRule = createComposeRule()
lateinit var navController: TestNavHostController

@Before
fun setUpNavHost(){
composeTestRule.setContent {
navController = TestNavHostController(LocalContext.current)
navController.navigatorProvider.addNavigator(ComposeNavigator())
HomeNavGraph(navController = navController, context = LocalContext.current)

}
}

@Test
fun performClick_OnSettingButton_navigatesToMyInformationScreen(){
composeTestRule
.onNodeWithContentDescription("My Info")

composeTestRule.onRoot().printToLog("test1234")
}

}
1 change: 1 addition & 0 deletions frontend/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
package com.team13.fooriend.core.graph

import android.content.Context
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.navigation.compose.composable
import androidx.navigation.navigation
import com.team13.fooriend.ui.screen.login.LogInScreen
import com.team13.fooriend.ui.screen.signup.SignUpScreen
import com.team13.fooriend.ui.util.getAccessToken

sealed class AuthScreen(val route: String) {
object Login : AuthScreen(route = "LOGIN")
object SignUp : AuthScreen(route = "SIGN_UP")
object Forgot : AuthScreen(route = "FORGOT")
}
fun NavGraphBuilder.authNavGraph(
context : Context,
navController: NavHostController
){
navigation(
route = Graph.AUTHENTICATION,
startDestination = AuthScreen.Login.route // default screen
){
composable(route = AuthScreen.Login.route){// LogInScreen
composable(route = AuthScreen.Login.route){
// if(isLoggedIn(context)){
// navController.popBackStack()
// navController.navigate(Graph.HOME)
// }
// LogInScreen
LogInScreen(
context = context,
onClick = {
navController.popBackStack()
navController.navigate(Graph.HOME)
Expand All @@ -32,10 +41,16 @@ fun NavGraphBuilder.authNavGraph(
}
composable(route = AuthScreen.SignUp.route){// SignUpScreen
SignUpScreen(
context = context,
onSignUpClick = {
navController.navigate(AuthScreen.Login.route)
}
)
}
}
}

private fun isLoggedIn(context: Context): Boolean {
val accesstoken = getAccessToken(context)
return accesstoken != ""
}
Loading

0 comments on commit d0f0b90

Please sign in to comment.