Skip to content

Commit

Permalink
✅ Implement BackupSettigsScreenTest
Browse files Browse the repository at this point in the history
  • Loading branch information
89645321 committed Dec 2, 2023
1 parent d16e3c0 commit 58e5b88
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class AccountSettingsScreenTest {
}

@Test
fun should_display_loading_indicator_when_clicking_backup_button_in_backup_dialog() {
fun should_remove_dialog_when_clicking_backup_button_in_backup_dialog() {
composeTestRule.onNodeWithText(LOGOUT).performClick()
composeTestRule.onNodeWithText(BACKUP).performClick()
composeTestRule.onNodeWithText(BACKUP_DIALOG).assertDoesNotExist()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.example.speechbuddy.compose.settings.BackupSettings
import com.example.speechbuddy.ui.SpeechBuddyTheme
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Before
import org.junit.Rule
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)
}
}

@Before
fun setUp() {
hiltRule.inject()
composeTestRule.activity.setContent {
SpeechBuddyTheme(
settingsRepository = composeTestRule.activity.settingsRepository,
initialDarkMode = false
) {
BackupSettings(
paddingValues = PaddingValues()
)
}
}
}

@Test
fun should_display_all_elements_when_account_settings_screen_appears() {
composeTestRule.onNodeWithText(BACKUP_TO_SERVER).assertIsDisplayed()
composeTestRule.onNodeWithText(LAST_BACKUP_DATE).assertIsDisplayed()
composeTestRule.onNodeWithText(ENABLE_AUTO_BACKUP).assertIsDisplayed()
composeTestRule.onNodeWithText(BACKUP_NOW).assertIsDisplayed().assertIsEnabled().assertHasClickAction()
composeTestRule.onNodeWithTag("auto_backup").assertIsDisplayed().assertIsEnabled()
}

@Test
fun should_change_auto_backup_when_switch_is_clicked() {
composeTestRule.onNodeWithTag("auto_backup").assertIsOn()
composeTestRule.onNodeWithTag("auto_backup").performClick()
composeTestRule.onNodeWithTag("auto_backup").assertIsOff()
composeTestRule.onNodeWithTag("auto_backup").performClick()
composeTestRule.onNodeWithTag("auto_backup").assertIsOn()
}

@Test
fun should_show_loading_indicator_when_backup_is_clicked() {
composeTestRule.onNodeWithText(BACKUP_NOW).performClick()
composeTestRule.onNodeWithTag("backup_loading").assertIsDisplayed()
}

companion object {
const val BACKUP_TO_SERVER = "서버에 백업하기"
const val LAST_BACKUP_DATE = "마지막 백업 날짜"
const val ENABLE_AUTO_BACKUP = "자동 백업 활성화"
const val BACKUP_NOW = "지금 백업하기"

val LIGHT_COLOR = Color(0xFF000000)
val DARK_COLOR = Color(0xFFFFFFFF)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.assertIsNotSelected
import androidx.compose.ui.test.assertIsOff
import androidx.compose.ui.test.assertIsOn
Expand Down Expand Up @@ -59,6 +60,9 @@ class DisplaySettingsScreenTest {
composeTestRule.onNodeWithText(INITIAL_PAGE).assertIsDisplayed()
composeTestRule.onNodeWithText(SYMBOL).assertIsDisplayed()
composeTestRule.onNodeWithText(TTS).assertIsDisplayed()
composeTestRule.onNodeWithTag("dark_mode").assertIsDisplayed().assertIsEnabled()
composeTestRule.onNodeWithTag("initial_page_symbol").assertIsDisplayed().assertIsEnabled()
composeTestRule.onNodeWithTag("initial_page_tts").assertIsDisplayed().assertIsEnabled()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
Expand Down Expand Up @@ -70,7 +71,7 @@ fun BackupSettings(
Switch(
checked = uiState.isAutoBackupEnabled,
onCheckedChange = { viewModel.setAutoBackup(it) },
modifier = Modifier.heightIn(max = 32.dp),
modifier = Modifier.heightIn(max = 32.dp).testTag("auto_backup"),
enabled = uiState.buttonEnabled
)
}
Expand Down Expand Up @@ -117,6 +118,7 @@ fun BackupSettings(
modifier = Modifier
.fillMaxSize()
.wrapContentSize()
.testTag("backup_loading")
)
}
}
Expand Down

0 comments on commit 58e5b88

Please sign in to comment.