From b05302fdddbffc55db095584542287a7882b2e6b Mon Sep 17 00:00:00 2001 From: Caren Date: Mon, 12 Dec 2022 13:29:09 -0800 Subject: [PATCH] Fix tests Change-Id: Ie1e2408ea523e6ddc0941fe261fce7f2502e3416 --- core/ui/build.gradle.kts | 1 - .../core/ui/NewsResourceCardTest.kt | 35 ++++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) rename core/ui/src/{test => androidTest}/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt (59%) diff --git a/core/ui/build.gradle.kts b/core/ui/build.gradle.kts index 7c39f1eda..6b37494e2 100644 --- a/core/ui/build.gradle.kts +++ b/core/ui/build.gradle.kts @@ -48,6 +48,5 @@ dependencies { api(libs.androidx.metrics) api(libs.androidx.tracing.ktx) - testImplementation(project(":core:testing")) androidTestImplementation(project(":core:testing")) } \ No newline at end of file diff --git a/core/ui/src/test/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 similarity index 59% rename from core/ui/src/test/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt rename to core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt index 20d93b41e..69f919a62 100644 --- a/core/ui/src/test/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 @@ -16,8 +16,9 @@ package com.google.samples.apps.nowinandroid.core.ui +import androidx.activity.ComponentActivity import androidx.compose.ui.test.assertIsDisplayed -import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onNodeWithText import com.google.samples.apps.nowinandroid.core.model.data.previewNewsResources import org.junit.Rule @@ -25,41 +26,49 @@ import org.junit.Test class NewsResourceCardTest { @get:Rule - val composeTestRule = createComposeRule() + val composeTestRule = createAndroidComposeRule() @Test - fun testMetaDataDisplay() { - // Resource with known resource type - val newsResource = previewNewsResources[0] + fun testMetaDataDisplay_withCodelabResource() { + val newsWithKnownResourceType = previewNewsResources[0] var dateFormatted = "" composeTestRule.setContent { NewsResourceCardExpanded( - newsResource = newsResource, + newsResource = newsWithKnownResourceType, isBookmarked = false, onToggleBookmark = {}, onClick = {} ) - dateFormatted = dateFormatted(publishDate = newsResource.publishDate) + dateFormatted = dateFormatted(publishDate = newsWithKnownResourceType.publishDate) } composeTestRule - .onNodeWithText(dateFormatted + " • " + newsResource.type.displayText) - .assertIsDisplayed() + .onNodeWithText( + composeTestRule.activity.getString( + R.string.card_meta_data_text, + dateFormatted, + newsWithKnownResourceType.type.displayText + ) + ) + .assertExists() + } - // Resource with Unknown resource type - val newsResource2 = previewNewsResources[4] + @Test + fun testMetaDataDisplay_withUnknownResource() { + val newsWithUnknownResourceType = previewNewsResources[3] + var dateFormatted = "" composeTestRule.setContent { NewsResourceCardExpanded( - newsResource = newsResource2, + newsResource = newsWithUnknownResourceType, isBookmarked = false, onToggleBookmark = {}, onClick = {} ) - dateFormatted = dateFormatted(publishDate = newsResource.publishDate) + dateFormatted = dateFormatted(publishDate = newsWithUnknownResourceType.publishDate) } composeTestRule