Skip to content

Commit

Permalink
[Crane] Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JolandaVerhoef committed Dec 16, 2020
1 parent 357372c commit 3278466
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.assertLabelEquals
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import dagger.hilt.android.testing.HiltAndroidRule
Expand Down Expand Up @@ -69,16 +69,16 @@ class CalendarTest {

@Test
fun scrollsToTheBottom() {
composeTestRule.onNodeWithText("January 1").assertExists()
composeTestRule.onNodeWithText("December 31").performScrollTo().performClick()
composeTestRule.onNodeWithContentDescription("January 1").assertExists()
composeTestRule.onNodeWithContentDescription("December 31").performScrollTo().performClick()
assert(datesRepository.datesSelected.toString() == "Dec 31")
}

@Test
fun onDaySelected() {
composeTestRule.onNodeWithText("January 1").assertExists()
composeTestRule.onNodeWithText("January 2").assertExists().performClick()
composeTestRule.onNodeWithText("January 3").assertExists()
composeTestRule.onNodeWithContentDescription("January 1").assertExists()
composeTestRule.onNodeWithContentDescription("January 2").assertExists().performClick()
composeTestRule.onNodeWithContentDescription("January 3").assertExists()

val datesNoSelected = composeTestRule.onDateNodes(NoSelected)
datesNoSelected[0].assertLabelEquals("January 1")
Expand All @@ -89,13 +89,13 @@ class CalendarTest {

@Test
fun twoDaysSelected() {
composeTestRule.onNodeWithText("January 2").assertExists().performClick()
composeTestRule.onNodeWithContentDescription("January 2").assertExists().performClick()

val datesNoSelectedOneClick = composeTestRule.onDateNodes(NoSelected)
datesNoSelectedOneClick[0].assertLabelEquals("January 1")
datesNoSelectedOneClick[1].assertLabelEquals("January 3")

composeTestRule.onNodeWithText("January 4").assertExists().performClick()
composeTestRule.onNodeWithContentDescription("January 4").assertExists().performClick()

composeTestRule.onDateNode(FirstDay).assertLabelEquals("January 2")
composeTestRule.onDateNode(Selected).assertLabelEquals("January 3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import org.junit.Rule
import org.junit.Test
import java.util.concurrent.CountDownLatch
import javax.inject.Inject
import kotlin.math.pow
import kotlin.math.round

@UninstallModules(DispatchersModule::class)
@HiltAndroidTest
Expand Down Expand Up @@ -118,4 +120,5 @@ class DetailsActivityTest {
}
}

private fun Double.round(decimals: Int = 2): Double = "%.${decimals}f".format(this).toDouble()
private fun Double.round(decimals: Int = 2): Double =
round(this * 10f.pow(decimals)) / 10f.pow(decimals)

0 comments on commit 3278466

Please sign in to comment.