|
| 1 | +package org.kabiri.android.usbterminal.ui.setting |
| 2 | + |
| 3 | +import androidx.activity.ComponentActivity |
| 4 | +import androidx.compose.ui.test.assertIsDisplayed |
| 5 | +import androidx.compose.ui.test.junit4.createAndroidComposeRule |
| 6 | +import androidx.compose.ui.test.onNodeWithText |
| 7 | +import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 8 | +import io.mockk.every |
| 9 | +import io.mockk.mockk |
| 10 | +import kotlinx.coroutines.flow.flowOf |
| 11 | +import org.hamcrest.CoreMatchers.notNullValue |
| 12 | +import org.hamcrest.MatcherAssert.assertThat |
| 13 | +import org.junit.Rule |
| 14 | +import org.junit.Test |
| 15 | +import org.junit.runner.RunWith |
| 16 | +import org.kabiri.android.usbterminal.R |
| 17 | +import org.kabiri.android.usbterminal.ui.theme.UsbTerminalTheme |
| 18 | + |
| 19 | +@RunWith(AndroidJUnit4::class) |
| 20 | +class SettingContentAndroidTest { |
| 21 | + @get:Rule |
| 22 | + val composeRule = createAndroidComposeRule<ComponentActivity>() |
| 23 | + |
| 24 | + private fun showContet(viewModel: SettingViewModel) { |
| 25 | + composeRule.setContent { |
| 26 | + UsbTerminalTheme { |
| 27 | + SettingContent( |
| 28 | + settingViewModel = viewModel, |
| 29 | + onDismiss = {}, |
| 30 | + ) |
| 31 | + } |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + fun settingContent_displaysExpectedTexts() { |
| 37 | + // arrange |
| 38 | + val context = composeRule.activity |
| 39 | + assertThat(context, notNullValue()) |
| 40 | + val viewModel = mockk<SettingViewModel>(relaxed = true) |
| 41 | + every { viewModel.currentBaudRate } returns flowOf(9600) |
| 42 | + every { viewModel.currentAutoScroll } returns flowOf(true) |
| 43 | + |
| 44 | + // act |
| 45 | + showContet(viewModel) |
| 46 | + |
| 47 | + // assert |
| 48 | + composeRule.onNodeWithText(context.getString(R.string.settings_title)).assertIsDisplayed() |
| 49 | + composeRule |
| 50 | + .onNodeWithText(context.getString(R.string.settings_subtitle)) |
| 51 | + .assertIsDisplayed() |
| 52 | + |
| 53 | + // Baud rate label (ensure unmerged tree so label is found) |
| 54 | + composeRule |
| 55 | + .onNodeWithText( |
| 56 | + context.getString(R.string.settings_label_baud_rate), |
| 57 | + useUnmergedTree = true, |
| 58 | + ).assertIsDisplayed() |
| 59 | + |
| 60 | + // Buttons and bottom text |
| 61 | + composeRule |
| 62 | + .onNodeWithText(context.getString(R.string.settings_bt_reset_default)) |
| 63 | + .assertIsDisplayed() |
| 64 | + composeRule |
| 65 | + .onNodeWithText(context.getString(R.string.settings_bt_dismiss_sheet)) |
| 66 | + .assertIsDisplayed() |
| 67 | + composeRule |
| 68 | + .onNodeWithText(context.getString(R.string.settings_bottom_text)) |
| 69 | + .assertIsDisplayed() |
| 70 | + |
| 71 | + // Auto-scroll label |
| 72 | + composeRule |
| 73 | + .onNodeWithText(context.getString(R.string.settings_label_auto_scroll)) |
| 74 | + .assertIsDisplayed() |
| 75 | + } |
| 76 | +} |
0 commit comments