-
Notifications
You must be signed in to change notification settings - Fork 629
/
LinkAppBarTest.kt
69 lines (58 loc) · 2.07 KB
/
LinkAppBarTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.stripe.android.link.ui
import androidx.activity.ComponentActivity
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import com.stripe.android.link.R
import com.stripe.android.link.theme.DefaultLinkTheme
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
internal class LinkAppBarTest {
@get:Rule
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
@Test
fun email_is_shown_when_provided() {
val email = "test@stripe.com"
setContent(email)
composeTestRule.onNodeWithText(email).assertExists()
}
@Test
fun on_back_button_click_callback_is_called() {
var count = 0
setContent(onBackPress = { count++ })
composeTestRule.onNodeWithContentDescription("Back").performClick()
assertThat(count).isEqualTo(1)
}
@Test
fun on_overflow_button_click_callback_is_called() {
var count = 0
setContent(showBottomSheetContent = { count++ })
composeTestRule.onNodeWithContentDescription("Menu").performClick()
assertThat(count).isEqualTo(1)
}
private fun setContent(
email: String? = null,
onBackPress: () -> Unit = {},
onLogout: () -> Unit = {},
showBottomSheetContent: (BottomSheetContent?) -> Unit = {}
) = composeTestRule.setContent {
DefaultLinkTheme {
LinkAppBar(
state = LinkAppBarState(
navigationIcon = R.drawable.ic_link_close,
showHeader = true,
showOverflowMenu = true,
email = email
),
onBackPress = onBackPress,
onLogout = onLogout,
showBottomSheetContent = showBottomSheetContent
)
}
}
}