Merge pull request #476 from android/caren/resource_type
Display resource type for each news resourcepull/489/head
commit
65fdb0c09c
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* 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.ui
|
||||||
|
|
||||||
|
import androidx.activity.ComponentActivity
|
||||||
|
import androidx.compose.ui.test.assertIsDisplayed
|
||||||
|
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
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class NewsResourceCardTest {
|
||||||
|
@get:Rule
|
||||||
|
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testMetaDataDisplay_withCodelabResource() {
|
||||||
|
val newsWithKnownResourceType = previewNewsResources[0]
|
||||||
|
var dateFormatted = ""
|
||||||
|
|
||||||
|
composeTestRule.setContent {
|
||||||
|
NewsResourceCardExpanded(
|
||||||
|
newsResource = newsWithKnownResourceType,
|
||||||
|
isBookmarked = false,
|
||||||
|
onToggleBookmark = {},
|
||||||
|
onClick = {}
|
||||||
|
)
|
||||||
|
|
||||||
|
dateFormatted = dateFormatted(publishDate = newsWithKnownResourceType.publishDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
composeTestRule
|
||||||
|
.onNodeWithText(
|
||||||
|
composeTestRule.activity.getString(
|
||||||
|
R.string.card_meta_data_text,
|
||||||
|
dateFormatted,
|
||||||
|
newsWithKnownResourceType.type.displayText
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.assertExists()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testMetaDataDisplay_withUnknownResource() {
|
||||||
|
val newsWithUnknownResourceType = previewNewsResources[3]
|
||||||
|
var dateFormatted = ""
|
||||||
|
|
||||||
|
composeTestRule.setContent {
|
||||||
|
NewsResourceCardExpanded(
|
||||||
|
newsResource = newsWithUnknownResourceType,
|
||||||
|
isBookmarked = false,
|
||||||
|
onToggleBookmark = {},
|
||||||
|
onClick = {}
|
||||||
|
)
|
||||||
|
|
||||||
|
dateFormatted = dateFormatted(publishDate = newsWithUnknownResourceType.publishDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
composeTestRule
|
||||||
|
.onNodeWithText(dateFormatted)
|
||||||
|
.assertIsDisplayed()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue