Skip to content

Commit

Permalink
ScreenShot Test & UI Test Included for TUIBadge latest changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
androidmahi committed Mar 12, 2024
1 parent a89822b commit fdbde91
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 7 deletions.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ package com.tarkalabs.uicomponents
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import com.tarkalabs.tarkaui.components.base.BadgeSize.L
import com.tarkalabs.tarkaui.components.base.BadgeStyle
import com.tarkalabs.tarkaui.components.base.TUIBadge
import com.tarkalabs.tarkaui.components.base.TUIBadgeTags
import com.tarkalabs.tarkaui.icons.Symbols16
import com.tarkalabs.tarkaui.icons.TarkaIcon
import com.tarkalabs.tarkaui.icons.TarkaIcons
import org.junit.Rule
import org.junit.Test

Expand All @@ -14,12 +19,34 @@ class TUIBadgeTest {

private val tags = TUIBadgeTags(parentTag = "testTag")

@Test fun badge_Displayed() {
@Test fun text_badge_Displayed() {
composeTestRule.setContent {
TUIBadge(
badgeSize = L, tags = tags, count = 299
badgeSize = L, tags = tags, style = BadgeStyle.Count(299)
)
}
composeTestRule.onNodeWithTag(tags.parentTag).assertIsDisplayed()
composeTestRule.onNodeWithText("299").assertIsDisplayed()
composeTestRule.onNodeWithTag(tags.iconTag).assertDoesNotExist()
}


@Test fun icon_badge_Displayed() {
composeTestRule.setContent {
TUIBadge(
badgeSize = L, tags = tags, style = BadgeStyle.Icon(TarkaIcons.Regular.Symbols16)
)
}
composeTestRule.onNodeWithTag(tags.iconTag).assertIsDisplayed()
}

@Test fun empty_badge_Displayed() {
composeTestRule.setContent {
TUIBadge(
badgeSize = L, tags = tags
)
}
composeTestRule.onNodeWithTag(tags.iconTag).assertDoesNotExist()
composeTestRule.onNodeWithTag(tags.parentTag).assertExists()
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.tarkalabs.uicomponents.screenshots

import com.tarkalabs.tarkaui.components.base.BadgeSize.M
import com.tarkalabs.tarkaui.components.base.BadgeSize.S
import com.tarkalabs.tarkaui.components.base.BadgeStyle
import com.tarkalabs.tarkaui.components.base.TUIBadge
import com.tarkalabs.tarkaui.icons.Info20
import com.tarkalabs.tarkaui.icons.TarkaIcons
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
Expand All @@ -27,10 +29,10 @@ open class TUIBadgeScreenShotTest(
}

@Test fun test_badge_with_count() = compareScreenshotFor(darkTheme, "_testBadgeWithCount_$testName") {
TUIBadge(count = 2, badgeSize = M)
TUIBadge(style = BadgeStyle.Count(2), badgeSize = M)
}

@Test fun test_badge_with_out_count() = compareScreenshotFor(darkTheme, "_testBadgeWithoutCount_$testName") {
TUIBadge(badgeSize = S)
@Test fun test_badge_with_icon() = compareScreenshotFor(darkTheme, "_testBadgeWithIcon_$testName") {
TUIBadge(style = BadgeStyle.Icon(TarkaIcons.Regular.Info20), badgeSize = M)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ sealed class BadgeStyle {
is BadgeStyle.Icon -> {
Icon(
modifier = Modifier
.testTag(tags.iconTag)
.defaultMinSize(minHeight = 10.dp, minWidth = 10.dp)
.wrapContentSize(),
painter = painterResource(id = style.icon.iconRes),
Expand All @@ -102,6 +103,7 @@ sealed class BadgeStyle {

data class TUIBadgeTags(
val parentTag: String = "TUIBadge",
val iconTag: String = "BadgeIcon",
)

@Preview(showBackground = true) @Composable fun BadgePreview() {
Expand Down

0 comments on commit fdbde91

Please sign in to comment.