Skip to content

Commit

Permalink
Merge pull request #124 from snuhcs-course/test/integration-settings
Browse files Browse the repository at this point in the history
Fix settings integration test bug
  • Loading branch information
JH747 authored Dec 10, 2023
2 parents b6c5af1 + a074826 commit 66df38d
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package com.example.speechbuddy

import android.content.Intent
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.example.speechbuddy.compose.settings.AccountSettings
import com.example.speechbuddy.ui.SpeechBuddyTheme
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import kotlinx.coroutines.DelicateCoroutinesApi
import org.junit.After
import org.junit.Before
import org.junit.Rule
Expand All @@ -23,17 +22,11 @@ import org.junit.Test
@HiltAndroidTest
class AccountSettingsScreenTest {

private val androidTestUtil = AndroidTestUtil()

@get:Rule(order = 0)
val hiltRule = HiltAndroidRule(this)

@get:Rule(order = 1)
val composeTestRule = androidTestUtil.createAndroidIntentComposeRule<HomeActivity> {
Intent(it, HomeActivity::class.java).apply {
putExtra("isTest", true)
}
}
val composeTestRule = createAndroidComposeRule<AuthActivity>()

@Before
fun setUp() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.example.speechbuddy

import android.content.Intent
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.assertIsOff
import androidx.compose.ui.test.assertIsOn
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
Expand All @@ -22,17 +21,12 @@ import org.junit.Test

@HiltAndroidTest
class BackupSettingsScreenTest {
private val androidTestUtil = AndroidTestUtil()

@get:Rule(order = 0)
val hiltRule = HiltAndroidRule(this)

@get:Rule(order = 1)
val composeTestRule = androidTestUtil.createAndroidIntentComposeRule<HomeActivity> {
Intent(it, HomeActivity::class.java).apply {
putExtra("isTest", true)
}
}
val composeTestRule = createAndroidComposeRule<AuthActivity>()

@Before
fun setUp() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.speechbuddy

import android.content.Intent
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.ui.graphics.Color
Expand All @@ -10,6 +9,7 @@ import androidx.compose.ui.test.assertIsNotSelected
import androidx.compose.ui.test.assertIsOff
import androidx.compose.ui.test.assertIsOn
import androidx.compose.ui.test.assertIsSelected
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
Expand All @@ -26,17 +26,11 @@ import org.junit.Test
@HiltAndroidTest
class DisplaySettingsScreenTest {

private val androidTestUtil = AndroidTestUtil()

@get:Rule(order = 0)
val hiltRule = HiltAndroidRule(this)

@get:Rule(order = 1)
val composeTestRule = androidTestUtil.createAndroidIntentComposeRule<HomeActivity> {
Intent(it, HomeActivity::class.java).apply {
putExtra("isTest", true)
}
}
val composeTestRule = createAndroidComposeRule<AuthActivity>()

@Before
fun setUp() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.example.speechbuddy

import android.content.Intent
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithText
import com.example.speechbuddy.compose.settings.GuestSettings
import com.example.speechbuddy.ui.SpeechBuddyTheme
Expand All @@ -18,26 +18,21 @@ import org.junit.Test

@HiltAndroidTest
class GuestSettingsScreenTest {
private val androidTestUtil = AndroidTestUtil()

@get:Rule(order = 0)
val hiltRule = HiltAndroidRule(this)

@get:Rule(order = 1)
val composeTestRule = androidTestUtil.createAndroidIntentComposeRule<HomeActivity> {
Intent(it, HomeActivity::class.java).apply {
putExtra("isTest", true)
}
}
val composeTestRule = createAndroidComposeRule<AuthActivity>()

@Before
fun setUp() {
hiltRule.inject()
val guestId = -1
val fakeEmail = "guest"
val fakeNickname = "guest"
composeTestRule.activity.sessionManager.setUserId(guestId)
composeTestRule.activity.userRepository.setMyInfo(guestId, fakeEmail, fakeNickname)
val fakeId = 1
val fakeEmail = "[email protected]"
val fakeNickname = "nickname"
composeTestRule.activity.sessionManager.setUserId(fakeId)
composeTestRule.activity.userRepository.setMyInfo(fakeId, fakeEmail, fakeNickname)
composeTestRule.activity.setContent {
SpeechBuddyTheme(
settingsRepository = composeTestRule.activity.settingsRepository,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.example.speechbuddy

import android.content.Intent
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.navigation.NavHostController
import com.example.speechbuddy.compose.settings.MainSettings
Expand All @@ -18,23 +18,18 @@ import org.junit.Test

@HiltAndroidTest
class MainSettingsScreenTest {
private val androidTestUtil = AndroidTestUtil()

@get:Rule(order = 0)
val hiltRule = HiltAndroidRule(this)

@get:Rule(order = 1)
val composeTestRule = androidTestUtil.createAndroidIntentComposeRule<HomeActivity> {
Intent(it, HomeActivity::class.java).apply {
putExtra("isTest", true)
}
}
val composeTestRule = createAndroidComposeRule<AuthActivity>()

@Before
fun setUp() {
hiltRule.inject()
val fakeId = 0
val fakeEmail = "email"
val fakeId = 1
val fakeEmail = "email@email.com"
val fakeNickname = "nickname"
composeTestRule.activity.sessionManager.setUserId(fakeId)
composeTestRule.activity.userRepository.setMyInfo(fakeId, fakeEmail, fakeNickname)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity
import com.example.speechbuddy.domain.SessionManager
import com.example.speechbuddy.repository.AuthRepository
import com.example.speechbuddy.repository.SettingsRepository
import com.example.speechbuddy.repository.UserRepository
import javax.inject.Inject

abstract class BaseActivity : AppCompatActivity() {
Expand All @@ -17,4 +18,7 @@ abstract class BaseActivity : AppCompatActivity() {
@Inject
lateinit var settingsRepository: SettingsRepository

@Inject
lateinit var userRepository: UserRepository

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.speechbuddy.repository

import com.example.speechbuddy.data.local.UserDao
import com.example.speechbuddy.data.local.UserIdPrefsManager
import com.example.speechbuddy.data.local.models.UserEntity
import com.example.speechbuddy.data.local.models.UserMapper
import com.example.speechbuddy.data.remote.UserRemoteSource
import com.example.speechbuddy.data.remote.models.UserDtoMapper
Expand Down Expand Up @@ -76,6 +77,13 @@ class UserRepository @Inject constructor(
}
}

fun setMyInfo(id: Int, email: String, nickname: String) {
CoroutineScope(Dispatchers.IO).launch {
userIdPrefsManager.saveUserId(id)
userDao.insertUser(UserEntity(id, email, nickname))
}
}

private fun <T> returnUnknownError(): Resource<T> {
return Resource.error(
"Unknown error", null
Expand Down

0 comments on commit 66df38d

Please sign in to comment.