Skip to content

Commit

Permalink
Merge pull request #27 from snuhcs-course/UI_testing
Browse files Browse the repository at this point in the history
UI testing
  • Loading branch information
ozeeeno authored Dec 2, 2023
2 parents 33e6607 + d192fc9 commit 5cce3eb
Show file tree
Hide file tree
Showing 31 changed files with 1,520 additions and 225 deletions.
3 changes: 3 additions & 0 deletions frontend/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,7 @@ dependencies {

// swipe refresh
implementation ("com.google.accompanist:accompanist-swiperefresh:0.18.0")

// using GrantPermissionRule
androidTestImplementation ("androidx.test:rules:1.3.0")
}
176 changes: 155 additions & 21 deletions frontend/app/src/androidTest/java/com/team13/fooriend/BottomBarTest.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package com.team13.fooriend

import android.Manifest
import android.content.Context
import android.os.Build
import android.util.Log
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.onNodeWithTag
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 androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
import com.team13.fooriend.ui.component.BottomBar
import com.team13.fooriend.ui.component.BottomNavigation
import com.team13.fooriend.ui.navigation.BottomNavItem
import com.team13.fooriend.ui.util.saveAccessToken
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
Expand All @@ -26,51 +26,185 @@ import org.junit.Test
class BottomBarTest {
@get:Rule
val composeTestRule = createComposeRule()
lateinit var navController: TestNavHostController
private lateinit var navController: TestNavHostController
lateinit var context: Context

@Before
fun setUpNavHost(){
composeTestRule.setContent {
navController = TestNavHostController(LocalContext.current)
context = LocalContext.current
saveAccessToken(context, "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwidXNlcm5hbWUiOiJtZWNoYW5pY2pvIiwiaWF0IjoxNzAxMjY3NTc5LCJleHAiOjE3MDkwNDM1Nzl9.QcaBr1w8RKQ_FkQ_Yce_J7fOn6TuvVhjl3H0jjMANmY")
navController = TestNavHostController(context)
navController.navigatorProvider.addNavigator(ComposeNavigator())
BottomBar(navController = navController, context = LocalContext.current, showBottomBar = true)
BottomBar(navController = navController, context = context, showBottomBar = true)
}
val route = navController.currentBackStackEntry?.destination?.route
Log.d("BottomBarTestLog", route.toString())
}
@Before
fun setUpPermission(){
// 위치 정보 공유 허가 코드
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
InstrumentationRegistry.getInstrumentation().uiAutomation.executeShellCommand(
"pm grant " + InstrumentationRegistry.getInstrumentation().targetContext.packageName
+ " android.permission.ACCESS_FINE_LOCATION"
)
}
}

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

composeTestRule
.onNodeWithText("Social")
.onNodeWithTag("Social")
.assertIsNotSelected()
.performClick()
val route = navController.currentBackStackEntry?.destination?.route
Assert.assertEquals(route, BottomNavItem.Social.route)
composeTestRule
.onNodeWithTag("Home")
.assertIsNotSelected()
composeTestRule
.onNodeWithTag("Social")
.assertIsSelected()
composeTestRule
.onNodeWithTag("MyPage")
.assertIsNotSelected()
}

@Test
fun performClick_OnMyPageIcon_navigatesToMyPageScreen(){
fun performClick_OnSocialIcon_navigatesToSocialScreen_startMyPageScreen(){
// MyPage -> Social
composeTestRule
.onNodeWithTag("MyPage")
.performClick()

composeTestRule
.onNodeWithTag("Social")
.assertIsNotSelected()
.performClick()
val route = navController.currentBackStackEntry?.destination?.route
Assert.assertEquals(route, BottomNavItem.Social.route)
composeTestRule
.onNodeWithText("MyPage")
.onNodeWithTag("Home")
.assertIsNotSelected()
composeTestRule
.onNodeWithTag("Social")
.assertIsSelected()
composeTestRule
.onNodeWithTag("MyPage")
.assertIsNotSelected()
}

@Test
fun test3(){
fun performClick_OnMyPageIcon_navigatesToMyPageScreen_startHomeScreen(){
// Home -> MyPage
composeTestRule
.onNodeWithTag("Home")
.performClick()

composeTestRule
.onNodeWithTag("MyPage")
.assertIsNotSelected()
.performClick()
val route = navController.currentBackStackEntry?.destination?.route
Assert.assertEquals(route, BottomNavItem.MyPage.route)
composeTestRule
.onNodeWithText("MyPage")
.onNodeWithTag("Home")
.assertIsNotSelected()
composeTestRule
.onNodeWithTag("Social")
.assertIsNotSelected()
composeTestRule
.onNodeWithTag("MyPage")
.assertIsSelected()
}

@Test
fun performClick_OnMyPageIcon_navigatesToMyPageScreen_startSocialScreen(){
// Social -> MyPage
composeTestRule
.onNodeWithTag("Social")
.performClick()

composeTestRule
.onNodeWithTag("MyPage")
.assertIsNotSelected()
.performClick()
val route = navController.currentBackStackEntry?.destination?.route
Assert.assertEquals(route, BottomNavItem.MyPage.route)
composeTestRule
.onNodeWithTag("Home")
.assertIsNotSelected()
composeTestRule
.onNodeWithTag("Social")
.assertIsNotSelected()
composeTestRule
.onNodeWithTag("MyPage")
.assertIsSelected()
}

@Test
fun performClick_OnHomeIcon_navigatesHomeScreen_startSocialScreen(){
// Social -> Home
composeTestRule
.onNodeWithTag("Social")
.performClick()

composeTestRule
.onNodeWithTag("Home")
.assertIsNotSelected()
.performClick()
val route = navController.currentBackStackEntry?.destination?.route
Assert.assertEquals(route, BottomNavItem.Home.route)
composeTestRule
.onNodeWithTag("Home")
.assertIsSelected()
composeTestRule
.onNodeWithTag("Social")
.assertIsNotSelected()
composeTestRule
.onNodeWithTag("MyPage")
.assertIsNotSelected()
}

@Test
fun performClick_OnHomeIcon_navigatesHomeScreen_startMyPageScreen(){
// MyPage -> Home
composeTestRule
.onNodeWithTag("MyPage")
.performClick()

composeTestRule
.onNodeWithTag("Home")
.assertIsNotSelected()
.performClick()
val route = navController.currentBackStackEntry?.destination?.route
Assert.assertEquals(route, BottomNavItem.Home.route)
composeTestRule
.onNodeWithTag("Home")
.assertIsSelected()
composeTestRule
.onNodeWithTag("Social")
.assertIsNotSelected()
composeTestRule
.onNodeWithTag("MyPage")
.assertIsNotSelected()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.team13.fooriend

import android.content.Context
import android.util.Log
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.onNodeWithTag
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.HomeNavGraph
import com.team13.fooriend.ui.navigation.BottomNavItem
import com.team13.fooriend.ui.util.saveAccessToken
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test

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

@Before
fun setUpNavHost(){
composeTestRule.setContent {
context = LocalContext.current
saveAccessToken(context, "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwidXNlcm5hbWUiOiJtZWNoYW5pY2pvIiwiaWF0IjoxNzAxMjY3NTc5LCJleHAiOjE3MDkwNDM1Nzl9.QcaBr1w8RKQ_FkQ_Yce_J7fOn6TuvVhjl3H0jjMANmY")
navController = TestNavHostController(context)
navController.navigatorProvider.addNavigator(ComposeNavigator())
HomeNavGraph(navController = navController, context = context, startDestination = BottomNavItem.MyPage.route)
}
composeTestRule.waitUntil(timeoutMillis = 10000) {
composeTestRule
.onAllNodesWithTag("reviewLazyGridItem")
.fetchSemanticsNodes().isNotEmpty()
}
composeTestRule
.onNodeWithTag("followingButton")
.assertIsDisplayed()
.performClick()
composeTestRule.waitUntil(100000) {
composeTestRule
.onAllNodesWithTag("popup")
.fetchSemanticsNodes().isNotEmpty()
}
composeTestRule
.onAllNodesWithTag("userListItem")[0]
.assertIsDisplayed()
.performClick()
composeTestRule.waitUntil(10000) {
composeTestRule
.onAllNodesWithTag("reviewLazyGridItem")
.fetchSemanticsNodes().isNotEmpty()
}
}

@Test
fun performClick_OnBackButton_navigatesToMyPageScreen(){
composeTestRule
.onNodeWithTag("backButton")
.assertIsDisplayed()
.performClick()
val route = navController.currentBackStackEntry?.destination?.route
Log.d("FooriendScreenTest", route.toString())
}

@Test
fun verify_FooriendFollowState(){
composeTestRule
.onNodeWithTag("profileSection")
.assertIsDisplayed()
composeTestRule.waitUntil(10000) {
composeTestRule
.onAllNodesWithTag("unfollowButton")
.fetchSemanticsNodes().isNotEmpty()
}
composeTestRule
.onNodeWithTag("unfollowButton")
.assertIsDisplayed()
}

@Test
fun performClick_OnUnfollowButton_OnFollowButton(){
composeTestRule.waitUntil(10000) {
composeTestRule
.onAllNodesWithTag("unfollowButton")
.fetchSemanticsNodes().isNotEmpty()
}
composeTestRule
.onNodeWithTag("unfollowButton")
.assertIsDisplayed()
.performClick()
composeTestRule.waitUntil(timeoutMillis = 10000) {
composeTestRule
.onAllNodesWithTag("unfollowButton")
.fetchSemanticsNodes().isEmpty()
}
composeTestRule
.onNodeWithTag("followButton")
.assertIsDisplayed()
.performClick()
}

@Test
fun performClick_OnReviewLazyGridItem_navigatesToReviewDetailScreen(){
composeTestRule.waitUntil(timeoutMillis = 10000) {
composeTestRule
.onAllNodesWithTag("reviewLazyGridItem")
.fetchSemanticsNodes().isNotEmpty()
}
composeTestRule
.onAllNodesWithTag("reviewLazyGridItem")[0]
.assertIsDisplayed()
.performClick()
val route = navController.currentBackStackEntry?.destination?.route
Assert.assertEquals(route, "reviewDetail/{reviewId}")
}
}
Loading

0 comments on commit 5cce3eb

Please sign in to comment.