-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ANDROID-15168 compose badge improvements (#383)
* ANDROID-15168 expose badge text size * ANDROID-15168 trim badgecontent if numeric and > 9 * ANDROID-15168 add more options to the catalog * ANDROID-15168 remove ExperimentalMaterialApi annotation * ANDROID-15168 add screenshots tests * Updated screenshots baseline * ANDROID-15168 add endline * ANDROID-15168 rename tests (and screenshots) * ANDROID-15168 rename tests (and screenshots) --------- Co-authored-by: jeprubio <[email protected]>
- Loading branch information
Showing
6 changed files
with
138 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
library/src/test/java/com/telefonica/mistica/compose/badge/BadgeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.telefonica.mistica.compose.badge | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.BadgedBox | ||
import androidx.compose.material.Icon | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onRoot | ||
import androidx.compose.ui.unit.dp | ||
import com.telefonica.mistica.R | ||
import com.telefonica.mistica.compose.theme.MisticaTheme | ||
import com.telefonica.mistica.compose.theme.brand.MovistarBrand | ||
import com.telefonica.mistica.testutils.ScreenshotsTest | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class BadgeTest: ScreenshotsTest() { | ||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun `Badge non numeric`() { | ||
`when some badge`("") | ||
|
||
`then screenshot is OK`() | ||
} | ||
|
||
@Test | ||
fun `Badge numeric one digit`() { | ||
`when some badge`(ONE_DIGIT_CONTENT) | ||
|
||
`then screenshot is OK`() | ||
} | ||
|
||
@Test | ||
fun `Badge numeric two digits`() { | ||
`when some badge`(TWO_DIGITS_CONTENT) | ||
|
||
`then screenshot is OK`() | ||
} | ||
|
||
private fun `when some badge`(value: String) { | ||
composeTestRule.setContent { | ||
MisticaTheme(brand = MovistarBrand) { | ||
Box(modifier = Modifier.padding(24.dp)) { | ||
BadgedBox( | ||
badge = { | ||
Badge( | ||
content = value | ||
) | ||
} | ||
) { | ||
Icon( | ||
painter = painterResource(id = R.drawable.icn_creditcard), | ||
contentDescription = "credit card" | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun `then screenshot is OK`() { | ||
compareScreenshot(composeTestRule.onRoot()) | ||
} | ||
|
||
companion object { | ||
private const val ONE_DIGIT_CONTENT = "9" | ||
private const val TWO_DIGITS_CONTENT = "99" | ||
} | ||
} |