Label Group views will now have visibility GONE if empty

This commit is contained in:
Davide Farella 2021-06-15 14:10:14 +02:00 committed by Davide Giuseppe Farella
parent b63f303c2b
commit 6cb60e6f27
4 changed files with 42 additions and 17 deletions

View File

@ -30,6 +30,8 @@ import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import ch.protonmail.android.R
import ch.protonmail.android.domain.entity.Id
import ch.protonmail.android.domain.entity.Name
import ch.protonmail.android.testAndroidInstrumented.assertion.isGone
import ch.protonmail.android.testAndroidInstrumented.assertion.isVisible
import ch.protonmail.android.testAndroidInstrumented.withBackgroundColor
import ch.protonmail.android.util.ViewTest
import org.junit.runner.RunWith
@ -51,6 +53,26 @@ class MultiLineLabelChipGroupViewTest : ViewTest<MultiLineLabelChipGroupView>(::
LabelChipUiModel(Id("g"), Name("long name for seventh label"), Color.BLACK),
)
@Test
fun viewIsGoneWhenNoLabels() {
// given - when
testView.setLabels(emptyList())
// then
onTestView().check(isGone())
}
@Test
fun viewIsVisibleWhenHasLabels() {
// given - when
testView.setLabels(testLabelsList)
// then
onTestView().check(isVisible())
}
@Test
fun listIsEmptyWhenLabelsListIsEmpty() {
val chipGroupView = testView

View File

@ -22,15 +22,13 @@ package ch.protonmail.android.ui.view
import android.graphics.Color
import android.view.View
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import ch.protonmail.android.R
import ch.protonmail.android.domain.entity.Id
import ch.protonmail.android.domain.entity.Name
import ch.protonmail.android.testAndroidInstrumented.assertion.isInvisible
import ch.protonmail.android.testAndroidInstrumented.assertion.isGone
import ch.protonmail.android.testAndroidInstrumented.assertion.isVisible
import ch.protonmail.android.testAndroidInstrumented.withBackgroundColor
import ch.protonmail.android.util.ViewTest
import org.hamcrest.Description
@ -52,18 +50,23 @@ class SingleLineLabelChipGroupViewTest : ViewTest<SingleLineLabelChipGroupView>(
)
@Test
fun moreIsInvisibleWhenLabelsListIsEmpty() {
val chipGroupView = testView
fun viewIsGoneWhenNoLabels() {
// given
val labels = emptyList<LabelChipUiModel>()
// when
chipGroupView.setLabels(labels)
// given - when
testView.setLabels(emptyList())
// then
Thread.sleep(500)
onMoreView().check(isInvisible())
onTestView().check(isGone())
}
@Test
fun viewIsVisibleWhenHasLabels() {
// given - when
testView.setLabels(testLabelsList)
// then
onTestView().check(isVisible())
}
@Test
@ -80,15 +83,11 @@ class SingleLineLabelChipGroupViewTest : ViewTest<SingleLineLabelChipGroupView>(
chipGroupView.setLabels(labels)
// then
Thread.sleep(500)
onView(withLabelId(expectedLabelId))
.check(matches(withText(expectedLabelName)))
.check(matches(withBackgroundColor(expectedLabelColor)))
}
private fun onMoreView(): ViewInteraction =
onView(withId(R.id.single_line_label_more_text_view))
private fun withLabelId(labelId: Id): Matcher<View> {
return object : TypeSafeDiagnosingMatcher<View>() {

View File

@ -25,6 +25,7 @@ import android.util.AttributeSet
import android.widget.FrameLayout
import androidx.annotation.StyleRes
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import ch.protonmail.android.R
import ch.protonmail.android.domain.entity.Id
@ -74,6 +75,7 @@ class MultiLineLabelChipGroupView @JvmOverloads constructor(
}
fun setLabels(labels: List<LabelChipUiModel>) {
isVisible = labels.isNotEmpty()
labelsAdapter.submitList(labels)
}

View File

@ -25,6 +25,7 @@ import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import androidx.annotation.StyleRes
import androidx.core.view.isVisible
import ch.protonmail.android.R
import ch.protonmail.android.domain.entity.Id
import ch.protonmail.android.domain.entity.Name
@ -68,6 +69,7 @@ class SingleLineLabelChipGroupView @JvmOverloads constructor (
}
fun setLabels(labels: List<LabelChipUiModel>) {
isVisible = labels.isNotEmpty()
if (labels.isNotEmpty() && labels == allLabels) return
allLabels = labels