Fixes UI tests

Change-Id: I8dd8eae9e79f111bb1ae4df2738fc0de4be25ea8
pull/1837/head
Jose Alcérreca 3 years ago committed by Don Turner
parent f6575e947b
commit b10b5b2dc6

@ -166,7 +166,10 @@ private fun testTopicEntity(
) = TopicEntity( ) = TopicEntity(
id = id, id = id,
name = name, name = name,
description = "", shortDescription = "",
longDescription = "",
url = "",
imageUrl = ""
) )
private fun testNewsResource( private fun testNewsResource(

@ -61,7 +61,10 @@ class ForYouScreenTest {
topic = Topic( topic = Topic(
id = 0, id = 0,
name = "Headlines", name = "Headlines",
shortDescription = "" shortDescription = "",
longDescription = "",
imageUrl = "",
url = ""
), ),
isFollowed = false isFollowed = false
), ),
@ -69,7 +72,10 @@ class ForYouScreenTest {
topic = Topic( topic = Topic(
id = 1, id = 1,
name = "UI", name = "UI",
shortDescription = "" shortDescription = "",
longDescription = "",
imageUrl = "",
url = ""
), ),
isFollowed = false isFollowed = false
), ),
@ -78,6 +84,9 @@ class ForYouScreenTest {
id = 2, id = 2,
name = "Tools", name = "Tools",
shortDescription = "", shortDescription = "",
longDescription = "",
imageUrl = "",
url = ""
), ),
isFollowed = false isFollowed = false
), ),
@ -122,7 +131,10 @@ class ForYouScreenTest {
topic = Topic( topic = Topic(
id = 0, id = 0,
name = "Headlines", name = "Headlines",
shortDescription = "" shortDescription = "",
longDescription = "",
imageUrl = "",
url = ""
), ),
isFollowed = false isFollowed = false
), ),
@ -130,7 +142,10 @@ class ForYouScreenTest {
topic = Topic( topic = Topic(
id = 1, id = 1,
name = "UI", name = "UI",
shortDescription = "" shortDescription = "",
longDescription = "",
imageUrl = "",
url = ""
), ),
isFollowed = true isFollowed = true
), ),
@ -139,6 +154,9 @@ class ForYouScreenTest {
id = 2, id = 2,
name = "Tools", name = "Tools",
shortDescription = "", shortDescription = "",
longDescription = "",
imageUrl = "",
url = ""
), ),
isFollowed = false isFollowed = false
), ),

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.google.samples.apps.nowinandroid.following package com.google.samples.apps.nowinandroid.feature.topic
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.junit4.createAndroidComposeRule
@ -24,11 +24,6 @@ import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic
import com.google.samples.apps.nowinandroid.core.model.data.NewsResource import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video
import com.google.samples.apps.nowinandroid.core.model.data.Topic import com.google.samples.apps.nowinandroid.core.model.data.Topic
import com.google.samples.apps.nowinandroid.feature.topic.NewsUiState
import com.google.samples.apps.nowinandroid.feature.topic.R
import com.google.samples.apps.nowinandroid.feature.topic.TopicScreen
import com.google.samples.apps.nowinandroid.feature.topic.TopicScreenUiState
import com.google.samples.apps.nowinandroid.feature.topic.TopicUiState
import kotlinx.datetime.Instant import kotlinx.datetime.Instant
import org.junit.Before import org.junit.Before
import org.junit.Rule import org.junit.Rule
@ -57,10 +52,8 @@ class TopicScreenTest {
fun niaLoadingIndicator_whenScreenIsLoading_showLoading() { fun niaLoadingIndicator_whenScreenIsLoading_showLoading() {
composeTestRule.setContent { composeTestRule.setContent {
TopicScreen( TopicScreen(
uiState = TopicScreenUiState(
topicState = TopicUiState.Loading, topicState = TopicUiState.Loading,
newsState = NewsUiState.Loading newsState = NewsUiState.Loading,
),
onBackClick = { }, onBackClick = { },
onFollowClick = { } onFollowClick = { }
) )
@ -76,10 +69,8 @@ class TopicScreenTest {
val testTopic = testTopics.first() val testTopic = testTopics.first()
composeTestRule.setContent { composeTestRule.setContent {
TopicScreen( TopicScreen(
uiState = TopicScreenUiState(
topicState = TopicUiState.Success(testTopic), topicState = TopicUiState.Success(testTopic),
newsState = NewsUiState.Loading newsState = NewsUiState.Loading,
),
onBackClick = { }, onBackClick = { },
onFollowClick = { } onFollowClick = { }
) )
@ -92,7 +83,7 @@ class TopicScreenTest {
// Description is shown // Description is shown
composeTestRule composeTestRule
.onNodeWithText(testTopic.topic.description) .onNodeWithText(testTopic.topic.longDescription)
.assertExists() .assertExists()
} }
@ -101,10 +92,8 @@ class TopicScreenTest {
val testTopic = testTopics.first() val testTopic = testTopics.first()
composeTestRule.setContent { composeTestRule.setContent {
TopicScreen( TopicScreen(
uiState = TopicScreenUiState(
topicState = TopicUiState.Loading, topicState = TopicUiState.Loading,
newsState = NewsUiState.Success(sampleNewsResources) newsState = NewsUiState.Success(sampleNewsResources),
),
onBackClick = { }, onBackClick = { },
onFollowClick = { } onFollowClick = { }
) )
@ -120,10 +109,8 @@ class TopicScreenTest {
val testTopic = testTopics.first() val testTopic = testTopics.first()
composeTestRule.setContent { composeTestRule.setContent {
TopicScreen( TopicScreen(
uiState = TopicScreenUiState(
topicState = TopicUiState.Success(testTopic), topicState = TopicUiState.Success(testTopic),
newsState = NewsUiState.Success(sampleNewsResources) newsState = NewsUiState.Success(sampleNewsResources),
),
onBackClick = { }, onBackClick = { },
onFollowClick = { } onFollowClick = { }
) )
@ -146,7 +133,10 @@ private val testTopics = listOf(
Topic( Topic(
id = 0, id = 0,
name = TOPIC_1_NAME, name = TOPIC_1_NAME,
description = TOPIC_DESC, longDescription = TOPIC_DESC,
shortDescription = "",
imageUrl = "",
url = ""
), ),
isFollowed = true isFollowed = true
), ),
@ -154,7 +144,10 @@ private val testTopics = listOf(
Topic( Topic(
id = 1, id = 1,
name = TOPIC_2_NAME, name = TOPIC_2_NAME,
description = TOPIC_DESC longDescription = TOPIC_DESC,
shortDescription = "",
imageUrl = "",
url = ""
), ),
isFollowed = false isFollowed = false
), ),
@ -162,7 +155,10 @@ private val testTopics = listOf(
Topic( Topic(
id = 2, id = 2,
name = TOPIC_3_NAME, name = TOPIC_3_NAME,
description = TOPIC_DESC longDescription = TOPIC_DESC,
shortDescription = "",
imageUrl = "",
url = ""
), ),
isFollowed = false isFollowed = false
) )
@ -187,7 +183,10 @@ private val sampleNewsResources = listOf(
Topic( Topic(
id = 0, id = 0,
name = "Headlines", name = "Headlines",
description = "" shortDescription = "",
longDescription = "",
imageUrl = "",
url = ""
) )
), ),
authors = emptyList() authors = emptyList()

@ -16,6 +16,7 @@
package com.google.samples.apps.nowinandroid.feature.topic package com.google.samples.apps.nowinandroid.feature.topic
import androidx.annotation.VisibleForTesting
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
@ -67,8 +68,9 @@ fun TopicRoute(
) )
} }
@VisibleForTesting
@Composable @Composable
private fun TopicScreen( fun TopicScreen(
topicState: TopicUiState, topicState: TopicUiState,
newsState: NewsUiState, newsState: NewsUiState,
onBackClick: () -> Unit, onBackClick: () -> Unit,

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.google.samples.apps.nowinandroid.following package com.google.samples.apps.nowinandroid.feature.topic
import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.SavedStateHandle
import app.cash.turbine.test import app.cash.turbine.test
@ -25,10 +25,7 @@ import com.google.samples.apps.nowinandroid.core.model.data.Topic
import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepository import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepository
import com.google.samples.apps.nowinandroid.core.testing.repository.TestTopicsRepository import com.google.samples.apps.nowinandroid.core.testing.repository.TestTopicsRepository
import com.google.samples.apps.nowinandroid.core.testing.util.TestDispatcherRule import com.google.samples.apps.nowinandroid.core.testing.util.TestDispatcherRule
import com.google.samples.apps.nowinandroid.feature.topic.NewsUiState
import com.google.samples.apps.nowinandroid.feature.topic.TopicDestinationsArgs.TOPIC_ID_ARG import com.google.samples.apps.nowinandroid.feature.topic.TopicDestinationsArgs.TOPIC_ID_ARG
import com.google.samples.apps.nowinandroid.feature.topic.TopicUiState
import com.google.samples.apps.nowinandroid.feature.topic.TopicViewModel
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.runTest
import kotlinx.datetime.Instant import kotlinx.datetime.Instant
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals

@ -55,4 +55,11 @@ dependencies {
kapt libs.hilt.ext.compiler kapt libs.hilt.ext.compiler
androidTestImplementation libs.androidx.work.testing androidTestImplementation libs.androidx.work.testing
configurations.configureEach {
resolutionStrategy {
// Temporary workaround for https://issuetracker.google.com/174733673
force 'org.objenesis:objenesis:2.6'
}
}
} }

Loading…
Cancel
Save