-
Notifications
You must be signed in to change notification settings - Fork 0
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 #57 from mori-atsushi/padding-style
Improve PaddingSetter
- Loading branch information
Showing
8 changed files
with
393 additions
and
71 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
216 changes: 216 additions & 0 deletions
216
...tTest/kotlin/com/moriatsushi/compose/stylesheet/component/padding/ComponentPaddingTest.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,216 @@ | ||
package com.moriatsushi.compose.stylesheet.component.padding | ||
|
||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.platform.LocalLayoutDirection | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.unit.LayoutDirection | ||
import androidx.compose.ui.unit.dp | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.moriatsushi.compose.stylesheet.token.Token | ||
import kotlin.test.assertEquals | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class ComponentPaddingTest { | ||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun testAsPaddingValues() { | ||
val componentPadding = ComponentPadding( | ||
start = Token(10.dp), | ||
top = Token(20.dp), | ||
end = Token(30.dp), | ||
bottom = Token(40.dp), | ||
) | ||
composeTestRule.setContent { | ||
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) { | ||
assertEquals( | ||
PaddingValues.Absolute( | ||
left = 10.dp, | ||
top = 20.dp, | ||
right = 30.dp, | ||
bottom = 40.dp, | ||
), | ||
componentPadding.asPaddingValues(), | ||
) | ||
} | ||
|
||
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) { | ||
assertEquals( | ||
PaddingValues.Absolute( | ||
left = 30.dp, | ||
top = 20.dp, | ||
right = 10.dp, | ||
bottom = 40.dp, | ||
), | ||
componentPadding.asPaddingValues(), | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun testAsPaddingValues_absolute() { | ||
val componentPadding = ComponentPadding( | ||
left = Token(10.dp), | ||
top = Token(20.dp), | ||
right = Token(30.dp), | ||
bottom = Token(40.dp), | ||
) | ||
composeTestRule.setContent { | ||
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) { | ||
assertEquals( | ||
PaddingValues.Absolute( | ||
left = 10.dp, | ||
top = 20.dp, | ||
right = 30.dp, | ||
bottom = 40.dp, | ||
), | ||
componentPadding.asPaddingValues(), | ||
) | ||
} | ||
|
||
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) { | ||
assertEquals( | ||
PaddingValues.Absolute( | ||
left = 10.dp, | ||
top = 20.dp, | ||
right = 30.dp, | ||
bottom = 40.dp, | ||
), | ||
componentPadding.asPaddingValues(), | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun testAsPaddingValues_paddingValues() { | ||
val paddingValues = PaddingValues( | ||
start = 10.dp, | ||
top = 20.dp, | ||
end = 30.dp, | ||
bottom = 40.dp, | ||
) | ||
val componentPadding = ComponentPadding(paddingValues) | ||
composeTestRule.setContent { | ||
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) { | ||
assertEquals( | ||
PaddingValues.Absolute( | ||
left = 10.dp, | ||
top = 20.dp, | ||
right = 30.dp, | ||
bottom = 40.dp, | ||
), | ||
componentPadding.asPaddingValues(), | ||
) | ||
} | ||
|
||
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) { | ||
assertEquals( | ||
PaddingValues.Absolute( | ||
left = 30.dp, | ||
top = 20.dp, | ||
right = 10.dp, | ||
bottom = 40.dp, | ||
), | ||
componentPadding.asPaddingValues(), | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun testAsPaddingValues_copied() { | ||
val paddingValues = PaddingValues( | ||
start = 10.dp, | ||
top = 20.dp, | ||
end = 30.dp, | ||
bottom = 40.dp, | ||
) | ||
val componentPadding = ComponentPadding(paddingValues) | ||
.copy(left = Token(50.dp)) | ||
.copy(bottom = Token(60.dp)) | ||
.copy(start = Token(70.dp)) | ||
|
||
composeTestRule.setContent { | ||
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) { | ||
assertEquals( | ||
PaddingValues.Absolute( | ||
left = 70.dp, | ||
top = 20.dp, | ||
right = 30.dp, | ||
bottom = 60.dp, | ||
), | ||
componentPadding.asPaddingValues(), | ||
) | ||
} | ||
|
||
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) { | ||
assertEquals( | ||
PaddingValues.Absolute( | ||
left = 50.dp, | ||
top = 20.dp, | ||
right = 70.dp, | ||
bottom = 60.dp, | ||
), | ||
componentPadding.asPaddingValues(), | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun testAsPaddingValues_merged() { | ||
val paddingValues = PaddingValues( | ||
start = 10.dp, | ||
top = 20.dp, | ||
end = 30.dp, | ||
bottom = 40.dp, | ||
) | ||
val padding1 = ComponentPadding( | ||
PaddingValues( | ||
start = 10.dp, | ||
top = 20.dp, | ||
end = 30.dp, | ||
bottom = 40.dp, | ||
), | ||
) | ||
val padding2 = ComponentPadding( | ||
start = Token(50.dp), | ||
top = Token(60.dp), | ||
) | ||
val merged1 = padding1.merge(padding2) | ||
val merged2 = padding2.merge(padding1) | ||
|
||
composeTestRule.setContent { | ||
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) { | ||
assertEquals( | ||
PaddingValues.Absolute( | ||
left = 50.dp, | ||
top = 60.dp, | ||
right = 30.dp, | ||
bottom = 40.dp, | ||
), | ||
merged1.asPaddingValues(), | ||
) | ||
} | ||
|
||
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) { | ||
assertEquals( | ||
PaddingValues.Absolute( | ||
left = 10.dp, | ||
top = 20.dp, | ||
right = 30.dp, | ||
bottom = 40.dp, | ||
), | ||
merged2.asPaddingValues(), | ||
) | ||
} | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.