Fix problems in SingleLineLabelChipGroupViewTest.kt
MAILAND-2623
This commit is contained in:
parent
b1ab210e16
commit
a8992de025
|
@ -19,23 +19,91 @@
|
|||
|
||||
package ch.protonmail.android.ui.view
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.View
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
|
||||
import ch.protonmail.android.domain.entity.Name
|
||||
import ch.protonmail.android.labels.domain.model.LabelId
|
||||
import ch.protonmail.android.testAndroidInstrumented.assertion.isGone
|
||||
import ch.protonmail.android.testAndroidInstrumented.assertion.isVisible
|
||||
import ch.protonmail.android.testAndroidInstrumented.matcher.withBackgroundColor
|
||||
import ch.protonmail.android.ui.model.LabelChipUiModel
|
||||
import ch.protonmail.android.util.ViewTest
|
||||
import org.hamcrest.Description
|
||||
import org.hamcrest.Matcher
|
||||
import org.hamcrest.TypeSafeDiagnosingMatcher
|
||||
import org.junit.runner.RunWith
|
||||
import kotlin.test.Test
|
||||
|
||||
/**
|
||||
* Test suite for [SingleLineLabelChipGroupView]
|
||||
*/
|
||||
@RunWith(AndroidJUnit4ClassRunner::class)
|
||||
class SingleLineLabelChipGroupViewTest : ViewTest<SingleLineLabelChipGroupView>(::SingleLineLabelChipGroupView) {
|
||||
|
||||
private val testLabelsList = listOf(
|
||||
LabelChipUiModel(LabelId("a"), Name("first"), Color.RED),
|
||||
LabelChipUiModel(LabelId("b"), Name("second"), Color.GREEN),
|
||||
LabelChipUiModel(LabelId("c"), Name("third"), Color.BLUE),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun viewIsGoneWhenNoLabels() {
|
||||
|
||||
// given - when
|
||||
testView.setLabels(emptyList())
|
||||
runOnActivityThread {
|
||||
testView.setLabels(emptyList())
|
||||
}
|
||||
|
||||
// then
|
||||
onTestView().check(isGone())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun viewIsVisibleWhenHasLabels() {
|
||||
|
||||
// given - when
|
||||
runOnActivityThread {
|
||||
testView.setLabels(testLabelsList)
|
||||
}
|
||||
|
||||
// then
|
||||
onTestView().check(isVisible())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun firstLabelShowsTheCorrectNameAndColor() {
|
||||
val chipGroupView = testView
|
||||
|
||||
// given
|
||||
val labels = testLabelsList
|
||||
val (expectedLabelId, expectedLabelName, expectedLabelColor) = with(labels.first()) {
|
||||
Triple(id, name.s, checkNotNull(color))
|
||||
}
|
||||
|
||||
// when
|
||||
runOnActivityThread {
|
||||
chipGroupView.setLabels(labels)
|
||||
}
|
||||
|
||||
// then
|
||||
onView(withLabelId(expectedLabelId))
|
||||
.check(matches(withText(expectedLabelName)))
|
||||
.check(matches(withBackgroundColor(expectedLabelColor)))
|
||||
}
|
||||
|
||||
private fun withLabelId(labelId: LabelId): Matcher<View> {
|
||||
return object : TypeSafeDiagnosingMatcher<View>() {
|
||||
|
||||
override fun matchesSafely(item: View, mismatchDescription: Description) =
|
||||
(item as? LabelChipView)?.labelId == labelId
|
||||
|
||||
override fun describeTo(description: Description) {
|
||||
description.appendText("Label id: ${labelId.id}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue