-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from tarkalabs/mahi/component/TUICardHeader
TUICardHeader component Created
- Loading branch information
Showing
12 changed files
with
200 additions
and
3 deletions.
There are no files selected for viewing
Binary file added
BIN
+5.83 KB
...TUICardHeaderScreenShotTest_darkTheme_false_tagShownfalse_trailIcShownfalse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.82 KB
....TUICardHeaderScreenShotTest_darkTheme_false_tagShownfalse_trailIcShowntrue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.91 KB
....TUICardHeaderScreenShotTest_darkTheme_false_tagShowntrue_trailIcShownfalse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.4 KB
...s.TUICardHeaderScreenShotTest_darkTheme_false_tagShowntrue_trailIcShowntrue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.65 KB
....TUICardHeaderScreenShotTest_darkTheme_true_tagShownfalse_trailIcShownfalse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.69 KB
...s.TUICardHeaderScreenShotTest_darkTheme_true_tagShownfalse_trailIcShowntrue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.72 KB
...s.TUICardHeaderScreenShotTest_darkTheme_true_tagShowntrue_trailIcShownfalse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.25 KB
...ts.TUICardHeaderScreenShotTest_darkTheme_true_tagShowntrue_trailIcShowntrue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions
52
tarkaui/src/androidTest/java/com/tarkalabs/uicomponents/TUICardHeaderTest.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,52 @@ | ||
package com.tarkalabs.uicomponents | ||
|
||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.assertTextEquals | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithContentDescription | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import com.tarkalabs.tarkaicons.MoreHorizontal24 | ||
import com.tarkalabs.tarkaicons.TarkaIcons | ||
import com.tarkalabs.uicomponents.components.TUICardHeader | ||
import com.tarkalabs.uicomponents.components.TUICardHeaderTags | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.verify | ||
|
||
class TUICardHeaderTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun is_passed_things_shown() { | ||
|
||
val onTrailIconClick: () -> Unit = mock() | ||
val title = "Test Title" | ||
val tagTitle = "Test Tag Title" | ||
val trailingIcon = TarkaIcons.Regular.MoreHorizontal24 | ||
|
||
val testTags = TUICardHeaderTags() | ||
composeTestRule.setContent { | ||
TUICardHeader( | ||
title = title, | ||
tagTitle = tagTitle, | ||
trailingIcon = trailingIcon, | ||
onTrailingIconClick = onTrailIconClick, | ||
tags = testTags | ||
) | ||
} | ||
|
||
composeTestRule.onNodeWithText(title).assertExists() | ||
composeTestRule.onNodeWithText(title).assertIsDisplayed() | ||
composeTestRule.onNodeWithTag(testTags.tagTitleTag).assertTextEquals(tagTitle) | ||
|
||
composeTestRule.onNodeWithContentDescription(trailingIcon.contentDescription).assertExists() | ||
|
||
composeTestRule.onNodeWithTag(testTags.trailingIconTag).performClick() | ||
verify(onTrailIconClick).invoke() | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...rc/androidTest/java/com/tarkalabs/uicomponents/screenshots/TUICardHeaderScreenShotTest.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,40 @@ | ||
package com.tarkalabs.uicomponents.screenshots | ||
|
||
import com.tarkalabs.tarkaicons.MoreHorizontal24 | ||
import com.tarkalabs.tarkaicons.TarkaIcon | ||
import com.tarkalabs.tarkaicons.TarkaIcons | ||
import com.tarkalabs.uicomponents.components.TUICardHeader | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
|
||
@RunWith(Parameterized::class) | ||
class TUICardHeaderScreenShotTest( | ||
private val darkTheme: Boolean, | ||
private val tagTitle: String?, | ||
private val trailIcon: TarkaIcon?, | ||
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)) { | ||
for (tagTitle in listOf(null, "Tag1")) { | ||
for (trailIcon in listOf(TarkaIcons.Filled.MoreHorizontal24, null)) { | ||
val testName = | ||
"darkTheme_${darkTheme}_tagShown${if (tagTitle == null) "false" else "true"}_trailIcShown${if (trailIcon == null) "false" else "true"}" | ||
add(arrayOf(darkTheme, tagTitle, trailIcon, testName)) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test fun tui_card_header_test() = compareScreenshotFor(darkTheme, testName) { | ||
TUICardHeader(title = "Pump Repair Pump", tagTitle = tagTitle, trailingIcon = trailIcon) {} | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
tarkaui/src/main/java/com/tarkalabs/uicomponents/components/TUICardHeader.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,104 @@ | ||
package com.tarkalabs.uicomponents.components | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.testTag | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import com.tarkalabs.tarkaicons.MoreHorizontal24 | ||
import com.tarkalabs.tarkaicons.TarkaIcon | ||
import com.tarkalabs.tarkaicons.TarkaIcons | ||
import com.tarkalabs.uicomponents.components.TagSize.S | ||
import com.tarkalabs.uicomponents.components.base.IconButtonStyle.GHOST | ||
import com.tarkalabs.uicomponents.components.base.TUIIconButton | ||
import com.tarkalabs.uicomponents.theme.TUITheme | ||
|
||
/** | ||
* This Component is used as a Header part in the Card Typed Detail Views. | ||
* | ||
* @param title - Title of the Header. | ||
* @param tagTitle - optional Title of the TUITag. | ||
* @param trailingIcon - optional end Icon. | ||
* | ||
* TUICardHeader( | ||
* title = "Pump Repair Pump", | ||
* tagTitle = "Tag1", | ||
* trailingIcon = TarkaIcons.Filled.MoreHorizontal24.copy(tintColor = TUITheme.colors.secondary) | ||
* ) {} | ||
* | ||
* **/ | ||
@Composable | ||
fun TUICardHeader( | ||
modifier: Modifier = Modifier, | ||
title: String, | ||
tagTitle: String? = null, | ||
trailingIcon: TarkaIcon? = null, | ||
tags: TUICardHeaderTags = TUICardHeaderTags(), | ||
onTrailingIconClick: () -> Unit, | ||
) { | ||
|
||
Row( | ||
modifier = modifier | ||
.testTag(tags.parentTag) | ||
.fillMaxWidth(), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
|
||
HorizontalSpacer(space = 16) | ||
|
||
Column { | ||
tagTitle?.let { | ||
TUITag( | ||
modifier = Modifier.testTag(tags.tagTitleTag), | ||
title = tagTitle, | ||
tagSize = S, | ||
tagType = TagType.LOW | ||
) {} | ||
VerticalSpacer(space = 8) | ||
} | ||
|
||
Text( | ||
text = title, | ||
color = TUITheme.colors.onSurface, | ||
style = TUITheme.typography.heading6 | ||
) | ||
} | ||
|
||
HorizontalSpacer(space = 8) | ||
|
||
trailingIcon?.let { | ||
Spacer(modifier = Modifier.weight(1f)) | ||
TUIIconButton( | ||
modifier = Modifier | ||
.testTag(tags.trailingIconTag), | ||
icon = trailingIcon, | ||
iconButtonStyle = GHOST, | ||
onIconClick = { onTrailingIconClick.invoke() } | ||
) | ||
} | ||
|
||
HorizontalSpacer(space = 16) | ||
|
||
} | ||
} | ||
|
||
data class TUICardHeaderTags( | ||
val parentTag: String = "TUICardHeader", | ||
val tagTitleTag: String = "TUICardHeader_tagTitleTag", | ||
val trailingIconTag: String = "TUICardHeader_trailingIconTag", | ||
) | ||
|
||
@Preview | ||
@Composable | ||
fun TUICardHeaderPreview() { | ||
TUICardHeader( | ||
title = "Pump Repair Pump", | ||
tagTitle = "Tag1", | ||
trailingIcon = TarkaIcons.Filled.MoreHorizontal24.copy(tintColor = TUITheme.colors.secondary) | ||
) {} | ||
} |
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