Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/integration others #119

Merged
merged 11 commits into from
Dec 9, 2023
2 changes: 2 additions & 0 deletions frontend/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ dependencies {
implementation("com.squareup.retrofit2:retrofit:$retrofitVersion")
implementation("com.squareup.retrofit2:converter-moshi:$retrofitVersion")
implementation("com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.1")
androidTestImplementation("com.squareup.retrofit2:retrofit:$retrofitVersion")
androidTestImplementation("com.squareup.retrofit2:converter-gson:$retrofitVersion")

// Gson
implementation("com.google.code.gson:gson:2.9.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class EmailVerificationScreenForResetPWTest {
// inputs
const val INVALID_EMAIL = "invalidemail"
const val UNREGISTERED_EMAIL_EXAMPLE = "[email protected]"
const val REGISTERED_EMAIL = "[email protected]"
const val REGISTERED_EMAIL = "[email protected]"
const val INVALID_CODE = "invalid"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class EmailVerificationScreenForSignupTest {
composeTestRule.onNodeWithText(EMAIL).performTextInput(ALREADY_TAKEN_EMAIL)
composeTestRule.onNodeWithText(SEND_CODE).performClick()
// wait for server's response
Thread.sleep(5000)
Thread.sleep(10000)

composeTestRule.onNodeWithText(EMAIL_ALREADY_TAKEN).assertIsDisplayed()
composeTestRule.onNodeWithText(NEXT).assertIsDisplayed().assertHasClickAction().assertIsNotEnabled()
Expand Down Expand Up @@ -135,7 +135,7 @@ class EmailVerificationScreenForSignupTest {

// inputs
const val INVALID_EMAIL = "invalidemail"
const val ALREADY_TAKEN_EMAIL = "[email protected]"
const val ALREADY_TAKEN_EMAIL = "[email protected]"
const val VALID_EMAIL = "[email protected]"
const val INVALID_CODE = "invalid"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
package com.example.speechbuddy

import android.content.Context
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.room.Room
import androidx.test.core.app.ApplicationProvider
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import com.example.speechbuddy.compose.settings.MySymbolSettings
import com.example.speechbuddy.data.local.AppDatabase
import com.example.speechbuddy.data.local.CategoryDao
import com.example.speechbuddy.data.local.SymbolDao
import com.example.speechbuddy.data.local.WeightRowDao
import com.example.speechbuddy.data.local.models.CategoryMapper
import com.example.speechbuddy.data.local.models.SymbolEntity
import com.example.speechbuddy.data.local.models.SymbolMapper
import com.example.speechbuddy.data.remote.MySymbolRemoteSource
import com.example.speechbuddy.data.remote.ProxyImageDownloader
import com.example.speechbuddy.data.remote.RealImageDownloader
import com.example.speechbuddy.data.remote.models.MySymbolDtoMapper
import com.example.speechbuddy.domain.SessionManager
import com.example.speechbuddy.domain.utils.Converters
import com.example.speechbuddy.repository.SymbolRepository
import com.example.speechbuddy.repository.WeightTableRepository
import com.example.speechbuddy.service.BackupService
import com.example.speechbuddy.service.SymbolCreationService
import com.example.speechbuddy.ui.SpeechBuddyTheme
import com.example.speechbuddy.utils.ResponseHandler
import com.example.speechbuddy.viewmodel.MySymbolSettingsViewModel
import com.example.speechbuddy.worker.SeedDatabaseWorker
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory


@HiltAndroidTest
class MySymbolSettingsScreenTest {

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

@get:Rule(order = 1)
val composeTestRule = createAndroidComposeRule<AuthActivity>()

// Room database instance
private lateinit var database: AppDatabase
private lateinit var symbolDao: SymbolDao
private lateinit var categoryDao: CategoryDao
private lateinit var weightRowDao: WeightRowDao

val retrofit = Retrofit.Builder()
.baseUrl("https://speechbuddy-1.herokuapp.com/")
.addConverterFactory(GsonConverterFactory.create())
.build()

val backupService = retrofit.create(BackupService::class.java)
val symbolCreationService = retrofit.create(SymbolCreationService::class.java)

@Before
fun setUp() {
hiltRule.inject()

val context = ApplicationProvider.getApplicationContext<Context>()
// val worker = SeedDatabaseWorker(context, WorkerParameters.DEFAULT)
val path = context.getDatabasePath("speechbuddy-db")

database = Room.databaseBuilder(
context,
AppDatabase::class.java,
path.toString()
).build()

symbolDao = database.symbolDao()
categoryDao = database.categoryDao()
weightRowDao = database.weightRowDao()

runBlocking {
val request = OneTimeWorkRequestBuilder<SeedDatabaseWorker>().build()
WorkManager.getInstance(context).enqueue(request)
Thread.sleep(5000)

val symbolEntity = symbolDao.getSymbolById(1)
val symbol = SymbolMapper().mapToDomainModel(symbolEntity.first())
symbolDao.updateSymbol(
SymbolMapper().mapFromDomainModel(
symbol.copy(
isMine = false,
isFavorite = true
)
)
)
symbolDao.insertSymbol(
SymbolEntity(
id = 1000,
text = "test",
imageUrl = null,
categoryId = 1,
isFavorite = false,
isMine = true
)
)
}

composeTestRule.activity.setContent {
SpeechBuddyTheme(
settingsRepository = composeTestRule.activity.settingsRepository,
initialDarkMode = false
) {
MySymbolSettings(
paddingValues = PaddingValues(),
viewModel = MySymbolSettingsViewModel(
weightTableRepository = WeightTableRepository(
symbolDao = symbolDao,
weightRowDao = weightRowDao,
converters = Converters(),
),
symbolRepository = SymbolRepository(
symbolDao = symbolDao,
categoryDao = categoryDao,
mySymbolRemoteSource = MySymbolRemoteSource(
symbolCreationService = symbolCreationService,
responseHandler = ResponseHandler()
),
proxyImageDownloader = ProxyImageDownloader(
realImageDownloader = RealImageDownloader(
backupService = backupService,
context = context

),
context = context

),
mySymbolDtoMapper = MySymbolDtoMapper(),
symbolMapper = SymbolMapper(),
categoryMapper = CategoryMapper(),
sessionManager = SessionManager(),
responseHandler = ResponseHandler()
),
)
)
}
}
}

@Test
fun should_display_all_elements_when_mysybolsettings_screen_appears() {
composeTestRule.onNodeWithText(SEARCH_BOX_TEXT).assertIsDisplayed()
composeTestRule.onNodeWithText(MY_SYMBOL_MENU_TEXT).assertIsDisplayed()

composeTestRule.onNodeWithText(FAVORITES_MENU_TEXT).assertIsDisplayed()
composeTestRule.onNodeWithText(DELETE_TEXT).assertIsDisplayed()
}

@Test
fun should_display_proper_symbols_when_in_MY_SYMBOL_MODE() {
composeTestRule.onNodeWithText(TEST_SYMBOL_TEXT_FOR_CREATION).assertIsDisplayed()
}

@Test
fun should_display_proper_symbols_when_in_FAVORITES_MODE() {
composeTestRule.onNodeWithText(FAVORITES_MENU_TEXT).performClick()
composeTestRule.waitForIdle()
composeTestRule.onNodeWithText(TEST_SYMBOL_TEXT_FOR_FAVORITE).assertIsDisplayed()
}


//

companion object {
const val SEARCH_BOX_TEXT = "검색어를 입력하세요"
const val MY_SYMBOL_MENU_TEXT = "내가 만든 상징"
const val FAVORITES_MENU_TEXT = "즐겨찾기"
const val DELETE_TEXT = "삭제"
const val TEST_SYMBOL_TEXT_FOR_CREATION = "test"
const val TEST_SYMBOL_TEXT_FOR_FAVORITE = "119에 전화해주세요"

}

}
Loading