From f4c2a2b1389f723acf4adb7898ac8b8bf6e4ac2e Mon Sep 17 00:00:00 2001 From: magicalmeghan Date: Thu, 22 Dec 2022 13:58:51 -0800 Subject: [PATCH] Added third draft of tests --- .../domain/GetUserNewsResourcesUseCaseTest.kt | 77 ++----------------- .../core/ui/NewsResourceCardTest.kt | 1 + 2 files changed, 7 insertions(+), 71 deletions(-) diff --git a/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetUserNewsResourcesUseCaseTest.kt b/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetUserNewsResourcesUseCaseTest.kt index 66a001184..d8fd950de 100644 --- a/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetUserNewsResourcesUseCaseTest.kt +++ b/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetUserNewsResourcesUseCaseTest.kt @@ -53,6 +53,9 @@ class GetUserNewsResourcesUseCaseTest { setOf(sampleNewsResources[0].id, sampleNewsResources[2].id) ) + // Set a followed topic for the user. + userDataRepository.setFollowedTopicIds(setOf(sampleTopic1.id)) + // Check that the correct news resources are returned with their bookmarked state. assertEquals( listOf( @@ -67,7 +70,7 @@ class GetUserNewsResourcesUseCaseTest { sampleNewsResources[0].topics.map { topic -> FollowableTopic( topic = topic, - isFollowed = false + isFollowed = topic.id == sampleTopic1.id ) }, true @@ -83,7 +86,7 @@ class GetUserNewsResourcesUseCaseTest { sampleNewsResources[1].topics.map { topic -> FollowableTopic( topic = topic, - isFollowed = false + isFollowed = topic.id == sampleTopic1.id ) }, false @@ -99,7 +102,7 @@ class GetUserNewsResourcesUseCaseTest { sampleNewsResources[2].topics.map { topic -> FollowableTopic( topic = topic, - isFollowed = false + isFollowed = topic.id == sampleTopic1.id ) }, true @@ -144,74 +147,6 @@ class GetUserNewsResourcesUseCaseTest { saveableNewsResources.first() ) } - - @Test - fun checkNewsResourcesContainCorrectFollowedTopics() = runTest { - - // Obtain the saveable news resources stream. - val saveableNewsResources = useCase() - - // Send some news resources. - newsRepository.sendNewsResources(sampleNewsResources) - - // Set a followed topic for the user. - userDataRepository.setFollowedTopicIds(setOf(sampleTopic1.id)) - - // Check that the followed topic is marked followed in the UserNewsResources - assertEquals( - listOf( - UserNewsResource( - sampleNewsResources[0].id, - sampleNewsResources[0].title, - sampleNewsResources[0].content, - sampleNewsResources[0].url, - sampleNewsResources[0].headerImageUrl, - sampleNewsResources[0].publishDate, - sampleNewsResources[0].type, - sampleNewsResources[0].topics.map { topic -> - FollowableTopic( - topic = topic, - isFollowed = topic.id == sampleTopic1.id - ) - }, - false - ), - UserNewsResource( - sampleNewsResources[1].id, - sampleNewsResources[1].title, - sampleNewsResources[1].content, - sampleNewsResources[1].url, - sampleNewsResources[1].headerImageUrl, - sampleNewsResources[1].publishDate, - sampleNewsResources[1].type, - sampleNewsResources[1].topics.map { topic -> - FollowableTopic( - topic = topic, - isFollowed = topic.id == sampleTopic1.id - ) - }, - false - ), - UserNewsResource( - sampleNewsResources[2].id, - sampleNewsResources[2].title, - sampleNewsResources[2].content, - sampleNewsResources[2].url, - sampleNewsResources[2].headerImageUrl, - sampleNewsResources[2].publishDate, - sampleNewsResources[2].type, - sampleNewsResources[2].topics.map { topic -> - FollowableTopic( - topic = topic, - isFollowed = topic.id == sampleTopic1.id - ) - }, - false - ), - ), - saveableNewsResources.first() - ) - } } private val sampleTopic1 = Topic( diff --git a/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt b/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt index 3a8ce415d..a46626cab 100644 --- a/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt +++ b/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt @@ -89,4 +89,5 @@ class NewsResourceCardTest { .onNodeWithText(followableTopics[1].topic.name) .assertContentDescriptionEquals("UI is followed") } + //TODO add a test for not followed - figure out whether to put it here or to make a new test } \ No newline at end of file