-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivityTests.kt
87 lines (66 loc) · 2.39 KB
/
MainActivityTests.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.example.muzzapp
import androidx.test.core.app.ActivityScenario.launch
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.appcompat.widget.Toolbar
import androidx.test.espresso.action.ViewActions.*
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import com.example.muzzapp.util.*
import org.junit.After
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
import org.junit.Before
import org.junit.BeforeClass
@RunWith(AndroidJUnit4::class)
class MainActivityTests {
companion object {
private lateinit var uiDevice: UiDevice
@BeforeClass
@JvmStatic
fun setDevicePreferences() {
//set up animations settings = off
uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
uiDevice.executeShellCommand(ANIMATION_OFF)
uiDevice.executeShellCommand(TRANS_ANIMATION_OFF)
uiDevice.executeShellCommand(WIN_ANIMATION_OFF)
}
}
@Before
fun setUp() {
ServiceLocator.resetRepository()
}
@After
fun tearDown() {
ServiceLocator.resetRepository()
}
@Test
fun isToolbarTitleDisplayed() {
val scenario = launch(MainActivity::class.java)
onView(isAssignableFrom(Toolbar::class.java)).check(matches(hasDescendant(withText(R.string.frag_title_user_name_you))))
scenario.close()
}
@Test
fun sender_user_types_hello_displays_Hello_In_Chat_Window() {
val scenario = launch(MainActivity::class.java)
editMessageBox.typetext("Hello")
sendButton.click()
chatRecyclerView
.check(matches(hasDescendant(withText("Hello"))))
scenario.close()
}
@Test
fun other_user_types_message_displays_the_message() {
val scenario = launch(MainActivity::class.java)
//change to Other User
menuSwitchUser.click()
onView(isAssignableFrom(Toolbar::class.java)).check(matches(hasDescendant(withText(R.string.frag_title_user_name_me))))
editMessageBox.typetext("Hello")
sendButton.click()
onView(withText("Hello")).check(matches(isDisplayed()))
scenario.close()
}
}