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