Skip to content

Commit

Permalink
Fixing UI test in settings activity (#360)
Browse files Browse the repository at this point in the history
* Fixing UI test for clicking log out in settings

* fixing broken UI tests
  • Loading branch information
eoji committed Oct 23, 2018
1 parent 7298de4 commit fd07e72
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/src/androidTest/kotlin/SettingsActivityTest.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import android.content.Intent
import android.support.test.espresso.intent.Intents
import android.support.test.espresso.intent.Intents.intended
Expand Down Expand Up @@ -43,6 +44,7 @@ class SettingsActivityTest {
@Test
fun testLogoutClick() {
events.clickOnView(R.id.log_out_row)
events.clickOnButtonInDialog("Log out")
checkThat.nextOpenActivityIs(DiscoveryActivity::class.java)
}

Expand Down
13 changes: 11 additions & 2 deletions app/src/androidTest/kotlin/utils/Events.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package utils
import android.support.annotation.IdRes
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.matcher.ViewMatchers.*
import android.support.test.espresso.action.ViewActions.click
import android.support.test.espresso.matcher.RootMatchers.isDialog
import android.support.test.espresso.matcher.ViewMatchers.withId
import android.support.test.espresso.matcher.ViewMatchers.withText
import android.widget.Button
import org.hamcrest.core.AllOf.allOf
import org.hamcrest.core.IsInstanceOf.instanceOf

class Events {

fun clickOnView(@IdRes viewId: Int) {
onView(withId(viewId)).perform(click())
}
}

fun clickOnButtonInDialog(text: String) {
onView(allOf(instanceOf(Button::class.java), withText(text))).inRoot(isDialog()).perform(click())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.kickstarter.libs.rx.transformers.Transformers.takePairWhen
import com.kickstarter.libs.rx.transformers.Transformers.takeWhen
import com.kickstarter.libs.utils.BooleanUtils.isTrue
import com.kickstarter.libs.utils.ListUtils
import com.kickstarter.libs.utils.ObjectUtils
import com.kickstarter.libs.utils.UserUtils
import com.kickstarter.models.User
import com.kickstarter.ui.activities.NewsletterActivity
Expand Down Expand Up @@ -92,12 +93,15 @@ interface NewsletterViewModel {
.compose(bindToLifecycle())
.subscribe(this.currentUser::refresh)

this.currentUser.observable()
val currentUser = this.currentUser.observable()
.filter { ObjectUtils.isNotNull(it) }

currentUser
.take(1)
.compose(bindToLifecycle())
.subscribe(this.userOutput::onNext)

this.currentUser.observable()
currentUser
.compose<Pair<User, Pair<Boolean, Newsletter>>>(takePairWhen<User, Pair<Boolean, Newsletter>>(this.newsletterInput))
.filter { us -> requiresDoubleOptIn(us.first, us.second.first) }
.map { us -> us.second.second }
Expand All @@ -109,7 +113,7 @@ interface NewsletterViewModel {
.compose(bindToLifecycle())
.subscribe(this.koala::trackNewsletterToggle)

this.currentUser.observable()
currentUser
.map { isSubscribedToAllNewsletters(it) }
.compose(bindToLifecycle())
.subscribe(this.subscribeAll::onNext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.kickstarter.libs.rx.transformers.Transformers
import com.kickstarter.libs.rx.transformers.Transformers.takeWhen
import com.kickstarter.libs.utils.IntegerUtils
import com.kickstarter.libs.utils.ListUtils
import com.kickstarter.libs.utils.ObjectUtils
import com.kickstarter.models.User
import com.kickstarter.services.ApiClientType
import com.kickstarter.ui.activities.NotificationsActivity
Expand Down Expand Up @@ -112,6 +113,7 @@ interface NotificationsViewModel {
.subscribe { this.currentUser.refresh(it) }

val currentUser = this.currentUser.observable()
.filter { ObjectUtils.isNotNull(it) }

currentUser
.take(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ interface PrivacyViewModel {

currentUser
.take(1)
.filter { ObjectUtils.isNotNull(it) }
.compose(bindToLifecycle())
.subscribe({ this.userOutput.onNext(it) })

Expand Down

0 comments on commit fd07e72

Please sign in to comment.