diff --git a/frontend/app/src/androidTest/java/com/example/speechbuddy/AccountSettingsScreenTest.kt b/frontend/app/src/androidTest/java/com/example/speechbuddy/AccountSettingsScreenTest.kt index 9eb17f08..99afba7a 100644 --- a/frontend/app/src/androidTest/java/com/example/speechbuddy/AccountSettingsScreenTest.kt +++ b/frontend/app/src/androidTest/java/com/example/speechbuddy/AccountSettingsScreenTest.kt @@ -1,12 +1,12 @@ 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 @@ -14,7 +14,6 @@ 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 @@ -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 { - Intent(it, HomeActivity::class.java).apply { - putExtra("isTest", true) - } - } + val composeTestRule = createAndroidComposeRule() @Before fun setUp() { diff --git a/frontend/app/src/androidTest/java/com/example/speechbuddy/AndroidTestUtil.kt b/frontend/app/src/androidTest/java/com/example/speechbuddy/AndroidTestUtil.kt deleted file mode 100644 index f9741f24..00000000 --- a/frontend/app/src/androidTest/java/com/example/speechbuddy/AndroidTestUtil.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.example.speechbuddy - -import android.content.Context -import android.content.Intent -import androidx.activity.ComponentActivity -import androidx.compose.ui.test.junit4.AndroidComposeTestRule -import androidx.test.core.app.ApplicationProvider -import androidx.test.ext.junit.rules.ActivityScenarioRule - -class AndroidTestUtil { - /** - * Factory method to provide Android specific implementation of createComposeRule, for a given - * activity class type A that needs to be launched via an intent. - * - * @param intentFactory A lambda that provides a Context that can used to create an intent. A intent needs to be returned. - */ - inline fun createAndroidIntentComposeRule(intentFactory: (context: Context) -> Intent) : AndroidComposeTestRule, A> { - val context = ApplicationProvider.getApplicationContext() - val intent = intentFactory(context) - - return AndroidComposeTestRule( - activityRule = ActivityScenarioRule(intent), - activityProvider = { scenarioRule -> scenarioRule.getActivity() } - ) - } - - /** - * Gets the activity from a scenarioRule. - * - * https://androidx.tech/artifacts/compose.ui/ui-test-junit4/1.0.0-alpha11-source/androidx/compose/ui/test/junit4/AndroidComposeTestRule.kt.html - */ - fun ActivityScenarioRule.getActivity(): A { - var activity: A? = null - - scenario.onActivity { activity = it } - - return activity ?: throw IllegalStateException("Activity was not set in the ActivityScenarioRule!") - } -} \ No newline at end of file diff --git a/frontend/app/src/androidTest/java/com/example/speechbuddy/BackupSettingsScreenTest.kt b/frontend/app/src/androidTest/java/com/example/speechbuddy/BackupSettingsScreenTest.kt index 02d999cc..123aae4e 100644 --- a/frontend/app/src/androidTest/java/com/example/speechbuddy/BackupSettingsScreenTest.kt +++ b/frontend/app/src/androidTest/java/com/example/speechbuddy/BackupSettingsScreenTest.kt @@ -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 @@ -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 { - Intent(it, HomeActivity::class.java).apply { - putExtra("isTest", true) - } - } + val composeTestRule = createAndroidComposeRule() @Before fun setUp() { diff --git a/frontend/app/src/androidTest/java/com/example/speechbuddy/DisplaySettingsScreenTest.kt b/frontend/app/src/androidTest/java/com/example/speechbuddy/DisplaySettingsScreenTest.kt index 177c0a28..bd9667b7 100644 --- a/frontend/app/src/androidTest/java/com/example/speechbuddy/DisplaySettingsScreenTest.kt +++ b/frontend/app/src/androidTest/java/com/example/speechbuddy/DisplaySettingsScreenTest.kt @@ -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 @@ -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 @@ -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 { - Intent(it, HomeActivity::class.java).apply { - putExtra("isTest", true) - } - } + val composeTestRule = createAndroidComposeRule() @Before fun setUp() { diff --git a/frontend/app/src/androidTest/java/com/example/speechbuddy/GuestSettingsScreenTest.kt b/frontend/app/src/androidTest/java/com/example/speechbuddy/GuestSettingsScreenTest.kt index 03205887..47d676b3 100644 --- a/frontend/app/src/androidTest/java/com/example/speechbuddy/GuestSettingsScreenTest.kt +++ b/frontend/app/src/androidTest/java/com/example/speechbuddy/GuestSettingsScreenTest.kt @@ -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 @@ -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 { - Intent(it, HomeActivity::class.java).apply { - putExtra("isTest", true) - } - } + val composeTestRule = createAndroidComposeRule() @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@email.com" + val fakeNickname = "nickname" + composeTestRule.activity.sessionManager.setUserId(fakeId) + composeTestRule.activity.userRepository.setMyInfo(fakeId, fakeEmail, fakeNickname) composeTestRule.activity.setContent { SpeechBuddyTheme( settingsRepository = composeTestRule.activity.settingsRepository, diff --git a/frontend/app/src/androidTest/java/com/example/speechbuddy/MainSettingsScreenTest.kt b/frontend/app/src/androidTest/java/com/example/speechbuddy/MainSettingsScreenTest.kt index 3d76c7e4..3feaf9be 100644 --- a/frontend/app/src/androidTest/java/com/example/speechbuddy/MainSettingsScreenTest.kt +++ b/frontend/app/src/androidTest/java/com/example/speechbuddy/MainSettingsScreenTest.kt @@ -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 @@ -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 { - Intent(it, HomeActivity::class.java).apply { - putExtra("isTest", true) - } - } + val composeTestRule = createAndroidComposeRule() @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) diff --git a/frontend/app/src/main/java/com/example/speechbuddy/BaseActivity.kt b/frontend/app/src/main/java/com/example/speechbuddy/BaseActivity.kt index f923f6c6..e9acc6ec 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/BaseActivity.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/BaseActivity.kt @@ -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() { @@ -17,4 +18,7 @@ abstract class BaseActivity : AppCompatActivity() { @Inject lateinit var settingsRepository: SettingsRepository + @Inject + lateinit var userRepository: UserRepository + } \ No newline at end of file diff --git a/frontend/app/src/main/java/com/example/speechbuddy/repository/UserRepository.kt b/frontend/app/src/main/java/com/example/speechbuddy/repository/UserRepository.kt index 300f7213..c03f421b 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/repository/UserRepository.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/repository/UserRepository.kt @@ -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 @@ -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 returnUnknownError(): Resource { return Resource.error( "Unknown error", null