Improve test data and add UI test for topic chip

pull/1681/head
Don Turner 2 months ago
parent 89795c98b5
commit ecfb5157dd

@ -267,4 +267,27 @@ class NavigationTest {
onNodeWithTag("topic:${topic.id}").assertExists() onNodeWithTag("topic:${topic.id}").assertExists()
} }
} }
@Test
fun navigatingToTopicFromForYou_showsTopicDetails() {
composeTestRule.apply {
// Follow a topic
onNodeWithText(sampleTopic).performClick()
// Get the topic ID
val topic = runBlocking {
topicsRepository.getTopics().first().filter { it.name == sampleTopic }.first()
}
// Tap the first topic chip
onNodeWithTag("topicChip:${topic.id}", useUnmergedTree = true)
.performClick()
// TEST FAILING HERE
composeTestRule.waitUntil(timeoutMillis = 3_600_000, condition = { false })
// Verify that we're on the correct topic details screen
onNodeWithTag("topic:${topic.id}").assertExists()
}
}
} }

@ -17,16 +17,13 @@
package com.google.samples.apps.nowinandroid.core.data.test.repository package com.google.samples.apps.nowinandroid.core.data.test.repository
import com.google.samples.apps.nowinandroid.core.data.Synchronizer import com.google.samples.apps.nowinandroid.core.data.Synchronizer
import com.google.samples.apps.nowinandroid.core.data.model.asEntity
import com.google.samples.apps.nowinandroid.core.data.repository.NewsRepository import com.google.samples.apps.nowinandroid.core.data.repository.NewsRepository
import com.google.samples.apps.nowinandroid.core.data.repository.NewsResourceQuery import com.google.samples.apps.nowinandroid.core.data.repository.NewsResourceQuery
import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceEntity
import com.google.samples.apps.nowinandroid.core.database.model.asExternalModel
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.network.Dispatcher import com.google.samples.apps.nowinandroid.core.network.Dispatcher
import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers.IO import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers.IO
import com.google.samples.apps.nowinandroid.core.network.demo.DemoNiaNetworkDataSource import com.google.samples.apps.nowinandroid.core.network.demo.DemoNiaNetworkDataSource
import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource import com.google.samples.apps.nowinandroid.core.network.model.asExternalModel
import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
@ -48,9 +45,11 @@ class FakeNewsRepository @Inject constructor(
query: NewsResourceQuery, query: NewsResourceQuery,
): Flow<List<NewsResource>> = ): Flow<List<NewsResource>> =
flow { flow {
val newsResources = datasource.getNewsResources()
val topics = datasource.getTopics()
emit( emit(
datasource newsResources
.getNewsResources()
.filter { networkNewsResource -> .filter { networkNewsResource ->
// Filter out any news resources which don't match the current query. // Filter out any news resources which don't match the current query.
// If no query parameters (filterTopicIds or filterNewsIds) are specified // If no query parameters (filterTopicIds or filterNewsIds) are specified
@ -64,8 +63,7 @@ class FakeNewsRepository @Inject constructor(
) )
.all(true::equals) .all(true::equals)
} }
.map(NetworkNewsResource::asEntity) .map { it.asExternalModel(topics) },
.map(NewsResourceEntity::asExternalModel),
) )
}.flowOn(ioDispatcher) }.flowOn(ioDispatcher)

@ -35,6 +35,20 @@ data class NetworkNewsResource(
val topics: List<String> = listOf(), val topics: List<String> = listOf(),
) )
fun NetworkNewsResource.asExternalModel(topics: List<NetworkTopic>) =
NewsResource(
id = id,
title = title,
content = content,
url = url,
headerImageUrl = headerImageUrl,
publishDate = publishDate,
type = type,
topics = topics
.filter { networkTopic -> this.topics.contains(networkTopic.id) }
.map(NetworkTopic::asExternalModel),
)
/** /**
* Network representation of [NewsResource] when fetched from /newsresources/{id} * Network representation of [NewsResource] when fetched from /newsresources/{id}
*/ */

@ -32,3 +32,13 @@ data class NetworkTopic(
val imageUrl: String = "", val imageUrl: String = "",
val followed: Boolean = false, val followed: Boolean = false,
) )
fun NetworkTopic.asExternalModel(): Topic =
Topic(
id = id,
name = name,
shortDescription = shortDescription,
longDescription = longDescription,
url = url,
imageUrl = imageUrl,
)

@ -56,6 +56,7 @@ import androidx.compose.ui.draganddrop.DragAndDropTransferData
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalInspectionMode import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.contentDescription
@ -341,6 +342,7 @@ fun NewsResourceTopics(
}, },
) )
}, },
modifier = Modifier.testTag("topicChip:${followableTopic.topic.id}"),
) )
} }
} }

Loading…
Cancel
Save