-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathOverlayUiTest.kt
More file actions
61 lines (52 loc) · 1.58 KB
/
OverlayUiTest.kt
File metadata and controls
61 lines (52 loc) · 1.58 KB
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
// Copyright (C) 2024 Slack Technologies, LLC
// SPDX-License-Identifier: Apache-2.0
package com.slack.circuit.overlay
import androidx.compose.material.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.junit4.v2.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import com.slack.circuit.overlay.OverlayState.HIDDEN
import com.slack.circuit.overlay.OverlayState.SHOWING
import kotlin.test.Test
import org.junit.Rule
private const val OVERLAY_STATE_TAG = "overlay_state"
class OverlayUiTest {
@get:Rule val compose = createComposeRule()
@Test
fun overlayStateLifecycle() {
var shouldShow by mutableStateOf(false)
compose.setContent {
ContentWithOverlays {
if (shouldShow) {
OverlayEffect {
show(TestOverlay())
shouldShow = false
}
}
Text(
text = "State: ${LocalOverlayState.current}",
modifier = Modifier.testTag(OVERLAY_STATE_TAG),
)
}
}
fun assertState(expected: OverlayState) {
compose.onNodeWithTag(OVERLAY_STATE_TAG).assertTextContains("State: $expected")
}
repeat(3) {
println("Iteration $it")
// Initial state
assertState(HIDDEN)
// Show it
shouldShow = true
assertState(SHOWING)
// Hide it again
shouldShow = false
assertState(HIDDEN)
}
}
}