Skip to content

Commit

Permalink
Merge pull request #177 from tarkalabs/ms/floatingNav_ssTest
Browse files Browse the repository at this point in the history
ScreenShot test for TUIFloatingNavButton
  • Loading branch information
rajajawahar authored Jan 25, 2024
2 parents 0b53f59 + b5b5a7b commit e38c41b
Show file tree
Hide file tree
Showing 15 changed files with 566 additions and 3 deletions.
104 changes: 104 additions & 0 deletions .idea/androidTestResultsUserPreferences.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.
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
@@ -0,0 +1,157 @@
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.performClick
import com.tarkalabs.tarkaicons.CalendarRtl24
import com.tarkalabs.tarkaicons.Directions24
import com.tarkalabs.tarkaicons.Diversity24
import com.tarkalabs.tarkaicons.Map24
import com.tarkalabs.tarkaicons.TarkaIcons
import com.tarkalabs.uicomponents.components.tab.TUIFloatingNavButton
import com.tarkalabs.uicomponents.components.tab.TUIFloatingNavButtonContentType.Burger
import com.tarkalabs.uicomponents.components.tab.TUIFloatingNavButtonContentType.List
import com.tarkalabs.uicomponents.components.tab.TUIFloatingNavButtonContentType.Navigation
import com.tarkalabs.uicomponents.components.tab.TUIFloatingNavButtonStyle.BURGER
import com.tarkalabs.uicomponents.components.tab.TUIFloatingNavButtonStyle.LIST
import com.tarkalabs.uicomponents.components.tab.TUIFloatingNavButtonStyle.VIEW_TOGGLE
import com.tarkalabs.uicomponents.components.tab.TUIFloatingNavButtonTags
import org.junit.Rule
import org.junit.Test
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify

class TUIFloatingNavButtonTest {

@get:Rule val composable = createComposeRule()
private val tags = TUIFloatingNavButtonTags()


@Test fun floating_nav_btn_is_displayed() {
val onClick: () -> Unit = mock()
composable.run {
setContent {
TUIFloatingNavButton(
contentType = Navigation(TarkaIcons.Filled.Diversity24, text = "Test"),
onClicked = onClick, tags = tags
)
}
onNodeWithTag(tags.parentTag).run {
assertIsDisplayed()
performClick()
verify(onClick)()
}

onNodeWithTag(tags.leadingIconTag, true).assertIsDisplayed()
onNodeWithTag(tags.trailingIconTag, true).assertIsDisplayed()
}
}

@Test fun floating_nav_btn_trailing_icon_is_not_displayed() {
val onClick: () -> Unit = mock()
composable.run {
setContent {
TUIFloatingNavButton(
contentType = Navigation(TarkaIcons.Filled.Diversity24, text = "Test"),
onClicked = onClick, tags = tags, style = VIEW_TOGGLE
)
}
onNodeWithTag(tags.parentTag).run {
assertIsDisplayed()
performClick()
verify(onClick)()
}

onNodeWithTag(tags.leadingIconTag, true).assertIsDisplayed()
onNodeWithTag(tags.trailingIconTag, true).assertDoesNotExist()
}
}

@Test fun floating_nav_list_type_all_icons_are_displayed() {
val onIconOneClick: () -> Unit = mock()
val onIconTwoClick: () -> Unit = mock()
val onIconThreeClick: () -> Unit = mock()

composable.run {
setContent {
TUIFloatingNavButton(
contentType = List(
iconOne = TarkaIcons.Filled.CalendarRtl24,
onIconOneClick = onIconOneClick,
iconTwo = TarkaIcons.Filled.Map24,
onIconTwoClick = onIconTwoClick,
iconThree = TarkaIcons.Filled.Directions24,
onIconThreeClick = onIconThreeClick
),
style = LIST
)
}
onNodeWithTag(tags.iconOneTag).run {
assertIsDisplayed()
performClick()
verify(onIconOneClick)()
}
onNodeWithTag(tags.iconTwoTag).run {
assertIsDisplayed()
performClick()
verify(onIconTwoClick)()
}
onNodeWithTag(tags.iconThreeTag).run {
assertIsDisplayed()
performClick()
verify(onIconThreeClick)()
}
}
}

@Test fun floating_nav_list_type_few_icons_are_displayed() {
val onIconOneClick: () -> Unit = mock()
val onIconTwoClick: () -> Unit = mock()

composable.run {
setContent {
TUIFloatingNavButton(
contentType = List(
iconOne = TarkaIcons.Filled.CalendarRtl24,
onIconOneClick = onIconOneClick,
iconTwo = TarkaIcons.Filled.Map24,
onIconTwoClick = onIconTwoClick,
),
style = LIST
)
}
onNodeWithTag(tags.iconOneTag).run {
assertIsDisplayed()
performClick()
verify(onIconOneClick)()
}
onNodeWithTag(tags.iconTwoTag).run {
assertIsDisplayed()
performClick()
verify(onIconTwoClick)()
}
onNodeWithTag(tags.iconThreeTag).run {
assertDoesNotExist()
}
}
}

@Test fun floating_nav_burger_button_is_displayed() {
val onClick: () -> Unit = mock()
composable.run {
setContent {
TUIFloatingNavButton(
contentType = Burger,
style = BURGER,
onClicked = onClick
)
}
onNodeWithTag(tags.burgerIconTag, true).run {
assertIsDisplayed()
performClick()
verify(onClick)()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.tarkalabs.uicomponents.screenshots

import com.tarkalabs.tarkaicons.CalendarRtl24
import com.tarkalabs.tarkaicons.Directions24
import com.tarkalabs.tarkaicons.Diversity24
import com.tarkalabs.tarkaicons.Map24
import com.tarkalabs.tarkaicons.TarkaIcons
import com.tarkalabs.uicomponents.components.tab.TUIFloatingNavButton
import com.tarkalabs.uicomponents.components.tab.TUIFloatingNavButtonContentType.Burger
import com.tarkalabs.uicomponents.components.tab.TUIFloatingNavButtonContentType.List
import com.tarkalabs.uicomponents.components.tab.TUIFloatingNavButtonContentType.Navigation
import com.tarkalabs.uicomponents.components.tab.TUIFloatingNavButtonStyle.BURGER
import com.tarkalabs.uicomponents.components.tab.TUIFloatingNavButtonStyle.LIST
import com.tarkalabs.uicomponents.components.tab.TUIFloatingNavButtonStyle.NAVIGATION
import com.tarkalabs.uicomponents.components.tab.TUIFloatingNavButtonStyle.VIEW_TOGGLE
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

@RunWith(Parameterized::class)
class TUIFloatingNavButtonScreenShotTest(
private val darkTheme: Boolean,
private val testName: String,
) : ComposeScreenshotComparator() {

companion object {
@JvmStatic
@Parameterized.Parameters
fun data(): Collection<Array<Any?>> {
return mutableListOf<Array<Any?>>().apply {
for (darkTheme in listOf(true, false)) {
val testName = "darkTheme_${darkTheme}"
add(arrayOf(darkTheme, testName))
}
}
}
}

@Test fun floatingNavButton() = compareScreenshotFor(darkTheme, "_floatingNavButton_$testName") {
TUIFloatingNavButton(
contentType = Navigation(leadingIcon = TarkaIcons.Filled.Diversity24, text = "Overview"),
style = NAVIGATION
)
}

@Test fun floatingNavViewToggleButton() =
compareScreenshotFor(darkTheme, "_floatingNavViewToggleButton_$testName") {
TUIFloatingNavButton(
contentType = Navigation(leadingIcon = TarkaIcons.Filled.Diversity24, text = "Overview"),
style = VIEW_TOGGLE
)
}

@Test fun floatingNavBurgerButton() =
compareScreenshotFor(darkTheme, "_floatingNavBurgerButton_$testName") {
TUIFloatingNavButton(contentType = Burger, style = BURGER)
}

@Test fun floatingNavListButton() =
compareScreenshotFor(darkTheme, "_floatingNavListButton_$testName") {
TUIFloatingNavButton(
contentType = List(
iconOne = TarkaIcons.Filled.CalendarRtl24, iconTwo = TarkaIcons.Filled.Map24,
iconThree = TarkaIcons.Filled.Directions24
), style = LIST
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import com.tarkalabs.uicomponents.theme.TUITheme
@Composable fun TUITextRow(
title: String,
style: TextRowStyle = Title,
modifier: Modifier = Modifier.fillMaxWidth(),
modifier: Modifier = Modifier,
iconOne: TarkaIcon? = null,
iconTwo: TarkaIcon? = null,
buttonTitle: String? = null,
Expand Down
Loading

0 comments on commit e38c41b

Please sign in to comment.