Fixes UI tests

Change-Id: I8dd8eae9e79f111bb1ae4df2738fc0de4be25ea8
pull/2/head
Jose Alcérreca 3 years ago committed by Don Turner
parent 1cd5190305
commit 22545bfb32

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

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

@ -14,7 +14,7 @@
* 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.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.NewsResourceType.Video
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 org.junit.Before
import org.junit.Rule
@ -57,10 +52,8 @@ class TopicScreenTest {
fun niaLoadingIndicator_whenScreenIsLoading_showLoading() {
composeTestRule.setContent {
TopicScreen(
uiState = TopicScreenUiState(
topicState = TopicUiState.Loading,
newsState = NewsUiState.Loading
),
topicState = TopicUiState.Loading,
newsState = NewsUiState.Loading,
onBackClick = { },
onFollowClick = { }
)
@ -76,10 +69,8 @@ class TopicScreenTest {
val testTopic = testTopics.first()
composeTestRule.setContent {
TopicScreen(
uiState = TopicScreenUiState(
topicState = TopicUiState.Success(testTopic),
newsState = NewsUiState.Loading
),
topicState = TopicUiState.Success(testTopic),
newsState = NewsUiState.Loading,
onBackClick = { },
onFollowClick = { }
)
@ -92,7 +83,7 @@ class TopicScreenTest {
// Description is shown
composeTestRule
.onNodeWithText(testTopic.topic.description)
.onNodeWithText(testTopic.topic.longDescription)
.assertExists()
}
@ -101,10 +92,8 @@ class TopicScreenTest {
val testTopic = testTopics.first()
composeTestRule.setContent {
TopicScreen(
uiState = TopicScreenUiState(
topicState = TopicUiState.Loading,
newsState = NewsUiState.Success(sampleNewsResources)
),
topicState = TopicUiState.Loading,
newsState = NewsUiState.Success(sampleNewsResources),
onBackClick = { },
onFollowClick = { }
)
@ -120,10 +109,8 @@ class TopicScreenTest {
val testTopic = testTopics.first()
composeTestRule.setContent {
TopicScreen(
uiState = TopicScreenUiState(
topicState = TopicUiState.Success(testTopic),
newsState = NewsUiState.Success(sampleNewsResources)
),
topicState = TopicUiState.Success(testTopic),
newsState = NewsUiState.Success(sampleNewsResources),
onBackClick = { },
onFollowClick = { }
)
@ -146,7 +133,10 @@ private val testTopics = listOf(
Topic(
id = 0,
name = TOPIC_1_NAME,
description = TOPIC_DESC,
longDescription = TOPIC_DESC,
shortDescription = "",
imageUrl = "",
url = ""
),
isFollowed = true
),
@ -154,7 +144,10 @@ private val testTopics = listOf(
Topic(
id = 1,
name = TOPIC_2_NAME,
description = TOPIC_DESC
longDescription = TOPIC_DESC,
shortDescription = "",
imageUrl = "",
url = ""
),
isFollowed = false
),
@ -162,7 +155,10 @@ private val testTopics = listOf(
Topic(
id = 2,
name = TOPIC_3_NAME,
description = TOPIC_DESC
longDescription = TOPIC_DESC,
shortDescription = "",
imageUrl = "",
url = ""
),
isFollowed = false
)
@ -187,7 +183,10 @@ private val sampleNewsResources = listOf(
Topic(
id = 0,
name = "Headlines",
description = ""
shortDescription = "",
longDescription = "",
imageUrl = "",
url = ""
)
),
authors = emptyList()

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

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.google.samples.apps.nowinandroid.following
package com.google.samples.apps.nowinandroid.feature.topic
import androidx.lifecycle.SavedStateHandle
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.TestTopicsRepository
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.TopicUiState
import com.google.samples.apps.nowinandroid.feature.topic.TopicViewModel
import kotlinx.coroutines.test.runTest
import kotlinx.datetime.Instant
import org.junit.Assert.assertEquals

@ -55,4 +55,11 @@ dependencies {
kapt libs.hilt.ext.compiler
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