Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend assertNotExist with a new implementation using a viewMatcher as a param #479

Merged
merged 4 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ import androidx.annotation.StyleRes
import androidx.annotation.StyleableRes
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.platform.app.InstrumentationRegistry
import com.adevinta.android.barista.internal.assertAny
import com.adevinta.android.barista.internal.matcher.TextColorMatcher
import com.adevinta.android.barista.internal.matcher.TextStyleableColorMatcher
import com.adevinta.android.barista.internal.util.resourceMatcher
import com.adevinta.android.barista.internal.matcher.withCompatText
import com.adevinta.android.barista.internal.util.resourceMatcher
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.containsString
import org.hamcrest.Matchers.not
import org.hamcrest.Matchers.*

object BaristaVisibilityAssertions {

Expand Down Expand Up @@ -58,6 +54,11 @@ object BaristaVisibilityAssertions {
onView(withCompatText(text)).check(doesNotExist())
}

@JvmStatic
fun assertNotExist(viewMatcher: Matcher<View>) {
onView(viewMatcher).check(doesNotExist())
}

@JvmStatic
fun assertNotDisplayed(viewId: Int) {
viewId.resourceMatcher().assertAny(not(isDisplayed()))
Expand Down
1 change: 1 addition & 0 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies {
androidTestImplementation(libs.testing.assertJ)
androidTestImplementation(libs.testing.mockito.kotlin)
androidTestImplementation(libs.testing.mockito.android)
androidTestImplementation("androidx.test.ext:junit:1.1.3")

testImplementation(libs.testing.jUnit)

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.adevinta.android.barista.sample

import android.view.View
import androidx.test.espresso.Espresso
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.rules.ActivityScenarioRule
import com.adevinta.android.barista.assertion.BaristaListAssertions.assertDisplayedAtPosition
import com.adevinta.android.barista.assertion.BaristaVisibilityAssertions
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
import com.adevinta.android.barista.interaction.BaristaViewPagerInteractions.swipeViewPagerBack
import com.adevinta.android.barista.interaction.BaristaViewPagerInteractions.swipeViewPagerForward
import com.adevinta.android.barista.internal.matcher.withCompatText
import junit.framework.AssertionFailedError
import org.hamcrest.CoreMatchers
import org.hamcrest.Matcher
import org.hamcrest.core.AllOf
import org.junit.Assert
import org.junit.Rule
import org.junit.Test

class RecyclerViewWithDifferentDataInsideViewPagerTest {
@Rule
var activityRule = ActivityScenarioRule(
RecyclerViewsWithDifferentDataInsideViewPagerActivity::class.java
)

@Test
fun checkClickRecyclerViewItem() {
swipeViewPagerForward(R.id.pager)
BaristaSleepInteractions.sleep(500)
assertDisplayedAtPosition(R.id.recycler, 1, "Marionberry")
swipeViewPagerBack(R.id.pager)
BaristaSleepInteractions.sleep(500)
assertDisplayedAtPosition(R.id.recycler, 0, R.id.textview, "Apple")
}

@Test
fun assertNotExistingView() {
swipeViewPagerForward(R.id.pager)
BaristaSleepInteractions.sleep(500)
try {
BaristaVisibilityAssertions.assertNotExist("Apple")
Assert.assertFalse(false)
} catch (error: AssertionFailedError) {
Assert.assertTrue(true)
}
Espresso.onView(withCompatText("Apple"))
.check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))

val displayedRecyclerView: Matcher<View> =
AllOf.allOf(ViewMatchers.withId(R.id.recycler), ViewMatchers.isDisplayed())

BaristaVisibilityAssertions.assertNotExist(
CoreMatchers.allOf(
ViewMatchers.withText("Apple"),
ViewMatchers.isDescendantOfA(displayedRecyclerView)
)
)

assertDisplayedAtPosition(R.id.recycler, 1, "Marionberry")
swipeViewPagerBack(R.id.pager)
BaristaSleepInteractions.sleep(500)
assertDisplayedAtPosition(R.id.recycler, 0, R.id.textview, "Apple")
}
}