Skip to content

Commit

Permalink
πŸš€ :: v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Tmdhoon2 committed Feb 7, 2024
2 parents dc9c9c3 + 7bc04a9 commit a720809
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 29 deletions.
5 changes: 4 additions & 1 deletion jobisdesignsystemv2/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ afterEvaluate {
from(components["release"])
groupId = "team.return.jobis.android"
artifactId = "design-system-v2"
version = "1.1.0"
version = "1.1.1"
}
}
}
Expand All @@ -67,6 +67,9 @@ dependencies {
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.10.01"))

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package team.returm.jobisdesignsystemv2

import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assertHasClickAction
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 androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import team.returm.jobisdesignsystemv2.button.JobisButton

private const val BTN_TEST_TAG = "ButtonTest"

/**
* Verifies that the button appears on the display and that a click action is performed
* assertHasClickAction cannot be used because JobisButton does not use the button's onClick
* @see JobisButton
* @see assertHasClickAction
*/
@RunWith(AndroidJUnit4::class)
class JobisButtonTest {
@get:Rule
val composeRule = createComposeRule()
private var clicked = 0

@Test
fun enabledJobisButtonTest() {
composeRule.setContent {
JobisButton(
modifier = Modifier.testTag(BTN_TEST_TAG),
text = BTN_TEST_TAG,
onClick = { clicked++ },
enabled = false,
)
}
composeRule
.onNodeWithTag(BTN_TEST_TAG)
.assertIsDisplayed()
.performClick()

composeRule.runOnIdle { assert(clicked == 0) }
}

@Test
fun jobisButtonTest() {
composeRule.setContent {
JobisButton(
modifier = Modifier.testTag(BTN_TEST_TAG),
text = BTN_TEST_TAG,
onClick = { clicked++ },
enabled = true,
)
}
composeRule
.onNodeWithTag(BTN_TEST_TAG)
.assertIsDisplayed()
.performClick()

composeRule.runOnIdle { assert(clicked == 1) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package team.returm.jobisdesignsystemv2

import androidx.compose.foundation.clickable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import team.returm.jobisdesignsystemv2.textfield.DescriptionType
import team.returm.jobisdesignsystemv2.textfield.JobisTextField

private const val TEXT_FIELD_TEST_TAG = "TextTest"

/**
* Verify that the DescriptionType of the textfield is properly changed and hint and title
* @see JobisTextField
* @see DescriptionType
*/
@RunWith(AndroidJUnit4::class)
class JobisTextFieldTest {
@get:Rule
val composeRule = createComposeRule()

@Test
fun jobisTextFieldTest() {
val hint = "hint"
val checkDescription = "check"
val errorDescription = "error"
val informationDescription = "information"
var type: DescriptionType = DescriptionType.Information
composeRule.setContent {
var text by remember { mutableStateOf("") }
LaunchedEffect(key1 = text) {
type = when (text.length) {
in 0 until 8 -> DescriptionType.Error
else -> DescriptionType.Check
}
}
JobisTextField(
title = TEXT_FIELD_TEST_TAG,
value = { text },
hint = hint,
onValueChange = { },
checkDescription = checkDescription,
errorDescription = errorDescription,
informationDescription = informationDescription,
descriptionType = type,
showDescription = { true },
modifier = Modifier.clickable { text = "text" }
)
}

val titleTest = composeRule.onNodeWithText(TEXT_FIELD_TEST_TAG)
titleTest.assertIsDisplayed()

val hintTest = composeRule.onNodeWithText(hint)
hintTest.assertIsDisplayed()

val descriptionTest = composeRule.onNodeWithText(TEXT_FIELD_TEST_TAG)
descriptionTest.performClick()

composeRule.runOnIdle { assert(type == DescriptionType.Error) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package team.returm.jobisdesignsystemv2

import androidx.compose.foundation.clickable
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import team.returm.jobisdesignsystemv2.foundation.JobisTypography
import team.returm.jobisdesignsystemv2.text.JobisText

private const val TEXT_TEST_TAG = "TextTest"

/**
* Verifies that text appears on the display and that styles are applied correctly
* @see JobisText
*/
@RunWith(AndroidJUnit4::class)
class JobisTextTest {
@get:Rule
val composeRule = createComposeRule()
private var style = JobisTypography.Body

@Test
fun jobisTextTest() {
composeRule.setContent {
JobisText(
text = TEXT_TEST_TAG,
style = style,
modifier = Modifier.clickable { style = JobisTypography.Caption }
)
}
val test = composeRule.onNodeWithText(TEXT_TEST_TAG).assertIsDisplayed()
test.performClick()

composeRule.runOnIdle { assert(style == JobisTypography.Caption) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal object AppBarPaddings {
@Composable
private fun BasicTopAppBar(
modifier: Modifier,
showLogo: Boolean,
onBackPressed: (() -> Unit)?,
actions: (@Composable RowScope.() -> Unit)?,
title: @Composable BoxScope.() -> Unit,
Expand All @@ -53,23 +54,20 @@ private fun BasicTopAppBar(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
when (onBackPressed) {
null -> {
Image(
modifier = Modifier.padding(vertical = 12.dp),
painter = painterResource(id = R.drawable.img_jobis),
contentDescription = stringResource(id = R.string.content_description_jobis),
)
}

else -> {
JobisIconButton(
modifier = Modifier.padding(vertical = 8.dp),
painter = painterResource(id = JobisIcon.Arrow),
contentDescription = stringResource(id = R.string.content_description_arrow),
onClick = onBackPressed,
)
}
if(showLogo){
Image(
modifier = Modifier.padding(vertical = 12.dp),
painter = painterResource(id = R.drawable.img_jobis),
contentDescription = stringResource(id = R.string.content_description_jobis),
)
}
onBackPressed?.run {
JobisIconButton(
modifier = Modifier.padding(vertical = 8.dp),
painter = painterResource(id = JobisIcon.Arrow),
contentDescription = stringResource(id = R.string.content_description_arrow),
onClick = onBackPressed,
)
}
actions?.run {
Row(
Expand All @@ -95,11 +93,13 @@ private fun BasicTopAppBar(
fun JobisSmallTopAppBar(
modifier: Modifier = Modifier,
title: String = "",
showLogo: Boolean = false,
onBackPressed: (() -> Unit)? = null,
actions: (@Composable RowScope.() -> Unit)? = null,
) {
BasicTopAppBar(
modifier = modifier,
showLogo = showLogo,
onBackPressed = onBackPressed,
actions = actions,
) {
Expand All @@ -123,11 +123,13 @@ fun JobisSmallTopAppBar(
fun JobisLargeTopAppBar(
modifier: Modifier = Modifier,
title: String = "",
showLogo: Boolean = false,
onBackPressed: (() -> Unit)? = null,
actions: (@Composable RowScope.() -> Unit)? = null,
) {
BasicTopAppBar(
modifier = modifier,
showLogo = showLogo,
onBackPressed = onBackPressed,
actions = actions,
) {
Expand Down Expand Up @@ -160,6 +162,7 @@ fun JobisLargeTopAppBar(
fun JobisCollapsingTopAppBar(
modifier: Modifier = Modifier,
title: String = "",
showLogo: Boolean = false,
scrollState: ScrollState,
onBackPressed: (() -> Unit)? = null,
actions: (@Composable RowScope.() -> Unit)? = null,
Expand Down Expand Up @@ -196,6 +199,7 @@ fun JobisCollapsingTopAppBar(

BasicTopAppBar(
modifier = modifier,
showLogo = showLogo,
onBackPressed = onBackPressed,
actions = actions,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
Expand All @@ -19,7 +21,6 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
Expand All @@ -30,8 +31,11 @@ import team.returm.jobisdesignsystemv2.foundation.JobisIcon
import team.returm.jobisdesignsystemv2.foundation.JobisTheme
import team.returm.jobisdesignsystemv2.foundation.JobisTypography
import team.returm.jobisdesignsystemv2.text.JobisText
import team.returm.jobisdesignsystemv2.utils.DEFAULT_PRESS_DEPTH
import team.returm.jobisdesignsystemv2.utils.DURATION_MILLIS
import team.returm.jobisdesignsystemv2.utils.MIN_PRESS_DEPTH
import team.returm.jobisdesignsystemv2.utils.clickable
import team.returm.jobisdesignsystemv2.utils.keyboardAsState

private val largeButtonShape = RoundedCornerShape(12.dp)
private val smallButtonShape = RoundedCornerShape(8.dp)
Expand All @@ -46,14 +50,35 @@ private fun BasicButton(
onClick: () -> Unit,
content: @Composable () -> Unit,
) {
val keyboardShow by keyboardAsState()
val padding = if (keyboardShow) {
PaddingValues(
vertical = 0.dp,
horizontal = 0.dp,
)
} else {
PaddingValues(
vertical = 12.dp,
horizontal = 24.dp,
)
}
val (shapeByKeyboardShow, pressDepth) = if (keyboardShow) {
RoundedCornerShape(0.dp) to MIN_PRESS_DEPTH
} else {
shape to DEFAULT_PRESS_DEPTH
}

Surface(
modifier = modifier
.clickable(
pressDepth = pressDepth,
enabled = enabled,
onPressed = onPressed,
onClick = onClick,
),
shape = shape,
)
.padding(padding)
.imePadding(),
shape = shapeByKeyboardShow,
color = backgroundColor,
content = content,
)
Expand Down Expand Up @@ -145,9 +170,7 @@ private fun LargeButton(
var pressed by remember { mutableStateOf(false) }

ColoredButton(
modifier = modifier
.fillMaxWidth()
.clip(largeButtonShape),
modifier = modifier.fillMaxWidth(),
color = color,
shape = largeButtonShape,
enabled = enabled,
Expand Down Expand Up @@ -192,7 +215,7 @@ private fun SmallButton(
var pressed by remember { mutableStateOf(false) }

ColoredButton(
modifier = modifier.clip(smallButtonShape),
modifier = modifier,
color = color,
shape = smallButtonShape,
enabled = enabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,10 @@ fun JobisTextField(
Column(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 12.dp),
.padding(
horizontal = 24.dp,
vertical = 12.dp,
),
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.Center,
) {
Expand Down
Loading

0 comments on commit a720809

Please sign in to comment.