File tree Expand file tree Collapse file tree
app/src/test/java/io/github/tobyhs/weatherweight Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
1414import io.github.tobyhs.weatherweight.R
1515import io.github.tobyhs.weatherweight.data.model.ForecastResultSet
1616import io.github.tobyhs.weatherweight.test.ForecastResultSetFactory
17- import io.github.tobyhs.weatherweight.test.TestCompositionLocalProvider
17+ import io.github.tobyhs.weatherweight.test.setContentWithTestProvider
1818import io.github.tobyhs.weatherweight.ui.LoadState
1919
2020import io.mockk.every
@@ -116,10 +116,8 @@ class ForecastScreenTest {
116116 }
117117
118118 private fun setContent () {
119- composeRule.setContent {
120- TestCompositionLocalProvider {
121- ForecastScreen (viewModel)
122- }
119+ setContentWithTestProvider(composeRule) {
120+ ForecastScreen (viewModel)
123121 }
124122 }
125123
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import androidx.compose.ui.test.onAllNodesWithTag
77import androidx.test.ext.junit.runners.AndroidJUnit4
88
99import io.github.tobyhs.weatherweight.test.ForecastResultSetFactory
10- import io.github.tobyhs.weatherweight.test.TestCompositionLocalProvider
10+ import io.github.tobyhs.weatherweight.test.setContentWithTestProvider
1111
1212import org.junit.Rule
1313import org.junit.Test
@@ -19,10 +19,8 @@ class HourlyForecastCardTest {
1919
2020 @Test
2121 fun compose () {
22- composeRule.setContent {
23- TestCompositionLocalProvider {
24- HourlyForecastCard (ForecastResultSetFactory .createHourlyForecasts()[0 ])
25- }
22+ setContentWithTestProvider(composeRule) {
23+ HourlyForecastCard (ForecastResultSetFactory .createHourlyForecasts()[0 ])
2624 }
2725 checkContent(composeRule)
2826 }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package io.github.tobyhs.weatherweight.test
22
33import androidx.compose.runtime.Composable
44import androidx.compose.runtime.CompositionLocalProvider
5+ import androidx.compose.ui.test.junit4.ComposeContentTestRule
56
67import io.github.tobyhs.weatherweight.ui.LocalClock
78
@@ -13,3 +14,7 @@ fun TestCompositionLocalProvider(content: @Composable () -> Unit) {
1314 val clock = Clock .system(ZoneId .of(" America/Los_Angeles" ))
1415 CompositionLocalProvider (LocalClock provides clock, content)
1516}
17+
18+ fun setContentWithTestProvider (composeRule : ComposeContentTestRule , content : @Composable () -> Unit ) {
19+ composeRule.setContent { TestCompositionLocalProvider (content) }
20+ }
You can’t perform that action at this time.
0 commit comments