|
|
@ -16,8 +16,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
package com.google.samples.apps.nowinandroid.core.ui
|
|
|
|
package com.google.samples.apps.nowinandroid.core.ui
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.activity.ComponentActivity
|
|
|
|
import androidx.compose.ui.test.assertIsDisplayed
|
|
|
|
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 androidx.compose.ui.test.onNodeWithText
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.previewNewsResources
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.previewNewsResources
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Rule
|
|
|
@ -25,41 +26,49 @@ import org.junit.Test
|
|
|
|
|
|
|
|
|
|
|
|
class NewsResourceCardTest {
|
|
|
|
class NewsResourceCardTest {
|
|
|
|
@get:Rule
|
|
|
|
@get:Rule
|
|
|
|
val composeTestRule = createComposeRule()
|
|
|
|
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun testMetaDataDisplay() {
|
|
|
|
fun testMetaDataDisplay_withCodelabResource() {
|
|
|
|
// Resource with known resource type
|
|
|
|
val newsWithKnownResourceType = previewNewsResources[0]
|
|
|
|
val newsResource = previewNewsResources[0]
|
|
|
|
|
|
|
|
var dateFormatted = ""
|
|
|
|
var dateFormatted = ""
|
|
|
|
|
|
|
|
|
|
|
|
composeTestRule.setContent {
|
|
|
|
composeTestRule.setContent {
|
|
|
|
NewsResourceCardExpanded(
|
|
|
|
NewsResourceCardExpanded(
|
|
|
|
newsResource = newsResource,
|
|
|
|
newsResource = newsWithKnownResourceType,
|
|
|
|
isBookmarked = false,
|
|
|
|
isBookmarked = false,
|
|
|
|
onToggleBookmark = {},
|
|
|
|
onToggleBookmark = {},
|
|
|
|
onClick = {}
|
|
|
|
onClick = {}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
dateFormatted = dateFormatted(publishDate = newsResource.publishDate)
|
|
|
|
dateFormatted = dateFormatted(publishDate = newsWithKnownResourceType.publishDate)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
composeTestRule
|
|
|
|
composeTestRule
|
|
|
|
.onNodeWithText(dateFormatted + " • " + newsResource.type.displayText)
|
|
|
|
.onNodeWithText(
|
|
|
|
.assertIsDisplayed()
|
|
|
|
composeTestRule.activity.getString(
|
|
|
|
|
|
|
|
R.string.card_meta_data_text,
|
|
|
|
|
|
|
|
dateFormatted,
|
|
|
|
|
|
|
|
newsWithKnownResourceType.type.displayText
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.assertExists()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Resource with Unknown resource type
|
|
|
|
@Test
|
|
|
|
val newsResource2 = previewNewsResources[4]
|
|
|
|
fun testMetaDataDisplay_withUnknownResource() {
|
|
|
|
|
|
|
|
val newsWithUnknownResourceType = previewNewsResources[3]
|
|
|
|
|
|
|
|
var dateFormatted = ""
|
|
|
|
|
|
|
|
|
|
|
|
composeTestRule.setContent {
|
|
|
|
composeTestRule.setContent {
|
|
|
|
NewsResourceCardExpanded(
|
|
|
|
NewsResourceCardExpanded(
|
|
|
|
newsResource = newsResource2,
|
|
|
|
newsResource = newsWithUnknownResourceType,
|
|
|
|
isBookmarked = false,
|
|
|
|
isBookmarked = false,
|
|
|
|
onToggleBookmark = {},
|
|
|
|
onToggleBookmark = {},
|
|
|
|
onClick = {}
|
|
|
|
onClick = {}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
dateFormatted = dateFormatted(publishDate = newsResource.publishDate)
|
|
|
|
dateFormatted = dateFormatted(publishDate = newsWithUnknownResourceType.publishDate)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
composeTestRule
|
|
|
|
composeTestRule
|