diff --git a/core/data/build.gradle.kts b/core/data/build.gradle.kts index 717082bfe5..0fd9e1615b 100644 --- a/core/data/build.gradle.kts +++ b/core/data/build.gradle.kts @@ -44,4 +44,6 @@ dependencies { implementation(libs.kotlinx.datetime) implementation(libs.kotlinx.coroutines.android) implementation(libs.kotlinx.serialization.json) + + testImplementation(testFixtures(project(":core:model"))) } \ No newline at end of file diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt index 504277e237..7036563231 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt @@ -16,10 +16,8 @@ package com.google.samples.apps.nowinandroid.core.database.model -import com.google.samples.apps.nowinandroid.core.model.data.Author 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 kotlin.test.assertEquals import kotlinx.datetime.Instant import org.junit.Test @@ -58,39 +56,20 @@ class PopulatedNewsResourceKtTest { ) ), ) - val newsResource = populatedNewsResource.asExternalModel() assertEquals( NewsResource( - id = "1", - title = "news", - content = "Hilt", - url = "url", - headerImageUrl = "headerImageUrl", - type = Video, - publishDate = Instant.fromEpochMilliseconds(1), - authors = listOf( - Author( - id = "2", - name = "name", - imageUrl = "imageUrl", - twitter = "twitter", - mediumPage = "mediumPage", - bio = "bio", - ) - ), - topics = listOf( - Topic( - id = "3", - name = "name", - shortDescription = "short description", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ) - ) + id = populatedNewsResource.entity.id, + title = populatedNewsResource.entity.title, + content = populatedNewsResource.entity.content, + url = populatedNewsResource.entity.url, + headerImageUrl = populatedNewsResource.entity.headerImageUrl, + publishDate = populatedNewsResource.entity.publishDate, + type = populatedNewsResource.entity.type, + authors = populatedNewsResource.authors.map(AuthorEntity::asExternalModel), + topics = populatedNewsResource.topics.map(TopicEntity::asExternalModel), ), - newsResource + populatedNewsResource.asExternalModel() ) } } diff --git a/core/domain/build.gradle.kts b/core/domain/build.gradle.kts index 47d07d65ef..c5c1b62050 100644 --- a/core/domain/build.gradle.kts +++ b/core/domain/build.gradle.kts @@ -31,4 +31,6 @@ dependencies { implementation(libs.hilt.android) kapt(libs.hilt.compiler) + + testImplementation(testFixtures(project(":core:model"))) } \ No newline at end of file diff --git a/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetFollowableTopicsStreamUseCaseTest.kt b/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetFollowableTopicsStreamUseCaseTest.kt index a3fff0d20d..9f11a0b33e 100644 --- a/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetFollowableTopicsStreamUseCaseTest.kt +++ b/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetFollowableTopicsStreamUseCaseTest.kt @@ -18,10 +18,11 @@ package com.google.samples.apps.nowinandroid.core.domain import com.google.samples.apps.nowinandroid.core.domain.TopicSortField.NAME import com.google.samples.apps.nowinandroid.core.domain.model.FollowableTopic -import com.google.samples.apps.nowinandroid.core.model.data.Topic +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeTopic import com.google.samples.apps.nowinandroid.core.testing.repository.TestTopicsRepository import com.google.samples.apps.nowinandroid.core.testing.repository.TestUserDataRepository import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule +import kotlin.random.Random import kotlin.test.assertEquals import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest @@ -87,7 +88,7 @@ class GetFollowableTopicsStreamUseCaseTest { } private val testTopics = listOf( - Topic("1", "Headlines", "", "", "", ""), - Topic("2", "Android Studio", "", "", "", ""), - Topic("3", "Compose", "", "", "", ""), + Random.nextFakeTopic(id = "1", name = "Headlines"), + Random.nextFakeTopic(id = "2", name = "Android Studio"), + Random.nextFakeTopic(id = "3", name = "Compose"), ) diff --git a/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetSaveableNewsResourcesStreamUseCaseTest.kt b/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetSaveableNewsResourcesStreamUseCaseTest.kt index 062fb4dc24..cbe17f7c48 100644 --- a/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetSaveableNewsResourcesStreamUseCaseTest.kt +++ b/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetSaveableNewsResourcesStreamUseCaseTest.kt @@ -17,17 +17,16 @@ package com.google.samples.apps.nowinandroid.core.domain import com.google.samples.apps.nowinandroid.core.domain.model.SaveableNewsResource -import com.google.samples.apps.nowinandroid.core.model.data.Author -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.core.model.data.nextFakeAuthor +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeNewsResource +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeTopic import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepository import com.google.samples.apps.nowinandroid.core.testing.repository.TestUserDataRepository import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule +import kotlin.random.Random import kotlin.test.assertEquals import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest -import kotlinx.datetime.Instant import org.junit.Rule import org.junit.Test @@ -125,81 +124,25 @@ class GetSaveableNewsResourcesStreamUseCaseTest { } } -private val sampleTopic1 = Topic( - id = "Topic1", - name = "Headlines", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", -) - -private val sampleTopic2 = Topic( - id = "Topic2", - name = "UI", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", -) - -private val sampleAuthor1 = - Author( - id = "Author1", - name = "Android Dev", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ) - -private val sampleAuthor2 = - Author( - id = "Author2", - name = "Android Dev", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ) +private val sampleTopic1 = Random.nextFakeTopic(id = "1", name = "Headlines") +private val sampleTopic2 = Random.nextFakeTopic(id = "2", name = "UI") +private val sampleAuthor1 = Random.nextFakeAuthor(id = "1") +private val sampleAuthor2 = Random.nextFakeAuthor(id = "2") private val sampleNewsResources = listOf( - NewsResource( + Random.nextFakeNewsResource( id = "1", - title = "Thanks for helping us reach 1M YouTube Subscribers", - content = "Thank you everyone for following the Now in Android series and everything the " + - "Android Developers YouTube channel has to offer. During the Android Developer " + - "Summit, our YouTube channel reached 1 million subscribers! Here’s a small video to " + - "thank you all.", - url = "https://youtu.be/-fJ6poHQrjM", - headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", - publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, - topics = listOf(sampleTopic1), - authors = listOf(sampleAuthor1) + authors = listOf(sampleAuthor1), + topics = listOf(sampleTopic1) ), - NewsResource( + Random.nextFakeNewsResource( id = "2", - title = "Transformations and customisations in the Paging Library", - content = "A demonstration of different operations that can be performed with Paging. " + - "Transformations like inserting separators, when to create a new pager, and " + - "customisation options for consuming PagingData.", - url = "https://youtu.be/ZARz0pjm5YM", - headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", - publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), - type = Video, - topics = listOf(sampleTopic1, sampleTopic2), - authors = listOf(sampleAuthor1) + authors = listOf(sampleAuthor1), + topics = listOf(sampleTopic1, sampleTopic2) ), - NewsResource( + Random.nextFakeNewsResource( id = "3", - title = "Community tip on Paging", - content = "Tips for using the Paging library from the developer community", - url = "https://youtu.be/r5JgIyS3t3s", - headerImageUrl = "https://i.ytimg.com/vi/r5JgIyS3t3s/maxresdefault.jpg", - publishDate = Instant.parse("2021-11-08T00:00:00.000Z"), - type = Video, - topics = listOf(sampleTopic2), - authors = listOf(sampleAuthor2) + authors = listOf(sampleAuthor2), + topics = listOf(sampleTopic2) ), ) diff --git a/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetSortedFollowableAuthorsStreamUseCaseTest.kt b/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetSortedFollowableAuthorsStreamUseCaseTest.kt index 24b88a88b3..ef8e66e90f 100644 --- a/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetSortedFollowableAuthorsStreamUseCaseTest.kt +++ b/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetSortedFollowableAuthorsStreamUseCaseTest.kt @@ -17,10 +17,11 @@ package com.google.samples.apps.nowinandroid.core.domain import com.google.samples.apps.nowinandroid.core.domain.model.FollowableAuthor -import com.google.samples.apps.nowinandroid.core.model.data.Author +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeAuthor import com.google.samples.apps.nowinandroid.core.testing.repository.TestAuthorsRepository import com.google.samples.apps.nowinandroid.core.testing.repository.TestUserDataRepository import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule +import kotlin.random.Random import kotlin.test.assertEquals import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest @@ -64,34 +65,8 @@ class GetSortedFollowableAuthorsStreamUseCaseTest { } } -private val sampleAuthor1 = - Author( - id = "Author1", - name = "Mandy", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ) - -private val sampleAuthor2 = - Author( - id = "Author2", - name = "Andy", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ) - -private val sampleAuthor3 = - Author( - id = "Author2", - name = "Sandy", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ) +private val sampleAuthor1 = Random.nextFakeAuthor(id = "1", name = "Mandy") +private val sampleAuthor2 = Random.nextFakeAuthor(id = "2", name = "Andy") +private val sampleAuthor3 = Random.nextFakeAuthor(id = "3", name = "Sandy") private val sampleAuthors = listOf(sampleAuthor1, sampleAuthor2, sampleAuthor3) diff --git a/core/model/build.gradle.kts b/core/model/build.gradle.kts index edfcc45968..1c27e83d39 100644 --- a/core/model/build.gradle.kts +++ b/core/model/build.gradle.kts @@ -17,8 +17,10 @@ @Suppress("DSL_SCOPE_VIOLATION") plugins { id("kotlin") + `java-test-fixtures` } dependencies { implementation(libs.kotlinx.datetime) + testFixturesImplementation(libs.kotlinx.datetime) } \ No newline at end of file diff --git a/core/model/src/testFixtures/kotlin/com/google/samples/apps/nowinandroid/core/model/data/AuthorFixtures.kt b/core/model/src/testFixtures/kotlin/com/google/samples/apps/nowinandroid/core/model/data/AuthorFixtures.kt new file mode 100644 index 0000000000..35be63c5c5 --- /dev/null +++ b/core/model/src/testFixtures/kotlin/com/google/samples/apps/nowinandroid/core/model/data/AuthorFixtures.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.samples.apps.nowinandroid.core.model.data + +import kotlin.random.Random + +fun Random.nextFakeAuthor( + id: String = nextLong().toString(), + name: String = "Android Dev $id", + imageUrl: String = "https://example.org/dev-android/$id.png", + twitter: String = "@dev-android-$id", + mediumPage: String = "https://medium.com/dev-android/$id", + bio: String = "", +): Author = Author( + id = id, + name = name, + imageUrl = imageUrl, + twitter = twitter, + mediumPage = mediumPage, + bio = bio, +) diff --git a/core/model/src/testFixtures/kotlin/com/google/samples/apps/nowinandroid/core/model/data/NewsResourceFixtures.kt b/core/model/src/testFixtures/kotlin/com/google/samples/apps/nowinandroid/core/model/data/NewsResourceFixtures.kt new file mode 100644 index 0000000000..768b47fe2e --- /dev/null +++ b/core/model/src/testFixtures/kotlin/com/google/samples/apps/nowinandroid/core/model/data/NewsResourceFixtures.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.samples.apps.nowinandroid.core.model.data + +import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Unknown +import kotlin.random.Random +import kotlinx.datetime.Instant + +fun Random.nextFakeNewsResource( + id: String = nextLong().toString(), + title: String = "News resource $id", + content: String = "", + url: String = "https://example.org/news/$id", + headerImageUrl: String? = "https://example.org/news/$id.png", + publishDate: Instant = Instant.fromEpochMilliseconds(0), + type: NewsResourceType = Unknown, + authors: List = emptyList(), + topics: List = emptyList(), +): NewsResource = NewsResource( + id = id, + title = title, + content = content, + url = url, + headerImageUrl = headerImageUrl, + publishDate = publishDate, + type = type, + authors = authors, + topics = topics, +) diff --git a/core/model/src/testFixtures/kotlin/com/google/samples/apps/nowinandroid/core/model/data/TopicFixtures.kt b/core/model/src/testFixtures/kotlin/com/google/samples/apps/nowinandroid/core/model/data/TopicFixtures.kt new file mode 100644 index 0000000000..b8e229a9c0 --- /dev/null +++ b/core/model/src/testFixtures/kotlin/com/google/samples/apps/nowinandroid/core/model/data/TopicFixtures.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.samples.apps.nowinandroid.core.model.data + +import kotlin.random.Random + +fun Random.nextFakeTopic( + id: String = Random.nextLong().toString(), + name: String = "Topic $id", + shortDescription: String = "", + longDescription: String = "", + url: String = "https://example.org/topic/$id", + imageUrl: String = "https://example.org/topic/$id.png" +): Topic = Topic( + id = id, + name = name, + shortDescription = shortDescription, + longDescription = longDescription, + url = url, + imageUrl = imageUrl, +) diff --git a/feature/author/build.gradle.kts b/feature/author/build.gradle.kts index cf52f17512..273b3cf2eb 100644 --- a/feature/author/build.gradle.kts +++ b/feature/author/build.gradle.kts @@ -25,4 +25,6 @@ android { dependencies { implementation(libs.kotlinx.datetime) + androidTestImplementation(testFixtures(project(":core:model"))) + testImplementation(testFixtures(project(":core:model"))) } diff --git a/feature/author/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/author/AuthorScreenTest.kt b/feature/author/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/author/AuthorScreenTest.kt index b955912f21..b2b65c2c53 100644 --- a/feature/author/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/author/AuthorScreenTest.kt +++ b/feature/author/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/author/AuthorScreenTest.kt @@ -22,10 +22,9 @@ import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText import com.google.samples.apps.nowinandroid.core.domain.model.FollowableAuthor import com.google.samples.apps.nowinandroid.core.domain.model.SaveableNewsResource -import com.google.samples.apps.nowinandroid.core.model.data.Author -import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video -import kotlinx.datetime.Instant +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeAuthor +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeNewsResource +import kotlin.random.Random import org.junit.Before import org.junit.Rule import org.junit.Test @@ -142,69 +141,12 @@ class AuthorScreenTest { } } -private const val AUTHOR_1_NAME = "Author 1" -private const val AUTHOR_2_NAME = "Author 2" -private const val AUTHOR_3_NAME = "Author 3" -private const val AUTHOR_BIO = "At vero eos et accusamus et iusto odio dignissimos ducimus qui." - private val testAuthors = listOf( - FollowableAuthor( - Author( - id = "0", - name = AUTHOR_1_NAME, - twitter = "", - bio = AUTHOR_BIO, - mediumPage = "", - imageUrl = "" - ), - isFollowed = true - ), - FollowableAuthor( - Author( - id = "1", - name = AUTHOR_2_NAME, - twitter = "", - bio = AUTHOR_BIO, - mediumPage = "", - imageUrl = "" - ), - isFollowed = false - ), - FollowableAuthor( - Author( - id = "2", - name = AUTHOR_3_NAME, - twitter = "", - bio = AUTHOR_BIO, - mediumPage = "", - imageUrl = "" - ), - isFollowed = false - ) + FollowableAuthor(Random.nextFakeAuthor(id = "1"), isFollowed = true), + FollowableAuthor(Random.nextFakeAuthor(id = "2"), isFollowed = false), + FollowableAuthor(Random.nextFakeAuthor(id = "3"), isFollowed = false), ) private val sampleNewsResources = listOf( - NewsResource( - id = "1", - title = "Thanks for helping us reach 1M YouTube Subscribers", - content = "Thank you everyone for following the Now in Android series and everything the " + - "Android Developers YouTube channel has to offer. During the Android Developer " + - "Summit, our YouTube channel reached 1 million subscribers! Here’s a small video to " + - "thank you all.", - url = "https://youtu.be/-fJ6poHQrjM", - headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", - publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, - authors = listOf( - Author( - id = "0", - name = "Headlines", - twitter = "", - bio = AUTHOR_BIO, - mediumPage = "", - imageUrl = "" - ) - ), - topics = emptyList() - ) + Random.nextFakeNewsResource(id = "1", authors = listOf(testAuthors.first().author)), ) diff --git a/feature/author/src/test/java/com/google/samples/apps/nowinandroid/feature/author/AuthorViewModelTest.kt b/feature/author/src/test/java/com/google/samples/apps/nowinandroid/feature/author/AuthorViewModelTest.kt index 92164ae54d..69b00750a4 100644 --- a/feature/author/src/test/java/com/google/samples/apps/nowinandroid/feature/author/AuthorViewModelTest.kt +++ b/feature/author/src/test/java/com/google/samples/apps/nowinandroid/feature/author/AuthorViewModelTest.kt @@ -19,15 +19,15 @@ package com.google.samples.apps.nowinandroid.feature.author import androidx.lifecycle.SavedStateHandle import com.google.samples.apps.nowinandroid.core.domain.GetSaveableNewsResourcesStreamUseCase import com.google.samples.apps.nowinandroid.core.domain.model.FollowableAuthor -import com.google.samples.apps.nowinandroid.core.model.data.Author -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.nextFakeAuthor +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeNewsResource import com.google.samples.apps.nowinandroid.core.testing.decoder.FakeStringDecoder import com.google.samples.apps.nowinandroid.core.testing.repository.TestAuthorsRepository import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepository import com.google.samples.apps.nowinandroid.core.testing.repository.TestUserDataRepository import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule import com.google.samples.apps.nowinandroid.feature.author.navigation.authorIdArg +import kotlin.random.Random import kotlin.test.assertEquals import kotlin.test.assertIs import kotlin.test.assertTrue @@ -37,7 +37,6 @@ import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.runTest -import kotlinx.datetime.Instant import org.junit.Before import org.junit.Rule import org.junit.Test @@ -208,108 +207,18 @@ class AuthorViewModelTest { } } -private const val AUTHOR_1_NAME = "Author 1" -private const val AUTHOR_2_NAME = "Author 2" -private const val AUTHOR_3_NAME = "Author 3" -private const val AUTHOR_BIO = "At vero eos et accusamus." -private const val AUTHOR_TWITTER = "dev" -private const val AUTHOR_MEDIUM_PAGE = "URL" -private const val AUTHOR_IMAGE_URL = "Image URL" - private val testInputAuthors = listOf( - FollowableAuthor( - Author( - id = "0", - name = AUTHOR_1_NAME, - bio = AUTHOR_BIO, - twitter = AUTHOR_TWITTER, - mediumPage = AUTHOR_MEDIUM_PAGE, - imageUrl = AUTHOR_IMAGE_URL, - ), - isFollowed = true - ), - FollowableAuthor( - Author( - id = "1", - name = AUTHOR_2_NAME, - bio = AUTHOR_BIO, - twitter = AUTHOR_TWITTER, - mediumPage = AUTHOR_MEDIUM_PAGE, - imageUrl = AUTHOR_IMAGE_URL, - ), - isFollowed = false - ), - FollowableAuthor( - Author( - id = "2", - name = AUTHOR_3_NAME, - bio = AUTHOR_BIO, - twitter = AUTHOR_TWITTER, - mediumPage = AUTHOR_MEDIUM_PAGE, - imageUrl = AUTHOR_IMAGE_URL, - ), - isFollowed = false - ) + FollowableAuthor(Random.nextFakeAuthor(id = "1"), isFollowed = true), + FollowableAuthor(Random.nextFakeAuthor(id = "2"), isFollowed = false), + FollowableAuthor(Random.nextFakeAuthor(id = "3"), isFollowed = false), ) private val testOutputAuthors = listOf( - FollowableAuthor( - Author( - id = "0", - name = AUTHOR_1_NAME, - bio = AUTHOR_BIO, - twitter = AUTHOR_TWITTER, - mediumPage = AUTHOR_MEDIUM_PAGE, - imageUrl = AUTHOR_IMAGE_URL, - ), - isFollowed = true - ), - FollowableAuthor( - Author( - id = "1", - name = AUTHOR_2_NAME, - bio = AUTHOR_BIO, - twitter = AUTHOR_TWITTER, - mediumPage = AUTHOR_MEDIUM_PAGE, - imageUrl = AUTHOR_IMAGE_URL, - ), - isFollowed = true - ), - FollowableAuthor( - Author( - id = "2", - name = AUTHOR_3_NAME, - bio = AUTHOR_BIO, - twitter = AUTHOR_TWITTER, - mediumPage = AUTHOR_MEDIUM_PAGE, - imageUrl = AUTHOR_IMAGE_URL, - ), - isFollowed = false - ) + FollowableAuthor(testInputAuthors[0].author, isFollowed = true), + FollowableAuthor(testInputAuthors[1].author, isFollowed = true), + FollowableAuthor(testInputAuthors[2].author, isFollowed = false), ) private val sampleNewsResources = listOf( - NewsResource( - id = "1", - title = "Thanks for helping us reach 1M YouTube Subscribers", - content = "Thank you everyone for following the Now in Android series and everything the " + - "Android Developers YouTube channel has to offer. During the Android Developer " + - "Summit, our YouTube channel reached 1 million subscribers! Here’s a small video to " + - "thank you all.", - url = "https://youtu.be/-fJ6poHQrjM", - headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", - publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, - authors = listOf( - Author( - id = "0", - name = "Android Dev", - bio = "Hello there!", - twitter = "dev", - mediumPage = "URL", - imageUrl = "image URL", - ) - ), - topics = emptyList() - ) + Random.nextFakeNewsResource(id = "1", authors = listOf(testInputAuthors[0].author)), ) diff --git a/feature/foryou/build.gradle.kts b/feature/foryou/build.gradle.kts index ae2d380e66..f384b5657f 100644 --- a/feature/foryou/build.gradle.kts +++ b/feature/foryou/build.gradle.kts @@ -27,4 +27,7 @@ dependencies { implementation(libs.kotlinx.datetime) implementation(libs.accompanist.flowlayout) + testImplementation(testFixtures(project(":core:model"))) + androidTestImplementation(testFixtures(project(":core:model"))) + testImplementation(testFixtures(project(":core:model"))) } diff --git a/feature/foryou/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenTest.kt b/feature/foryou/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenTest.kt index d89f5d91f8..fb39fef3ef 100644 --- a/feature/foryou/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenTest.kt +++ b/feature/foryou/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenTest.kt @@ -31,10 +31,11 @@ import androidx.compose.ui.test.performScrollToNode import com.google.samples.apps.nowinandroid.core.domain.model.FollowableAuthor import com.google.samples.apps.nowinandroid.core.domain.model.FollowableTopic import com.google.samples.apps.nowinandroid.core.domain.model.SaveableNewsResource -import com.google.samples.apps.nowinandroid.core.model.data.Author -import com.google.samples.apps.nowinandroid.core.model.data.Topic +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeAuthor +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeTopic import com.google.samples.apps.nowinandroid.core.model.data.previewNewsResources import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState +import kotlin.random.Random import org.junit.Rule import org.junit.Test @@ -341,43 +342,13 @@ class ForYouScreenTest { } } -private val testTopic = Topic( - id = "", - name = "", - shortDescription = "", - longDescription = "", - url = "", - imageUrl = "" -) -private val testAuthor = Author( - id = "", - name = "", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "" -) +private val testAuthor = Random.nextFakeAuthor() private val testTopics = listOf( - FollowableTopic( - topic = testTopic.copy(id = "0", name = "Headlines"), - isFollowed = false - ), - FollowableTopic( - topic = testTopic.copy(id = "1", name = "UI"), - isFollowed = false - ), - FollowableTopic( - topic = testTopic.copy(id = "2", name = "Tools"), - isFollowed = false - ), + FollowableTopic(topic = Random.nextFakeTopic(id = "1", name = "Headlines"), isFollowed = false), + FollowableTopic(topic = Random.nextFakeTopic(id = "2", name = "UI"), isFollowed = false), + FollowableTopic(topic = Random.nextFakeTopic(id = "3", name = "Tools"), isFollowed = false), ) private val testAuthors = listOf( - FollowableAuthor( - author = testAuthor.copy(id = "0", name = "Android Dev"), - isFollowed = false - ), - FollowableAuthor( - author = testAuthor.copy(id = "1", name = "Android Dev 2"), - isFollowed = false - ), + FollowableAuthor(author = testAuthor.copy(id = "1", name = "Android Dev"), isFollowed = false), + FollowableAuthor(author = testAuthor.copy(id = "2", name = "Android Dev 2"), isFollowed = false) ) diff --git a/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt b/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt index daeeb46c2d..e8a71be496 100644 --- a/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt +++ b/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt @@ -22,10 +22,9 @@ import com.google.samples.apps.nowinandroid.core.domain.GetSortedFollowableAutho import com.google.samples.apps.nowinandroid.core.domain.model.FollowableAuthor import com.google.samples.apps.nowinandroid.core.domain.model.FollowableTopic import com.google.samples.apps.nowinandroid.core.domain.model.SaveableNewsResource -import com.google.samples.apps.nowinandroid.core.model.data.Author -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.core.model.data.nextFakeAuthor +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeNewsResource +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeTopic import com.google.samples.apps.nowinandroid.core.testing.repository.TestAuthorsRepository import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepository import com.google.samples.apps.nowinandroid.core.testing.repository.TestTopicsRepository @@ -34,13 +33,13 @@ import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule import com.google.samples.apps.nowinandroid.core.testing.util.TestNetworkMonitor import com.google.samples.apps.nowinandroid.core.testing.util.TestSyncStatusMonitor import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState +import kotlin.random.Random import kotlin.test.assertEquals import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.runTest -import kotlinx.datetime.Instant import org.junit.Before import org.junit.Rule import org.junit.Test @@ -193,83 +192,13 @@ class ForYouViewModelTest { assertEquals( OnboardingUiState.Shown( - topics = listOf( - FollowableTopic( - topic = Topic( - id = "0", - name = "Headlines", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ), - FollowableTopic( - topic = Topic( - id = "1", - name = "UI", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ), - FollowableTopic( - topic = Topic( - id = "2", - name = "Tools", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ), - ), - authors = listOf( - FollowableAuthor( - author = Author( - id = "0", - name = "Android Dev", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ), - FollowableAuthor( - author = Author( - id = "1", - name = "Android Dev 2", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ), - FollowableAuthor( - author = Author( - id = "2", - name = "Android Dev 3", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ) - ), + topics = sampleTopics.map { FollowableTopic(it, isFollowed = false) }, + authors = sampleAuthors.map { FollowableAuthor(it, isFollowed = false) }, ), viewModel.onboardingUiState.value ) assertEquals( - NewsFeedUiState.Success( - feed = emptyList() - ), + NewsFeedUiState.Success(emptyList()), viewModel.feedState.value ) @@ -291,84 +220,13 @@ class ForYouViewModelTest { assertEquals( OnboardingUiState.Shown( - topics = listOf( - FollowableTopic( - topic = Topic( - id = "0", - name = "Headlines", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ), - FollowableTopic( - topic = Topic( - id = "1", - name = "UI", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ), - FollowableTopic( - topic = Topic( - id = "2", - name = "Tools", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ), - ), - authors = listOf( - FollowableAuthor( - author = Author( - id = "0", - name = "Android Dev", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ), - FollowableAuthor( - author = Author( - id = "1", - name = "Android Dev 2", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ), - FollowableAuthor( - author = Author( - id = "2", - name = "Android Dev 3", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ) - ), + topics = sampleTopics.map { FollowableTopic(it, isFollowed = false) }, + authors = sampleAuthors.map { FollowableAuthor(it, isFollowed = false) }, ), viewModel.onboardingUiState.value ) assertEquals( - NewsFeedUiState.Success( - feed = emptyList() - - ), + NewsFeedUiState.Success(emptyList()), viewModel.feedState.value ) @@ -385,7 +243,7 @@ class ForYouViewModelTest { authorsRepository.sendAuthors(sampleAuthors) userDataRepository.setFollowedAuthorIds(emptySet()) topicsRepository.sendTopics(sampleTopics) - userDataRepository.setFollowedTopicIds(setOf("0", "1")) + userDataRepository.setFollowedTopicIds(sampleTopics.take(2).map { it.id }.toSet()) viewModel.dismissOnboarding() assertEquals( @@ -402,13 +260,7 @@ class ForYouViewModelTest { ) assertEquals( NewsFeedUiState.Success( - feed = - sampleNewsResources.map { - SaveableNewsResource( - newsResource = it, - isSaved = false - ) - } + feed = sampleNewsResources.map { SaveableNewsResource(it, isSaved = false) } ), viewModel.feedState.value ) @@ -431,174 +283,34 @@ class ForYouViewModelTest { assertEquals( OnboardingUiState.Shown( - topics = listOf( - FollowableTopic( - topic = Topic( - id = "0", - name = "Headlines", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ), - FollowableTopic( - topic = Topic( - id = "1", - name = "UI", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ), - FollowableTopic( - topic = Topic( - id = "2", - name = "Tools", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ) - ), - authors = listOf( - FollowableAuthor( - author = Author( - id = "0", - name = "Android Dev", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ), - FollowableAuthor( - author = Author( - id = "1", - name = "Android Dev 2", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ), - FollowableAuthor( - author = Author( - id = "2", - name = "Android Dev 3", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ) - ), + topics = sampleTopics.map { FollowableTopic(it, isFollowed = false) }, + authors = sampleAuthors.map { FollowableAuthor(it, isFollowed = false) }, ), viewModel.onboardingUiState.value ) assertEquals( - NewsFeedUiState.Success( - feed = emptyList(), - ), + NewsFeedUiState.Success(emptyList()), viewModel.feedState.value ) - viewModel.updateTopicSelection("1", isChecked = true) + viewModel.updateTopicSelection(sampleTopics[1].id, isChecked = true) assertEquals( OnboardingUiState.Shown( topics = listOf( - FollowableTopic( - topic = Topic( - id = "0", - name = "Headlines", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ), - FollowableTopic( - topic = Topic( - id = "1", - name = "UI", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = true - ), - FollowableTopic( - topic = Topic( - id = "2", - name = "Tools", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ) - ), - authors = listOf( - FollowableAuthor( - author = Author( - id = "0", - name = "Android Dev", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ), - FollowableAuthor( - author = Author( - id = "1", - name = "Android Dev 2", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ), - FollowableAuthor( - author = Author( - id = "2", - name = "Android Dev 3", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ) + FollowableTopic(sampleTopics[0], isFollowed = false), + FollowableTopic(sampleTopics[1], isFollowed = true), + FollowableTopic(sampleTopics[2], isFollowed = false), ), + authors = sampleAuthors.map { FollowableAuthor(it, isFollowed = false) }, ), viewModel.onboardingUiState.value ) assertEquals( NewsFeedUiState.Success( feed = listOf( - SaveableNewsResource( - newsResource = sampleNewsResources[1], - isSaved = false - ), - SaveableNewsResource( - newsResource = sampleNewsResources[2], - isSaved = false - ) + SaveableNewsResource(sampleNewsResources[1], isSaved = false), + SaveableNewsResource(sampleNewsResources[2], isSaved = false) ) ), viewModel.feedState.value @@ -622,159 +334,25 @@ class ForYouViewModelTest { assertEquals( OnboardingUiState.Shown( - topics = listOf( - FollowableTopic( - topic = Topic( - id = "0", - name = "Headlines", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ), - FollowableTopic( - topic = Topic( - id = "1", - name = "UI", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ), - FollowableTopic( - topic = Topic( - id = "2", - name = "Tools", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ) - ), - authors = listOf( - FollowableAuthor( - author = Author( - id = "0", - name = "Android Dev", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ), - FollowableAuthor( - author = Author( - id = "1", - name = "Android Dev 2", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ), - FollowableAuthor( - author = Author( - id = "2", - name = "Android Dev 3", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ) - ), + topics = sampleTopics.map { FollowableTopic(it, isFollowed = false) }, + authors = sampleAuthors.map { FollowableAuthor(it, isFollowed = false) }, ), viewModel.onboardingUiState.value ) assertEquals( - NewsFeedUiState.Success( - feed = emptyList(), - ), + NewsFeedUiState.Success(emptyList()), viewModel.feedState.value ) - viewModel.updateAuthorSelection("1", isChecked = true) + viewModel.updateAuthorSelection(sampleAuthors[1].id, isChecked = true) assertEquals( OnboardingUiState.Shown( - topics = listOf( - FollowableTopic( - topic = Topic( - id = "0", - name = "Headlines", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ), - FollowableTopic( - topic = Topic( - id = "1", - name = "UI", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ), - FollowableTopic( - topic = Topic( - id = "2", - name = "Tools", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ) - ), + topics = sampleTopics.map { FollowableTopic(it, isFollowed = false) }, authors = listOf( - FollowableAuthor( - author = Author( - id = "0", - name = "Android Dev", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ), - FollowableAuthor( - author = Author( - id = "1", - name = "Android Dev 2", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = true - ), - FollowableAuthor( - author = Author( - id = "2", - name = "Android Dev 3", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ) + FollowableAuthor(sampleAuthors[0], isFollowed = false), + FollowableAuthor(sampleAuthors[1], isFollowed = true), + FollowableAuthor(sampleAuthors[2], isFollowed = false) ), ), viewModel.onboardingUiState.value @@ -782,14 +360,8 @@ class ForYouViewModelTest { assertEquals( NewsFeedUiState.Success( feed = listOf( - SaveableNewsResource( - newsResource = sampleNewsResources[1], - isSaved = false - ), - SaveableNewsResource( - newsResource = sampleNewsResources[2], - isSaved = false - ) + SaveableNewsResource(sampleNewsResources[1], isSaved = false), + SaveableNewsResource(sampleNewsResources[2], isSaved = false) ) ), viewModel.feedState.value @@ -810,89 +382,19 @@ class ForYouViewModelTest { authorsRepository.sendAuthors(sampleAuthors) userDataRepository.setFollowedAuthorIds(emptySet()) newsRepository.sendNewsResources(sampleNewsResources) - viewModel.updateTopicSelection("1", isChecked = true) - viewModel.updateTopicSelection("1", isChecked = false) + viewModel.updateTopicSelection(sampleTopics[1].id, isChecked = true) + viewModel.updateTopicSelection(sampleTopics[1].id, isChecked = false) advanceUntilIdle() assertEquals( OnboardingUiState.Shown( - topics = listOf( - FollowableTopic( - topic = Topic( - id = "0", - name = "Headlines", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ), - FollowableTopic( - topic = Topic( - id = "1", - name = "UI", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ), - FollowableTopic( - topic = Topic( - id = "2", - name = "Tools", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ) - ), - authors = listOf( - FollowableAuthor( - author = Author( - id = "0", - name = "Android Dev", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ), - FollowableAuthor( - author = Author( - id = "1", - name = "Android Dev 2", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ), - FollowableAuthor( - author = Author( - id = "2", - name = "Android Dev 3", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ) - ), + topics = sampleTopics.map { FollowableTopic(it, isFollowed = false) }, + authors = sampleAuthors.map { FollowableAuthor(it, isFollowed = false) }, ), viewModel.onboardingUiState.value ) assertEquals( - NewsFeedUiState.Success( - feed = emptyList() - ), + NewsFeedUiState.Success(emptyList()), viewModel.feedState.value ) @@ -911,89 +413,18 @@ class ForYouViewModelTest { authorsRepository.sendAuthors(sampleAuthors) userDataRepository.setFollowedAuthorIds(emptySet()) newsRepository.sendNewsResources(sampleNewsResources) - viewModel.updateAuthorSelection("1", isChecked = true) - viewModel.updateAuthorSelection("1", isChecked = false) + viewModel.updateAuthorSelection(sampleAuthors[1].id, isChecked = true) + viewModel.updateAuthorSelection(sampleAuthors[1].id, isChecked = false) assertEquals( - OnboardingUiState.Shown( - topics = listOf( - FollowableTopic( - topic = Topic( - id = "0", - name = "Headlines", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ), - FollowableTopic( - topic = Topic( - id = "1", - name = "UI", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ), - FollowableTopic( - topic = Topic( - id = "2", - name = "Tools", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - isFollowed = false - ) - ), - authors = listOf( - FollowableAuthor( - author = Author( - id = "0", - name = "Android Dev", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ), - FollowableAuthor( - author = Author( - id = "1", - name = "Android Dev 2", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ), - FollowableAuthor( - author = Author( - id = "2", - name = "Android Dev 3", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ) - ), + topics = sampleTopics.map { FollowableTopic(it, isFollowed = false) }, + authors = sampleAuthors.map { FollowableAuthor(it, isFollowed = false) }, ), viewModel.onboardingUiState.value ) assertEquals( - NewsFeedUiState.Success( - feed = emptyList() - ), + NewsFeedUiState.Success(emptyList()), viewModel.feedState.value ) @@ -1008,12 +439,12 @@ class ForYouViewModelTest { val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } topicsRepository.sendTopics(sampleTopics) - userDataRepository.setFollowedTopicIds(setOf("1")) + userDataRepository.setFollowedTopicIds(setOf(sampleTopics[1].id)) authorsRepository.sendAuthors(sampleAuthors) - userDataRepository.setFollowedAuthorIds(setOf("1")) + userDataRepository.setFollowedAuthorIds(setOf(sampleAuthors[1].id)) userDataRepository.setShouldHideOnboarding(true) newsRepository.sendNewsResources(sampleNewsResources) - viewModel.updateNewsResourceSaved("2", true) + viewModel.updateNewsResourceSaved(sampleNewsResources[1].id, true) assertEquals( OnboardingUiState.NotShown, @@ -1022,14 +453,8 @@ class ForYouViewModelTest { assertEquals( NewsFeedUiState.Success( feed = listOf( - SaveableNewsResource( - newsResource = sampleNewsResources[1], - isSaved = true - ), - SaveableNewsResource( - newsResource = sampleNewsResources[2], - isSaved = false - ) + SaveableNewsResource(sampleNewsResources[1], isSaved = true), + SaveableNewsResource(sampleNewsResources[2], isSaved = false) ) ), viewModel.feedState.value @@ -1041,150 +466,31 @@ class ForYouViewModelTest { } private val sampleAuthors = listOf( - Author( - id = "0", - name = "Android Dev", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - Author( - id = "1", - name = "Android Dev 2", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - Author( - id = "2", - name = "Android Dev 3", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ) + Random.nextFakeAuthor(id = "1"), + Random.nextFakeAuthor(id = "2"), + Random.nextFakeAuthor(id = "3"), ) private val sampleTopics = listOf( - Topic( - id = "0", - name = "Headlines", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - Topic( - id = "1", - name = "UI", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - Topic( - id = "2", - name = "Tools", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ) + Random.nextFakeTopic(id = "1", name = "Headlines"), + Random.nextFakeTopic(id = "2", name = "UI"), + Random.nextFakeTopic(id = "3", name = "Tools"), ) private val sampleNewsResources = listOf( - NewsResource( + Random.nextFakeNewsResource( id = "1", - title = "Thanks for helping us reach 1M YouTube Subscribers", - content = "Thank you everyone for following the Now in Android series and everything the " + - "Android Developers YouTube channel has to offer. During the Android Developer " + - "Summit, our YouTube channel reached 1 million subscribers! Here’s a small video to " + - "thank you all.", - url = "https://youtu.be/-fJ6poHQrjM", - headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", - publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, - topics = listOf( - Topic( - id = "0", - name = "Headlines", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ) - ), - authors = listOf( - Author( - id = "0", - name = "Android Dev", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ) - ) + authors = listOf(sampleAuthors[0]), + topics = listOf(sampleTopics[0]) ), - NewsResource( + Random.nextFakeNewsResource( id = "2", - title = "Transformations and customisations in the Paging Library", - content = "A demonstration of different operations that can be performed with Paging. " + - "Transformations like inserting separators, when to create a new pager, and " + - "customisation options for consuming PagingData.", - url = "https://youtu.be/ZARz0pjm5YM", - headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", - publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), - type = Video, - topics = listOf( - Topic( - id = "1", - name = "UI", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - ), - authors = listOf( - Author( - id = "1", - name = "Android Dev 2", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ) - ) + authors = listOf(sampleAuthors[1]), + topics = listOf(sampleTopics[1]) ), - NewsResource( + Random.nextFakeNewsResource( id = "3", - title = "Community tip on Paging", - content = "Tips for using the Paging library from the developer community", - url = "https://youtu.be/r5JgIyS3t3s", - headerImageUrl = "https://i.ytimg.com/vi/r5JgIyS3t3s/maxresdefault.jpg", - publishDate = Instant.parse("2021-11-08T00:00:00.000Z"), - type = Video, - topics = listOf( - Topic( - id = "1", - name = "UI", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ), - ), - authors = listOf( - Author( - id = "1", - name = "Android Dev 2", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ) - ) + authors = listOf(sampleAuthors[1]), + topics = listOf(sampleTopics[1]) ), ) diff --git a/feature/interests/build.gradle.kts b/feature/interests/build.gradle.kts index de3f7854be..42b0f90024 100644 --- a/feature/interests/build.gradle.kts +++ b/feature/interests/build.gradle.kts @@ -21,3 +21,7 @@ plugins { android { namespace = "com.google.samples.apps.nowinandroid.feature.interests" } +dependencies { + androidTestImplementation(testFixtures(project(":core:model"))) + testImplementation(testFixtures(project(":core:model"))) +} diff --git a/feature/interests/src/androidTest/java/com/google/samples/apps/nowinandroid/interests/InterestsScreenTest.kt b/feature/interests/src/androidTest/java/com/google/samples/apps/nowinandroid/interests/InterestsScreenTest.kt index 4b067734fa..8b4b8600f1 100644 --- a/feature/interests/src/androidTest/java/com/google/samples/apps/nowinandroid/interests/InterestsScreenTest.kt +++ b/feature/interests/src/androidTest/java/com/google/samples/apps/nowinandroid/interests/InterestsScreenTest.kt @@ -27,12 +27,14 @@ import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText import com.google.samples.apps.nowinandroid.core.domain.model.FollowableAuthor import com.google.samples.apps.nowinandroid.core.domain.model.FollowableTopic -import com.google.samples.apps.nowinandroid.core.model.data.Author -import com.google.samples.apps.nowinandroid.core.model.data.Topic +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeAuthor +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeTopic import com.google.samples.apps.nowinandroid.feature.interests.InterestsScreen import com.google.samples.apps.nowinandroid.feature.interests.InterestsTabState import com.google.samples.apps.nowinandroid.feature.interests.InterestsUiState import com.google.samples.apps.nowinandroid.feature.interests.R +import com.google.samples.apps.nowinandroid.feature.interests.R.string +import kotlin.random.Random import org.junit.Before import org.junit.Rule import org.junit.Test @@ -96,13 +98,13 @@ class InterestsScreenTest { } composeTestRule - .onNodeWithText(TOPIC_1_NAME) + .onNodeWithText(testTopics[0].topic.name) .assertIsDisplayed() composeTestRule - .onNodeWithText(TOPIC_2_NAME) + .onNodeWithText(testTopics[1].topic.name) .assertIsDisplayed() composeTestRule - .onNodeWithText(TOPIC_3_NAME) + .onNodeWithText(testTopics[2].topic.name) .assertIsDisplayed() composeTestRule @@ -173,7 +175,7 @@ class InterestsScreenTest { InterestsScreen( uiState = uiState, tabState = InterestsTabState( - titles = listOf(R.string.interests_topics, R.string.interests_people), + titles = listOf(string.interests_topics, string.interests_people), currentIndex = tabIndex ), followAuthor = { _, _ -> }, @@ -184,85 +186,26 @@ class InterestsScreenTest { ) } } - -private const val TOPIC_1_NAME = "Headlines" -private const val TOPIC_2_NAME = "UI" -private const val TOPIC_3_NAME = "Tools" private const val TOPIC_SHORT_DESC = "At vero eos et accusamus." -private const val TOPIC_LONG_DESC = "At vero eos et accusamus et iusto odio dignissimos ducimus." -private const val TOPIC_URL = "URL" -private const val TOPIC_IMAGE_URL = "Image URL" - private val testTopics = listOf( FollowableTopic( - Topic( - id = "0", - name = TOPIC_1_NAME, - shortDescription = TOPIC_SHORT_DESC, - longDescription = TOPIC_LONG_DESC, - url = TOPIC_URL, - imageUrl = TOPIC_IMAGE_URL, - ), + Random.nextFakeTopic(id = "1", shortDescription = TOPIC_SHORT_DESC), isFollowed = true ), FollowableTopic( - Topic( - id = "1", - name = TOPIC_2_NAME, - shortDescription = TOPIC_SHORT_DESC, - longDescription = TOPIC_LONG_DESC, - url = TOPIC_URL, - imageUrl = TOPIC_IMAGE_URL, - ), + Random.nextFakeTopic(id = "2", shortDescription = TOPIC_SHORT_DESC), isFollowed = false ), FollowableTopic( - Topic( - id = "2", - name = TOPIC_3_NAME, - shortDescription = TOPIC_SHORT_DESC, - longDescription = TOPIC_LONG_DESC, - url = TOPIC_URL, - imageUrl = TOPIC_IMAGE_URL, - ), + Random.nextFakeTopic(id = "3", shortDescription = TOPIC_SHORT_DESC), isFollowed = false ) ) private val testAuthors = listOf( - FollowableAuthor( - Author( - id = "0", - name = "Android Dev", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = true - ), - FollowableAuthor( - Author( - id = "1", - name = "Android Dev 2", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ), - FollowableAuthor( - Author( - id = "2", - name = "Android Dev 3", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ) + FollowableAuthor(Random.nextFakeAuthor(id = "1"), isFollowed = true), + FollowableAuthor(Random.nextFakeAuthor(id = "2"), isFollowed = false), + FollowableAuthor(Random.nextFakeAuthor(id = "3"), isFollowed = false) ) private val numberOfUnfollowedTopics = testTopics.filter { !it.isFollowed }.size diff --git a/feature/interests/src/test/java/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt b/feature/interests/src/test/java/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt index aaac504d38..adb5699792 100644 --- a/feature/interests/src/test/java/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt +++ b/feature/interests/src/test/java/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt @@ -20,14 +20,15 @@ import com.google.samples.apps.nowinandroid.core.domain.GetFollowableTopicsStrea import com.google.samples.apps.nowinandroid.core.domain.GetSortedFollowableAuthorsStreamUseCase import com.google.samples.apps.nowinandroid.core.domain.model.FollowableAuthor import com.google.samples.apps.nowinandroid.core.domain.model.FollowableTopic -import com.google.samples.apps.nowinandroid.core.model.data.Author -import com.google.samples.apps.nowinandroid.core.model.data.Topic +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeAuthor +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeTopic import com.google.samples.apps.nowinandroid.core.testing.repository.TestAuthorsRepository import com.google.samples.apps.nowinandroid.core.testing.repository.TestTopicsRepository import com.google.samples.apps.nowinandroid.core.testing.repository.TestUserDataRepository import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule import com.google.samples.apps.nowinandroid.feature.interests.InterestsUiState import com.google.samples.apps.nowinandroid.feature.interests.InterestsViewModel +import kotlin.random.Random import kotlin.test.assertEquals import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch @@ -204,154 +205,26 @@ class InterestsViewModelTest { } } -private const val TOPIC_1_NAME = "Android Studio" -private const val TOPIC_2_NAME = "Build" -private const val TOPIC_3_NAME = "Compose" -private const val TOPIC_SHORT_DESC = "At vero eos et accusamus." -private const val TOPIC_LONG_DESC = "At vero eos et accusamus et iusto odio dignissimos ducimus." -private const val TOPIC_URL = "URL" -private const val TOPIC_IMAGE_URL = "Image URL" - private val testInputAuthors = listOf( - FollowableAuthor( - Author( - id = "0", - name = "Android Dev", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = true - ), - FollowableAuthor( - Author( - id = "1", - name = "Android Dev 2", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ), - FollowableAuthor( - Author( - id = "2", - name = "Android Dev 3", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ) + FollowableAuthor(author = Random.nextFakeAuthor(id = "1"), isFollowed = true), + FollowableAuthor(author = Random.nextFakeAuthor(id = "2"), isFollowed = false), + FollowableAuthor(author = Random.nextFakeAuthor(id = "3"), isFollowed = false), ) private val testOutputAuthors = listOf( - FollowableAuthor( - Author( - id = "0", - name = "Android Dev", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = true - ), - FollowableAuthor( - Author( - id = "1", - name = "Android Dev 2", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = true - ), - FollowableAuthor( - Author( - id = "2", - name = "Android Dev 3", - imageUrl = "", - twitter = "", - mediumPage = "", - bio = "", - ), - isFollowed = false - ) + FollowableAuthor(author = Random.nextFakeAuthor(id = "1"), isFollowed = true), + FollowableAuthor(author = Random.nextFakeAuthor(id = "2"), isFollowed = true), + FollowableAuthor(author = Random.nextFakeAuthor(id = "3"), isFollowed = false), ) private val testInputTopics = listOf( - FollowableTopic( - Topic( - id = "0", - name = TOPIC_1_NAME, - shortDescription = TOPIC_SHORT_DESC, - longDescription = TOPIC_LONG_DESC, - url = TOPIC_URL, - imageUrl = TOPIC_IMAGE_URL, - ), - isFollowed = true - ), - FollowableTopic( - Topic( - id = "1", - name = TOPIC_2_NAME, - shortDescription = TOPIC_SHORT_DESC, - longDescription = TOPIC_LONG_DESC, - url = TOPIC_URL, - imageUrl = TOPIC_IMAGE_URL, - ), - isFollowed = false - ), - FollowableTopic( - Topic( - id = "2", - name = TOPIC_3_NAME, - shortDescription = TOPIC_SHORT_DESC, - longDescription = TOPIC_LONG_DESC, - url = TOPIC_URL, - imageUrl = TOPIC_IMAGE_URL, - ), - isFollowed = false - ) + FollowableTopic(Random.nextFakeTopic(id = "1"), isFollowed = true), + FollowableTopic(Random.nextFakeTopic(id = "2"), isFollowed = false), + FollowableTopic(Random.nextFakeTopic(id = "3"), isFollowed = false), ) private val testOutputTopics = listOf( - FollowableTopic( - Topic( - id = "0", - name = TOPIC_1_NAME, - shortDescription = TOPIC_SHORT_DESC, - longDescription = TOPIC_LONG_DESC, - url = TOPIC_URL, - imageUrl = TOPIC_IMAGE_URL, - ), - isFollowed = true - ), - FollowableTopic( - Topic( - id = "1", - name = TOPIC_2_NAME, - shortDescription = TOPIC_SHORT_DESC, - longDescription = TOPIC_LONG_DESC, - url = TOPIC_URL, - imageUrl = TOPIC_IMAGE_URL, - ), - isFollowed = true - ), - FollowableTopic( - Topic( - id = "2", - name = TOPIC_3_NAME, - shortDescription = TOPIC_SHORT_DESC, - longDescription = TOPIC_LONG_DESC, - url = TOPIC_URL, - imageUrl = TOPIC_IMAGE_URL, - ), - isFollowed = false - ) + FollowableTopic(Random.nextFakeTopic(id = "1"), isFollowed = true), + FollowableTopic(Random.nextFakeTopic(id = "2"), isFollowed = true), + FollowableTopic(Random.nextFakeTopic(id = "3"), isFollowed = false), ) diff --git a/feature/topic/build.gradle.kts b/feature/topic/build.gradle.kts index 70c730dbd1..260763745b 100644 --- a/feature/topic/build.gradle.kts +++ b/feature/topic/build.gradle.kts @@ -25,4 +25,6 @@ android { dependencies { implementation(libs.kotlinx.datetime) + androidTestImplementation(testFixtures(project(":core:model"))) + testImplementation(testFixtures(project(":core:model"))) } \ No newline at end of file diff --git a/feature/topic/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreenTest.kt b/feature/topic/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreenTest.kt index 0f20a5e5e1..3786a74dbf 100644 --- a/feature/topic/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreenTest.kt +++ b/feature/topic/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreenTest.kt @@ -26,10 +26,9 @@ import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performScrollToNode import com.google.samples.apps.nowinandroid.core.domain.model.FollowableTopic import com.google.samples.apps.nowinandroid.core.domain.model.SaveableNewsResource -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 kotlinx.datetime.Instant +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeNewsResource +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeTopic +import kotlin.random.Random import org.junit.Before import org.junit.Rule import org.junit.Test @@ -147,69 +146,10 @@ class TopicScreenTest { } } -private const val TOPIC_1_NAME = "Headlines" -private const val TOPIC_2_NAME = "UI" -private const val TOPIC_3_NAME = "Tools" -private const val TOPIC_DESC = "At vero eos et accusamus et iusto odio dignissimos ducimus qui." - private val testTopics = listOf( - FollowableTopic( - Topic( - id = "0", - name = TOPIC_1_NAME, - shortDescription = "", - longDescription = TOPIC_DESC, - url = "", - imageUrl = "" - ), - isFollowed = true - ), - FollowableTopic( - Topic( - id = "1", - name = TOPIC_2_NAME, - shortDescription = "", - longDescription = TOPIC_DESC, - url = "", - imageUrl = "" - ), - isFollowed = false - ), - FollowableTopic( - Topic( - id = "2", - name = TOPIC_3_NAME, - shortDescription = "", - longDescription = TOPIC_DESC, - url = "", - imageUrl = "" - ), - isFollowed = false - ) + FollowableTopic(Random.nextFakeTopic(id = "1", name = "Headlines"), isFollowed = true), + FollowableTopic(Random.nextFakeTopic(id = "2", name = "UI"), isFollowed = false), + FollowableTopic(Random.nextFakeTopic(id = "3", name = "Tools"), isFollowed = false), ) -private val sampleNewsResources = listOf( - NewsResource( - id = "1", - title = "Thanks for helping us reach 1M YouTube Subscribers", - content = "Thank you everyone for following the Now in Android series and everything the " + - "Android Developers YouTube channel has to offer. During the Android Developer " + - "Summit, our YouTube channel reached 1 million subscribers! Here’s a small video to " + - "thank you all.", - url = "https://youtu.be/-fJ6poHQrjM", - headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", - publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, - topics = listOf( - Topic( - id = "0", - name = "Headlines", - shortDescription = "", - longDescription = TOPIC_DESC, - url = "", - imageUrl = "" - ) - ), - authors = emptyList() - ) -) +private val sampleNewsResources = listOf(Random.nextFakeNewsResource()) diff --git a/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt b/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt index 17d7b45ee5..abc04c1f60 100644 --- a/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt +++ b/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt @@ -19,15 +19,15 @@ package com.google.samples.apps.nowinandroid.feature.topic import androidx.lifecycle.SavedStateHandle import com.google.samples.apps.nowinandroid.core.domain.GetSaveableNewsResourcesStreamUseCase import com.google.samples.apps.nowinandroid.core.domain.model.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.core.model.data.nextFakeNewsResource +import com.google.samples.apps.nowinandroid.core.model.data.nextFakeTopic import com.google.samples.apps.nowinandroid.core.testing.decoder.FakeStringDecoder 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.TestUserDataRepository import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule import com.google.samples.apps.nowinandroid.feature.topic.navigation.topicIdArg +import kotlin.random.Random import kotlin.test.assertEquals import kotlin.test.assertIs import kotlinx.coroutines.flow.collect @@ -36,7 +36,6 @@ import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.runTest -import kotlinx.datetime.Instant import org.junit.Before import org.junit.Rule import org.junit.Test @@ -136,7 +135,7 @@ class TopicViewModelTest { } topicsRepository.sendTopics(testInputTopics.map { it.topic }) userDataRepository.setFollowedTopicIds(setOf(testInputTopics[1].topic.id)) - newsRepository.sendNewsResources(sampleNewsResources) + newsRepository.sendNewsResources(listOf(Random.nextFakeNewsResource())) val topicUiState = viewModel.topicUiState.value val newsUiState = viewModel.newUiState.value @@ -165,108 +164,14 @@ class TopicViewModelTest { } } -private const val TOPIC_1_NAME = "Android Studio" -private const val TOPIC_2_NAME = "Build" -private const val TOPIC_3_NAME = "Compose" -private const val TOPIC_SHORT_DESC = "At vero eos et accusamus." -private const val TOPIC_LONG_DESC = "At vero eos et accusamus et iusto odio dignissimos ducimus." -private const val TOPIC_URL = "URL" -private const val TOPIC_IMAGE_URL = "Image URL" - private val testInputTopics = listOf( - FollowableTopic( - Topic( - id = "0", - name = TOPIC_1_NAME, - shortDescription = TOPIC_SHORT_DESC, - longDescription = TOPIC_LONG_DESC, - url = TOPIC_URL, - imageUrl = TOPIC_IMAGE_URL, - ), - isFollowed = true - ), - FollowableTopic( - Topic( - id = "1", - name = TOPIC_2_NAME, - shortDescription = TOPIC_SHORT_DESC, - longDescription = TOPIC_LONG_DESC, - url = TOPIC_URL, - imageUrl = TOPIC_IMAGE_URL, - ), - isFollowed = false - ), - FollowableTopic( - Topic( - id = "2", - name = TOPIC_3_NAME, - shortDescription = TOPIC_SHORT_DESC, - longDescription = TOPIC_LONG_DESC, - url = TOPIC_URL, - imageUrl = TOPIC_IMAGE_URL, - ), - isFollowed = false - ) + FollowableTopic(Random.nextFakeTopic(id = "1", name = "Android Studio"), isFollowed = true), + FollowableTopic(Random.nextFakeTopic(id = "2", name = "Build"), isFollowed = false), + FollowableTopic(Random.nextFakeTopic(id = "3", name = "Compose"), isFollowed = false), ) private val testOutputTopics = listOf( - FollowableTopic( - Topic( - id = "0", - name = TOPIC_1_NAME, - shortDescription = TOPIC_SHORT_DESC, - longDescription = TOPIC_LONG_DESC, - url = TOPIC_URL, - imageUrl = TOPIC_IMAGE_URL, - ), - isFollowed = true - ), - FollowableTopic( - Topic( - id = "1", - name = TOPIC_2_NAME, - shortDescription = TOPIC_SHORT_DESC, - longDescription = TOPIC_LONG_DESC, - url = TOPIC_URL, - imageUrl = TOPIC_IMAGE_URL, - ), - isFollowed = true - ), - FollowableTopic( - Topic( - id = "2", - name = TOPIC_3_NAME, - shortDescription = TOPIC_SHORT_DESC, - longDescription = TOPIC_LONG_DESC, - url = TOPIC_URL, - imageUrl = TOPIC_IMAGE_URL, - ), - isFollowed = false - ) -) - -private val sampleNewsResources = listOf( - NewsResource( - id = "1", - title = "Thanks for helping us reach 1M YouTube Subscribers", - content = "Thank you everyone for following the Now in Android series and everything the " + - "Android Developers YouTube channel has to offer. During the Android Developer " + - "Summit, our YouTube channel reached 1 million subscribers! Here’s a small video to " + - "thank you all.", - url = "https://youtu.be/-fJ6poHQrjM", - headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", - publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, - topics = listOf( - Topic( - id = "0", - name = "Headlines", - shortDescription = "", - longDescription = "long description", - url = "URL", - imageUrl = "image URL", - ) - ), - authors = emptyList() - ) + testInputTopics[0], + testInputTopics[1].copy(isFollowed = true), + testInputTopics[2], )