Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote AbstractFlexContainerTest to commonMain #1574

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Square, Inc.
* Copyright (C) 2023 Square, Inc.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume a robot did this? I have no recollection.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you F6 a file it will update the copyright for some reason.

*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,9 +30,8 @@ import app.cash.redwood.ui.dp
import app.cash.redwood.widget.ChangeListener
import app.cash.redwood.widget.Widget
import app.cash.redwood.yoga.FlexDirection
import com.google.testing.junit.testparameterinjector.TestParameter
import org.junit.Assume.assumeTrue
import org.junit.Test
import kotlin.test.Test
import kotlin.test.assertTrue

@Suppress("JUnitMalformedDeclaration")
abstract class AbstractFlexContainerTest<T : Any> {
Expand All @@ -45,8 +44,16 @@ abstract class AbstractFlexContainerTest<T : Any> {
this.modifier = modifier
}

@Test fun emptyLayout(
@TestParameter flexDirectionEnum: FlexDirectionEnum,
@Test fun emptyLayout_Column() {
emptyLayout(FlexDirectionEnum.Column)
}

@Test fun emptyLayout_Row() {
emptyLayout(FlexDirectionEnum.Row)
}

private fun emptyLayout(
flexDirectionEnum: FlexDirectionEnum,
) {
assumeTrue(flexDirectionEnum in listOf(FlexDirectionEnum.Row, FlexDirectionEnum.Column))
val flexDirection = flexDirectionEnum.value
Expand All @@ -56,10 +63,42 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container)
}

@Test fun layoutWithConstraints(
@TestParameter flexDirectionEnum: FlexDirectionEnum,
@TestParameter widthEnum: ConstraintEnum,
@TestParameter heightEnum: ConstraintEnum,
@Test fun layoutWithConstraints_Column_Wrap_Wrap() {
layoutWithConstraints(FlexDirectionEnum.Column, ConstraintEnum.Wrap, ConstraintEnum.Wrap)
}

@Test fun layoutWithConstraints_Column_Wrap_Fill() {
layoutWithConstraints(FlexDirectionEnum.Column, ConstraintEnum.Wrap, ConstraintEnum.Fill)
}

@Test fun layoutWithConstraints_Column_Fill_Wrap() {
layoutWithConstraints(FlexDirectionEnum.Column, ConstraintEnum.Fill, ConstraintEnum.Wrap)
}

@Test fun layoutWithConstraints_Column_Fill_Fill() {
layoutWithConstraints(FlexDirectionEnum.Column, ConstraintEnum.Fill, ConstraintEnum.Fill)
}

@Test fun layoutWithConstraints_Row_Wrap_Wrap() {
layoutWithConstraints(FlexDirectionEnum.Row, ConstraintEnum.Wrap, ConstraintEnum.Wrap)
}

@Test fun layoutWithConstraints_Row_Wrap_Fill() {
layoutWithConstraints(FlexDirectionEnum.Row, ConstraintEnum.Wrap, ConstraintEnum.Fill)
}

@Test fun layoutWithConstraints_Row_Fill_Wrap() {
layoutWithConstraints(FlexDirectionEnum.Row, ConstraintEnum.Fill, ConstraintEnum.Wrap)
}

@Test fun layoutWithConstraints_Row_Fill_Fill() {
layoutWithConstraints(FlexDirectionEnum.Row, ConstraintEnum.Fill, ConstraintEnum.Fill)
}

private fun layoutWithConstraints(
flexDirectionEnum: FlexDirectionEnum,
widthEnum: ConstraintEnum,
heightEnum: ConstraintEnum,
) {
assumeTrue(flexDirectionEnum in listOf(FlexDirectionEnum.Row, FlexDirectionEnum.Column))
val flexDirection = flexDirectionEnum.value
Expand All @@ -73,8 +112,16 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container)
}

@Test fun shortLayout(
@TestParameter flexDirectionEnum: FlexDirectionEnum,
@Test fun shortLayout_Column() {
shortLayout(FlexDirectionEnum.Column)
}

@Test fun shortLayout_Row() {
shortLayout(FlexDirectionEnum.Row)
}

private fun shortLayout(
flexDirectionEnum: FlexDirectionEnum,
) {
assumeTrue(flexDirectionEnum in listOf(FlexDirectionEnum.Row, FlexDirectionEnum.Column))
val flexDirection = flexDirectionEnum.value
Expand All @@ -87,8 +134,16 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container)
}

@Test fun longLayout(
@TestParameter flexDirectionEnum: FlexDirectionEnum,
@Test fun longLayout_Column() {
longLayout(FlexDirectionEnum.Column)
}

@Test fun longLayout_Row() {
longLayout(FlexDirectionEnum.Row)
}

private fun longLayout(
flexDirectionEnum: FlexDirectionEnum,
) {
assumeTrue(flexDirectionEnum in listOf(FlexDirectionEnum.Row, FlexDirectionEnum.Column))
val flexDirection = flexDirectionEnum.value
Expand All @@ -101,8 +156,16 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container)
}

@Test fun layoutWithMarginAndDifferentAlignments(
@TestParameter flexDirectionEnum: FlexDirectionEnum,
@Test fun layoutWithMarginAndDifferentAlignments_Column() {
layoutWithMarginAndDifferentAlignments(FlexDirectionEnum.Column)
}

@Test fun layoutWithMarginAndDifferentAlignments_Row() {
layoutWithMarginAndDifferentAlignments(FlexDirectionEnum.Row)
}

private fun layoutWithMarginAndDifferentAlignments(
flexDirectionEnum: FlexDirectionEnum,
) {
assumeTrue(flexDirectionEnum in listOf(FlexDirectionEnum.Row, FlexDirectionEnum.Column))
val flexDirection = flexDirectionEnum.value
Expand All @@ -123,9 +186,41 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container)
}

@Test fun layoutWithCrossAxisAlignment(
@TestParameter flexDirectionEnum: FlexDirectionEnum,
@TestParameter crossAxisAlignmentEnum: CrossAxisAlignmentEnum,
@Test fun layoutWithCrossAxisAlignment_Column_Start() {
layoutWithCrossAxisAlignment(FlexDirectionEnum.Column, CrossAxisAlignmentEnum.Start)
}

@Test fun layoutWithCrossAxisAlignment_Column_Center() {
layoutWithCrossAxisAlignment(FlexDirectionEnum.Column, CrossAxisAlignmentEnum.Center)
}

@Test fun layoutWithCrossAxisAlignment_Column_End() {
layoutWithCrossAxisAlignment(FlexDirectionEnum.Column, CrossAxisAlignmentEnum.End)
}

@Test fun layoutWithCrossAxisAlignment_Column_Stretch() {
layoutWithCrossAxisAlignment(FlexDirectionEnum.Column, CrossAxisAlignmentEnum.Stretch)
}

@Test fun layoutWithCrossAxisAlignment_Row_Start() {
layoutWithCrossAxisAlignment(FlexDirectionEnum.Row, CrossAxisAlignmentEnum.Start)
}

@Test fun layoutWithCrossAxisAlignment_Row_Center() {
layoutWithCrossAxisAlignment(FlexDirectionEnum.Row, CrossAxisAlignmentEnum.Center)
}

@Test fun layoutWithCrossAxisAlignment_Row_End() {
layoutWithCrossAxisAlignment(FlexDirectionEnum.Row, CrossAxisAlignmentEnum.End)
}

@Test fun layoutWithCrossAxisAlignment_Row_Stretch() {
layoutWithCrossAxisAlignment(FlexDirectionEnum.Row, CrossAxisAlignmentEnum.Stretch)
}

private fun layoutWithCrossAxisAlignment(
flexDirectionEnum: FlexDirectionEnum,
crossAxisAlignmentEnum: CrossAxisAlignmentEnum,
) {
assumeTrue(flexDirectionEnum in listOf(FlexDirectionEnum.Row, FlexDirectionEnum.Column))
val flexDirection = flexDirectionEnum.value
Expand Down Expand Up @@ -157,8 +252,20 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container, "FlexEnd")
}

@Test fun columnWithMainAxisAlignment(
@TestParameter mainAxisAlignmentEnum: MainAxisAlignmentEnum,
@Test fun columnWithMainAxisAlignment_Center() {
columnWithMainAxisAlignment(MainAxisAlignmentEnum.Center)
}

@Test fun columnWithMainAxisAlignment_SpaceBetween() {
columnWithMainAxisAlignment(MainAxisAlignmentEnum.SpaceBetween)
}

@Test fun columnWithMainAxisAlignment_SpaceAround() {
columnWithMainAxisAlignment(MainAxisAlignmentEnum.SpaceAround)
}

private fun columnWithMainAxisAlignment(
mainAxisAlignmentEnum: MainAxisAlignmentEnum,
) {
assumeTrue(mainAxisAlignmentEnum in listOf(MainAxisAlignmentEnum.Center, MainAxisAlignmentEnum.SpaceBetween, MainAxisAlignmentEnum.SpaceAround))
val mainAxisAlignment = mainAxisAlignmentEnum.value
Expand Down Expand Up @@ -223,6 +330,11 @@ abstract class AbstractFlexContainerTest<T : Any> {
container.onEndChanges()
verifySnapshot(container, "updated")
}

/** We don't have assume() on kotlin.test. Tests that fail here should be skipped instead. */
private fun assumeTrue(b: Boolean) {
assertTrue(b)
}
Comment on lines +334 to +337
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete? And delete call-sites? Presumably you did not create invalid variants when exploding them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn’t, but I want to keep the assume calls around for when we later do burst.

}

interface TestFlexContainer<T : Any> : ChangeListener {
Expand Down