forked from hitherejoe/ComposeAcademy-Playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssertOnOffTests.kt
47 lines (39 loc) · 1.08 KB
/
AssertOnOffTests.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
package co.joebirch.composeplayground.assertions
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.ui.core.TestTag
import androidx.ui.layout.Stack
import androidx.ui.material.MaterialTheme
import androidx.ui.material.Surface
import androidx.ui.material.Switch
import androidx.ui.test.*
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Rule
@RunWith(AndroidJUnit4::class)
class AssertOnOffTests {
@get:Rule
val composeTestRule = createComposeRule()
private fun launchContent(isOn: Boolean) {
composeTestRule.setContent {
MaterialTheme {
Surface {
Stack {
TestTag(tag = "MyTag") {
Switch(checked = isOn, onCheckedChange = { })
}
}
}
}
}
}
@Test
fun testExists() {
launchContent(true)
findByTag("MyTag").assertIsOn()
}
@Test
fun testNotExists() {
launchContent(false)
findByTag("MyTag").assertIsOff()
}
}