Skip to content

Commit

Permalink
Prameterize all AbstractFlexContainer tests (#1282)
Browse files Browse the repository at this point in the history
  • Loading branch information
veyndan authored Jun 28, 2023
1 parent 794ae03 commit 8874c53
Show file tree
Hide file tree
Showing 73 changed files with 42 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,35 @@ abstract class AbstractFlexContainerTest<T : Any> {
abstract fun widget(text: String, modifier: Modifier = Modifier): Widget<T>
abstract fun verifySnapshot(container: TestFlexContainer<T>, name: String? = null)

@Test fun emptyRow() {
val container = flexContainer(FlexDirection.Row)
container.alignItems(AlignItems.FlexStart)
verifySnapshot(container)
}

@Test fun emptyColumn() {
val container = flexContainer(FlexDirection.Column)
container.alignItems(AlignItems.FlexStart)
verifySnapshot(container)
}

@Test fun shortRow() {
val container = flexContainer(FlexDirection.Row)
@Test fun emptyLayout(
@TestParameter flexDirectionEnum: FlexDirectionEnum,
) {
assumeTrue(flexDirectionEnum in listOf(FlexDirectionEnum.Row, FlexDirectionEnum.Column))
val flexDirection = flexDirectionEnum.toFlexDirection()
val container = flexContainer(flexDirection)
container.alignItems(AlignItems.FlexStart)
movies.take(5).forEach { movie ->
container.add(widget(movie))
}
verifySnapshot(container)
}

@Test fun shortColumn() {
val container = flexContainer(FlexDirection.Column)
@Test fun shortLayout(
@TestParameter flexDirectionEnum: FlexDirectionEnum,
) {
assumeTrue(flexDirectionEnum in listOf(FlexDirectionEnum.Row, FlexDirectionEnum.Column))
val flexDirection = flexDirectionEnum.toFlexDirection()
val container = flexContainer(flexDirection)
container.alignItems(AlignItems.FlexStart)
movies.take(5).forEach { movie ->
container.add(widget(movie))
}
verifySnapshot(container)
}

@Test fun longRow() {
val container = flexContainer(FlexDirection.Row)
container.alignItems(AlignItems.FlexStart)
movies.forEach { movie ->
container.add(widget(movie))
}
verifySnapshot(container)
}

@Test fun longColumn() {
val container = flexContainer(FlexDirection.Column)
@Test fun longLayout(
@TestParameter flexDirectionEnum: FlexDirectionEnum,
) {
assumeTrue(flexDirectionEnum in listOf(FlexDirectionEnum.Row, FlexDirectionEnum.Column))
val flexDirection = flexDirectionEnum.toFlexDirection()
val container = flexContainer(flexDirection)
container.alignItems(AlignItems.FlexStart)
movies.forEach { movie ->
container.add(widget(movie))
Expand Down Expand Up @@ -135,36 +123,16 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container, "FlexEnd")
}

@Test fun columnWithJustifyContentCenter() {
val container = flexContainer(FlexDirection.Column)
container.width(Constraint.Fill)
container.height(Constraint.Fill)
container.alignItems(AlignItems.FlexStart)
container.justifyContent(JustifyContent.Center)
movies.forEach { movie ->
container.add(widget(movie))
}
verifySnapshot(container)
}

@Test fun columnWithJustifyContentSpaceBetween() {
val container = flexContainer(FlexDirection.Column)
container.width(Constraint.Fill)
container.height(Constraint.Fill)
container.alignItems(AlignItems.FlexStart)
container.justifyContent(JustifyContent.SpaceBetween)
movies.forEach { movie ->
container.add(widget(movie))
}
verifySnapshot(container)
}

@Test fun columnWithJustifyContentSpaceAround() {
@Test fun columnWithJustifyContent(
@TestParameter justifyContentEnum: JustifyContentEnum,
) {
assumeTrue(justifyContentEnum in listOf(JustifyContentEnum.Center, JustifyContentEnum.SpaceBetween, JustifyContentEnum.SpaceAround))
val justifyContent = justifyContentEnum.toJustifyContent()
val container = flexContainer(FlexDirection.Column)
container.width(Constraint.Fill)
container.height(Constraint.Fill)
container.alignItems(AlignItems.FlexStart)
container.justifyContent(JustifyContent.SpaceAround)
container.justifyContent(justifyContent)
movies.forEach { movie ->
container.add(widget(movie))
}
Expand Down Expand Up @@ -284,3 +252,21 @@ private fun AlignItemsEnum.toAlignItems() = when (this) {
AlignItemsEnum.Baseline -> AlignItems.Baseline
AlignItemsEnum.Stretch -> AlignItems.Stretch
}

enum class JustifyContentEnum {
FlexStart,
FlexEnd,
Center,
SpaceBetween,
SpaceAround,
SpaceEvenly,
}

private fun JustifyContentEnum.toJustifyContent() = when (this) {
JustifyContentEnum.FlexStart -> JustifyContent.FlexStart
JustifyContentEnum.FlexEnd -> JustifyContent.FlexEnd
JustifyContentEnum.Center -> JustifyContent.Center
JustifyContentEnum.SpaceBetween -> JustifyContent.SpaceBetween
JustifyContentEnum.SpaceAround -> JustifyContent.SpaceAround
JustifyContentEnum.SpaceEvenly -> JustifyContent.SpaceEvenly
}

0 comments on commit 8874c53

Please sign in to comment.