|
| 1 | +package to.bitkit.ui.screens.wallets.send |
| 2 | + |
| 3 | +import androidx.compose.ui.test.assertIsNotEnabled |
| 4 | +import androidx.compose.ui.test.junit4.createComposeRule |
| 5 | +import androidx.compose.ui.test.onNodeWithTag |
| 6 | +import androidx.compose.ui.test.performClick |
| 7 | +import org.junit.Rule |
| 8 | +import org.junit.Test |
| 9 | +import to.bitkit.models.BitcoinDisplayUnit |
| 10 | +import to.bitkit.models.NodeLifecycleState |
| 11 | +import to.bitkit.models.PrimaryDisplay |
| 12 | +import to.bitkit.viewmodels.CurrencyUiState |
| 13 | +import to.bitkit.viewmodels.MainUiState |
| 14 | +import to.bitkit.viewmodels.SendEvent |
| 15 | +import to.bitkit.viewmodels.SendMethod |
| 16 | +import to.bitkit.viewmodels.SendUiState |
| 17 | + |
| 18 | +class SendAmountContentTest { |
| 19 | + |
| 20 | + @get:Rule |
| 21 | + val composeTestRule = createComposeRule() |
| 22 | + |
| 23 | + private val testUiState = SendUiState( |
| 24 | + payMethod = SendMethod.LIGHTNING, |
| 25 | + amountInput = "100", |
| 26 | + isAmountInputValid = true, |
| 27 | + isUnified = true |
| 28 | + ) |
| 29 | + |
| 30 | + private val testWalletState = MainUiState( |
| 31 | + nodeLifecycleState = NodeLifecycleState.Running |
| 32 | + ) |
| 33 | + |
| 34 | + @Test |
| 35 | + fun whenScreenLoaded_shouldShowAllComponents() { |
| 36 | + composeTestRule.setContent { |
| 37 | + SendAmountContent( |
| 38 | + input = "100", |
| 39 | + uiState = testUiState, |
| 40 | + walletUiState = testWalletState, |
| 41 | + currencyUiState = CurrencyUiState(primaryDisplay = PrimaryDisplay.BITCOIN), |
| 42 | + displayUnit = BitcoinDisplayUnit.MODERN, |
| 43 | + primaryDisplay = PrimaryDisplay.BITCOIN, |
| 44 | + onInputChanged = {}, |
| 45 | + onEvent = {}, |
| 46 | + onBack = {} |
| 47 | + ) |
| 48 | + } |
| 49 | + |
| 50 | + composeTestRule.onNodeWithTag("send_amount_screen").assertExists() |
| 51 | +// composeTestRule.onNodeWithTag("amount_input_field").assertExists() doesn't displayed because of viewmodel injection |
| 52 | + composeTestRule.onNodeWithTag("available_balance").assertExists() |
| 53 | + composeTestRule.onNodeWithTag("payment_method_button").assertExists() |
| 54 | + composeTestRule.onNodeWithTag("continue_button").assertExists() |
| 55 | + composeTestRule.onNodeWithTag("amount_keyboard").assertExists() |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + fun whenNodeNotRunning_shouldShowSyncView() { |
| 60 | + composeTestRule.setContent { |
| 61 | + SendAmountContent( |
| 62 | + input = "100", |
| 63 | + uiState = testUiState, |
| 64 | + walletUiState = MainUiState( |
| 65 | + nodeLifecycleState = NodeLifecycleState.Initializing |
| 66 | + ), |
| 67 | + displayUnit = BitcoinDisplayUnit.MODERN, |
| 68 | + primaryDisplay = PrimaryDisplay.BITCOIN, |
| 69 | + currencyUiState = CurrencyUiState(), |
| 70 | + onInputChanged = {}, |
| 71 | + onEvent = {}, |
| 72 | + onBack = {} |
| 73 | + ) |
| 74 | + } |
| 75 | + |
| 76 | + composeTestRule.onNodeWithTag("sync_node_view").assertExists() |
| 77 | + composeTestRule.onNodeWithTag("amount_input_field").assertDoesNotExist() |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + fun whenPaymentMethodButtonClicked_shouldTriggerEvent() { |
| 82 | + var eventTriggered = false |
| 83 | + composeTestRule.setContent { |
| 84 | + SendAmountContent( |
| 85 | + input = "100", |
| 86 | + uiState = testUiState, |
| 87 | + walletUiState = testWalletState, |
| 88 | + currencyUiState = CurrencyUiState(), |
| 89 | + onInputChanged = {}, |
| 90 | + onEvent = { event -> |
| 91 | + if (event is SendEvent.PaymentMethodSwitch) { |
| 92 | + eventTriggered = true |
| 93 | + } |
| 94 | + }, |
| 95 | + displayUnit = BitcoinDisplayUnit.MODERN, |
| 96 | + primaryDisplay = PrimaryDisplay.BITCOIN, |
| 97 | + onBack = {} |
| 98 | + ) |
| 99 | + } |
| 100 | + |
| 101 | + composeTestRule.onNodeWithTag("payment_method_button") |
| 102 | + .performClick() |
| 103 | + |
| 104 | + assert(eventTriggered) |
| 105 | + } |
| 106 | + |
| 107 | + @Test |
| 108 | + fun whenContinueButtonClicked_shouldTriggerEvent() { |
| 109 | + var eventTriggered = false |
| 110 | + composeTestRule.setContent { |
| 111 | + SendAmountContent( |
| 112 | + input = "100", |
| 113 | + uiState = testUiState.copy(isAmountInputValid = true), |
| 114 | + walletUiState = testWalletState, |
| 115 | + currencyUiState = CurrencyUiState(), |
| 116 | + onInputChanged = {}, |
| 117 | + onEvent = { event -> |
| 118 | + if (event is SendEvent.AmountContinue) { |
| 119 | + eventTriggered = true |
| 120 | + } |
| 121 | + }, |
| 122 | + displayUnit = BitcoinDisplayUnit.MODERN, |
| 123 | + primaryDisplay = PrimaryDisplay.BITCOIN, |
| 124 | + onBack = {} |
| 125 | + ) |
| 126 | + } |
| 127 | + |
| 128 | + composeTestRule.onNodeWithTag("continue_button") |
| 129 | + .performClick() |
| 130 | + |
| 131 | + assert(eventTriggered) |
| 132 | + } |
| 133 | + |
| 134 | + @Test |
| 135 | + fun whenAmountInvalid_continueButtonShouldBeDisabled() { |
| 136 | + composeTestRule.setContent { |
| 137 | + SendAmountContent( |
| 138 | + input = "100", |
| 139 | + uiState = testUiState.copy(isAmountInputValid = false), |
| 140 | + walletUiState = testWalletState, |
| 141 | + currencyUiState = CurrencyUiState(), |
| 142 | + onInputChanged = {}, |
| 143 | + onEvent = {}, |
| 144 | + displayUnit = BitcoinDisplayUnit.MODERN, |
| 145 | + primaryDisplay = PrimaryDisplay.BITCOIN, |
| 146 | + onBack = {} |
| 147 | + ) |
| 148 | + } |
| 149 | + |
| 150 | + composeTestRule.onNodeWithTag("continue_button").assertIsNotEnabled() |
| 151 | + } |
| 152 | +} |
0 commit comments