-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoginTest.kt
57 lines (44 loc) · 1.9 KB
/
LoginTest.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
package cat.helm.basearchitecture
import android.support.test.espresso.Espresso
import android.support.test.espresso.Espresso.closeSoftKeyboard
import android.support.test.espresso.action.ViewActions.click
import android.support.test.espresso.action.ViewActions.typeText
import android.support.test.espresso.assertion.ViewAssertions
import android.support.test.espresso.matcher.ViewMatchers
import android.support.test.rule.ActivityTestRule
import cat.helm.basearchitecture.customMatcher.ToastMatcher
import cat.helm.basearchitecture.repository.LoginRepository
import cat.helm.basearchitecture.ui.main.MainActivity
import org.junit.Rule
import org.junit.Test
import org.mockito.Mock
import org.mockito.Mockito.`when`
/**
* Created by Héctor on 21/12/2017.
*/
class LoginTest {
@get:Rule
val rule = EspressoDaggerMockRule()
@Rule
@JvmField
var activityRule = ActivityTestRule(MainActivity::class.java, false, false)
@Mock
lateinit var repo: LoginRepository
// @Test
// fun userShouldNotLoginWithEmptyCredentials() {
//
// Espresso.onView(ViewMatchers.withId(R.id.loginButton)).perform(click())
// Espresso.onView(ViewMatchers.withText("Email and password should be filled")).inRoot(ToastMatcher()).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
// }
@Test
fun a() {
`when`(repo.login("username","password")).thenReturn(Result.of { "pastel" })
activityRule.launchActivity(null)
Espresso.onView(ViewMatchers.withId(R.id.username)).perform(typeText("user"))
closeSoftKeyboard()
Espresso.onView(ViewMatchers.withId(R.id.password)).perform(typeText("password"))
closeSoftKeyboard()
Espresso.onView(ViewMatchers.withId(R.id.loginButton)).perform(click())
Espresso.onView(ViewMatchers.withText("token: pastel")).inRoot(ToastMatcher()).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
}
}