Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #58 from Alviere/swipe_refresh_layout
Browse files Browse the repository at this point in the history
SwipeRefreshLayout support added
  • Loading branch information
cdsap authored Nov 16, 2017
2 parents ba9cedc + f88bc4e commit 8c4635a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
25 changes: 25 additions & 0 deletions kakao/src/main/kotlin/com/agoda/kakao/Actions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.support.test.espresso.web.model.Atom
import android.support.test.espresso.web.model.ElementReference
import android.support.test.espresso.web.sugar.Web
import android.support.test.espresso.web.webdriver.DriverAtoms
import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.RecyclerView
import android.view.Gravity
import android.view.InputDevice
Expand Down Expand Up @@ -657,6 +658,30 @@ interface TabLayoutActions : BaseActions {
}
}

/**
* Provides actions for SwipeRefreshLayout
*/
interface SwipeRefreshLayoutActions : SwipeableActions {
/**
* Sets the refreshing state of SwipeRefreshLayout
*
* @param refreshing state to be set
*/
fun setRefreshing(refreshing: Boolean) {
view.perform(object : ViewAction {
override fun getDescription() = "Sets the refreshing state to $refreshing"

override fun getConstraints() = ViewMatchers.isAssignableFrom(SwipeRefreshLayout::class.java)

override fun perform(uiController: UiController, view: View) {
if (view is SwipeRefreshLayout) {
view.isRefreshing = refreshing
}
}
})
}
}

/**
* Provides action for interacting with WebViews
*
Expand Down
19 changes: 19 additions & 0 deletions kakao/src/main/kotlin/com/agoda/kakao/Assertions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,25 @@ interface ImageViewAssertions : BaseAssertions {
}
}

/**
* Provides assertion for SwipeRefreshLayout
*/
interface SwipeRefreshLayoutAssertions : BaseAssertions {
/**
* Checks if the SwipeRefreshLayout is refreshing
*/
fun isRefreshing() {
view.check(ViewAssertions.matches(SwipeRefreshLayoutMatcher(true)))
}

/**
* Checks if the SwipeRefreshLayout is not refreshing
*/
fun isNotRefresing() {
view.check(ViewAssertions.matches(SwipeRefreshLayoutMatcher(false)))
}
}

/**
* Provides assertion for BottomNavigationview
*/
Expand Down
16 changes: 16 additions & 0 deletions kakao/src/main/kotlin/com/agoda/kakao/Matchers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import android.support.test.espresso.matcher.BoundedMatcher
import android.support.v4.content.ContextCompat
import android.support.v4.graphics.drawable.DrawableCompat
import android.support.v4.view.ViewPager
import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.ImageView
Expand Down Expand Up @@ -339,3 +340,18 @@ class BackgroundColorMatcher(@ColorRes private val resId: Int = -1,
description.appendText("with background color: $resId or $colorCode")
}
}

class SwipeRefreshLayoutMatcher(private val refreshing: Boolean) : TypeSafeMatcher<View>() {
override fun matchesSafely(item: View?): Boolean {
return item?.let {
if (item is SwipeRefreshLayout) {
item.isRefreshing == refreshing
} else false
} ?: false
}

override fun describeTo(desc: Description) {
desc.appendText("with refreshing state: ")
.appendValue(refreshing)
}
}
12 changes: 12 additions & 0 deletions kakao/src/main/kotlin/com/agoda/kakao/Views.kt
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ class KTabLayout : KBaseView<KTabLayout>, TabLayoutActions, TabLayoutAssertions
constructor(parent: DataInteraction, function: ViewBuilder.() -> Unit) : super(parent, function)
}

/**
* View with SwipeRefreshLayoutActions and SwipeRefreshLayoutAssertions
*
* @see SwipeRefreshLayoutActions
* @see SwipeRefreshLayoutAssertions
*/
class KSwipeRefreshLayout : KBaseView<KSwipeRefreshLayout>, SwipeRefreshLayoutActions, SwipeRefreshLayoutAssertions {
constructor(function: ViewBuilder.() -> Unit) : super(function)
constructor(parent: Matcher<View>, function: ViewBuilder.() -> Unit) : super(parent, function)
constructor(parent: DataInteraction, function: ViewBuilder.() -> Unit) : super(parent, function)
}

/**
* View with TextInputLayoutAssertions
*
Expand Down

0 comments on commit 8c4635a

Please sign in to comment.