Skip to content

Commit 6fc5faa

Browse files
committed
test: SendAmountContentTest
1 parent 4520b3b commit 6fc5faa

File tree

1 file changed

+141
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)