|
| 1 | +package to.bitkit.ui.components |
| 2 | + |
| 3 | +import androidx.compose.ui.test.* |
| 4 | +import androidx.compose.ui.test.junit4.createComposeRule |
| 5 | +import dagger.hilt.android.testing.HiltAndroidRule |
| 6 | +import dagger.hilt.android.testing.HiltAndroidTest |
| 7 | +import org.junit.Before |
| 8 | +import org.junit.Rule |
| 9 | +import org.junit.Test |
| 10 | + |
| 11 | +@HiltAndroidTest |
| 12 | +class KeyboardTest { |
| 13 | + |
| 14 | + @get:Rule |
| 15 | + val composeTestRule = createComposeRule() |
| 16 | + |
| 17 | + @get:Rule |
| 18 | + val hiltRule = HiltAndroidRule(this) |
| 19 | + |
| 20 | + @Before |
| 21 | + fun setup() { |
| 22 | + hiltRule.inject() |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + fun keyboard_displaysAllButtons() { |
| 27 | + composeTestRule.setContent { |
| 28 | + Keyboard(onClick = {}) |
| 29 | + } |
| 30 | + |
| 31 | + composeTestRule.onNodeWithTag("KeyboardButton_1").assertIsDisplayed() |
| 32 | + composeTestRule.onNodeWithTag("KeyboardButton_2").assertIsDisplayed() |
| 33 | + composeTestRule.onNodeWithTag("KeyboardButton_3").assertIsDisplayed() |
| 34 | + composeTestRule.onNodeWithTag("KeyboardButton_4").assertIsDisplayed() |
| 35 | + composeTestRule.onNodeWithTag("KeyboardButton_5").assertIsDisplayed() |
| 36 | + composeTestRule.onNodeWithTag("KeyboardButton_6").assertIsDisplayed() |
| 37 | + composeTestRule.onNodeWithTag("KeyboardButton_7").assertIsDisplayed() |
| 38 | + composeTestRule.onNodeWithTag("KeyboardButton_8").assertIsDisplayed() |
| 39 | + composeTestRule.onNodeWithTag("KeyboardButton_9").assertIsDisplayed() |
| 40 | + composeTestRule.onNodeWithTag("KeyboardButton_.").assertIsDisplayed() |
| 41 | + composeTestRule.onNodeWithTag("KeyboardButton_0").assertIsDisplayed() |
| 42 | + composeTestRule.onNodeWithTag("KeyboardButton_").assertIsDisplayed() |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + fun keyboard_tripleZero_when_not_decimal() { |
| 47 | + composeTestRule.setContent { |
| 48 | + Keyboard(onClick = {}, isDecimal = false) |
| 49 | + } |
| 50 | + composeTestRule.onNodeWithTag("KeyboardButton_000").assertIsDisplayed() |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + fun keyboard_decimal_when_decimal() { |
| 55 | + composeTestRule.setContent { |
| 56 | + Keyboard(onClick = {}, isDecimal = true) |
| 57 | + } |
| 58 | + composeTestRule.onNodeWithTag("KeyboardButton_.").assertIsDisplayed() |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + fun keyboard_button_click_triggers_callback() { |
| 63 | + var clickedValue = "" |
| 64 | + composeTestRule.setContent { |
| 65 | + Keyboard(onClick = { clickedValue = it }) |
| 66 | + } |
| 67 | + |
| 68 | + composeTestRule.onNodeWithTag("KeyboardButton_5").performClick() |
| 69 | + assert(clickedValue == "5") |
| 70 | + |
| 71 | + composeTestRule.onNodeWithTag("KeyboardButton_.").performClick() |
| 72 | + assert(clickedValue == ".") |
| 73 | + |
| 74 | + composeTestRule.onNodeWithTag("KeyboardButton_0").performClick() |
| 75 | + assert(clickedValue == "0") |
| 76 | + |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + fun keyboard_button_click_tripleZero() { |
| 81 | + var clickedValue = "" |
| 82 | + composeTestRule.setContent { |
| 83 | + Keyboard(onClick = { clickedValue = it }, isDecimal = false) |
| 84 | + } |
| 85 | + |
| 86 | + composeTestRule.onNodeWithTag("KeyboardButton_000").performClick() |
| 87 | + assert(clickedValue == "000") |
| 88 | + } |
| 89 | + |
| 90 | +} |
0 commit comments