Skip to content

Commit

Permalink
Merge pull request #962 from mannodermaus/fix/date-display-for-search…
Browse files Browse the repository at this point in the history
…-result-items

Align TimetableItemTag content for SearchScreen with Figma
  • Loading branch information
takahirom authored Sep 7, 2024
2 parents 2e7e983 + 8e31be0 commit f97f1ae
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInRoot
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.semantics.SemanticsPropertyKey
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
Expand All @@ -69,6 +72,11 @@ const val TimetableItemCardBookmarkedIconTestTag = "TimetableItemCardBookmarkedI
const val TimetableItemCardTestTag = "TimetableListItem"
const val TimetableItemCardTitleTextTestTag = "TimetableItemCardTitleText"

private val timetableItemCardSemanticsKey = SemanticsPropertyKey<TimetableItem>("TimetableItem")

@Suppress("UnusedReceiverParameter")
val SemanticsProperties.TimetableItemCard get() = timetableItemCardSemanticsKey

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun TimetableItemCard(
Expand Down Expand Up @@ -99,6 +107,9 @@ fun TimetableItemCard(
Row(
modifier = modifier
.testTag(TimetableItemCardTestTag)
.semantics {
this[SemanticsProperties.TimetableItemCard] = timetableItem
}
.border(
border = BorderStroke(
width = 1.dp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import android.content.Context
import android.hardware.Sensor
import android.hardware.SensorEvent
import android.hardware.SensorManager
import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.onFirst
import androidx.test.core.app.ApplicationProvider.getApplicationContext
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers
import com.github.takahirom.roborazzi.provideRoborazziContext
Expand All @@ -22,6 +25,8 @@ import io.github.droidkaigi.confsched.data.sponsors.FakeSponsorsApiClient
import io.github.droidkaigi.confsched.data.sponsors.SponsorsApiClient
import io.github.droidkaigi.confsched.data.staff.FakeStaffApiClient
import io.github.droidkaigi.confsched.data.staff.StaffApiClient
import io.github.droidkaigi.confsched.droidkaigiui.component.TimetableItemCard
import io.github.droidkaigi.confsched.droidkaigiui.component.TimetableItemCardTestTag
import io.github.droidkaigi.confsched.model.FontFamily
import io.github.droidkaigi.confsched.model.ProfileCard
import io.github.droidkaigi.confsched.model.Settings
Expand All @@ -34,12 +39,14 @@ import io.github.droidkaigi.confsched.testing.robot.SettingsDataStoreRobot.Setti
import io.github.droidkaigi.confsched.testing.robot.SettingsDataStoreRobot.SettingsStatus.UseDotGothic16FontFamily
import io.github.droidkaigi.confsched.testing.robot.SettingsDataStoreRobot.SettingsStatus.UseSystemDefaultFont
import io.github.droidkaigi.confsched.testing.robot.SponsorsServerRobot.ServerStatus
import io.github.droidkaigi.confsched.testing.robot.TimetableItemCardRobot.Language
import io.github.droidkaigi.confsched.testing.robot.TimetableServerRobot.ServerStatus.Error
import io.github.droidkaigi.confsched.testing.robot.TimetableServerRobot.ServerStatus.Operational
import io.github.droidkaigi.confsched.testing.robot.TimetableServerRobot.ServerStatus.OperationalBothAssetAvailable
import io.github.droidkaigi.confsched.testing.robot.TimetableServerRobot.ServerStatus.OperationalOnlySlideAssetAvailable
import io.github.droidkaigi.confsched.testing.robot.TimetableServerRobot.ServerStatus.OperationalOnlyVideoAssetAvailable
import io.github.droidkaigi.confsched.testing.rules.RobotTestRule
import io.github.droidkaigi.confsched.testing.utils.assertSemanticsProperty
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.test.TestDispatcher
import org.robolectric.RuntimeEnvironment
Expand Down Expand Up @@ -502,3 +509,39 @@ class DefaultSettingsDataStoreRobot @Inject constructor(

override fun get(): Flow<Settings> = settingsDataStore.get()
}

interface TimetableItemCardRobot {
enum class Language(
val tagName: String,
) {
MIXED("MIXED"),
JAPANESE("JA"),
ENGLISH("EN"),
}

fun checkTimetableListItemByLanguage(language: Language)
}

class DefaultTimetableItemCardRobot @Inject constructor(
private val robotTestRule: RobotTestRule,
) : TimetableItemCardRobot {
override fun checkTimetableListItemByLanguage(language: Language) {
val doesNotContains = Language.entries.filterNot { it == language }

robotTestRule.composeTestRule
.onAllNodes(hasTestTag(TimetableItemCardTestTag))
.onFirst()
.assertSemanticsProperty(SemanticsProperties.TimetableItemCard) { item ->
item?.language?.toLang()?.tagName == language.tagName
}

doesNotContains.forEach { doesNotContain ->
robotTestRule.composeTestRule
.onAllNodes(hasTestTag(TimetableItemCardTestTag))
.onFirst()
.assertSemanticsProperty(SemanticsProperties.TimetableItemCard) { item ->
item?.language?.toLang()?.tagName != doesNotContain.tagName
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import io.github.droidkaigi.confsched.sessions.component.SearchFiltersFilterLang
import io.github.droidkaigi.confsched.sessions.component.SearchFiltersLazyRowTestTag
import io.github.droidkaigi.confsched.sessions.component.SearchTextFieldAppBarTextFieldTestTag
import io.github.droidkaigi.confsched.sessions.section.TimetableListTestTag
import io.github.droidkaigi.confsched.testing.robot.TimetableItemCardRobot.Language
import io.github.droidkaigi.confsched.testing.utils.assertCountAtLeast
import io.github.droidkaigi.confsched.testing.utils.assertTextDoesNotContain
import io.github.droidkaigi.confsched.testing.utils.hasTestTag
Expand All @@ -36,9 +37,11 @@ class SearchScreenRobot @Inject constructor(
private val screenRobot: DefaultScreenRobot,
private val timetableServerRobot: DefaultTimetableServerRobot,
private val deviceSetupRobot: DefaultDeviceSetupRobot,
timetableItemRobot: DefaultTimetableItemCardRobot,
) : ScreenRobot by screenRobot,
TimetableServerRobot by timetableServerRobot,
DeviceSetupRobot by deviceSetupRobot {
DeviceSetupRobot by deviceSetupRobot,
TimetableItemCardRobot by timetableItemRobot {
enum class ConferenceDay(
val day: Int,
val dateText: String,
Expand All @@ -55,14 +58,6 @@ class SearchScreenRobot @Inject constructor(
Other("Other en"),
}

enum class Language(
val tagName: String,
) {
MIXED("MIXED"),
JAPANESE("JA"),
ENGLISH("EN"),
}

fun setupSearchScreenContent() {
robotTestRule.setContent {
KaigiTheme {
Expand Down Expand Up @@ -231,25 +226,6 @@ class SearchScreenRobot @Inject constructor(
waitUntilIdle()
}

fun checkTimetableListItemByLanguage(
language: Language,
) {
val doesNotContains = Language.entries.filterNot { it == language }

composeTestRule
.onAllNodes(hasTestTag(TimetableItemCardTestTag))
.onFirst()
.assertTextContains(language.tagName)

doesNotContains.forEach { doesNotContain ->
composeTestRule
.onAllNodes(hasTestTag(TimetableItemCardTestTag))
.onFirst()
.assertTextDoesNotContain(doesNotContain.tagName)
}
waitUntilIdle()
}

fun checkDemoSearchWordDisplayed() {
checkSearchWordDisplayed(DemoSearchWord)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.droidkaigi.confsched.testing.utils
import androidx.compose.ui.semantics.SemanticsActions
import androidx.compose.ui.semantics.SemanticsNode
import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.semantics.SemanticsPropertyKey
import androidx.compose.ui.semantics.getOrNull
import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.SemanticsNodeInteraction
Expand Down Expand Up @@ -85,6 +86,23 @@ fun SemanticsNodeInteraction.assertLineCount(expectedCount: Int) {
}
}

fun <T> SemanticsNodeInteraction.assertSemanticsProperty(
key: SemanticsPropertyKey<T>,
condition: (T?) -> Boolean,
) {
fetchSemanticsNode()
.let { node ->
val actual = node
.config
.getOrNull(key)

assertTrue(
"Node has unexpected value for semantics property $key: $actual",
condition(actual),
)
}
}

private fun buildErrorMessageForMinimumCountMismatch(
errorMessage: String,
foundNodes: List<SemanticsNode>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import io.github.droidkaigi.confsched.testing.execute
import io.github.droidkaigi.confsched.testing.robot.SearchScreenRobot
import io.github.droidkaigi.confsched.testing.robot.SearchScreenRobot.Category
import io.github.droidkaigi.confsched.testing.robot.SearchScreenRobot.ConferenceDay
import io.github.droidkaigi.confsched.testing.robot.SearchScreenRobot.Language
import io.github.droidkaigi.confsched.testing.robot.TimetableItemCardRobot.Language
import io.github.droidkaigi.confsched.testing.robot.TimetableServerRobot.ServerStatus
import io.github.droidkaigi.confsched.testing.robot.runRobot
import io.github.droidkaigi.confsched.testing.rules.RobotTestRule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package io.github.droidkaigi.confsched.sessions.section

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import io.github.droidkaigi.confsched.droidkaigiui.component.TimetableItemTag
import io.github.droidkaigi.confsched.model.TimetableItem

@Composable
Expand All @@ -23,5 +25,13 @@ fun SearchList(
contentPadding = contentPadding,
highlightWord = highlightWord,
modifier = modifier,
timetableItemTagsContent = { timetableItem ->
timetableItem.day?.monthAndDay()?.let { monthAndDay ->
TimetableItemTag(
tagText = monthAndDay,
tagColor = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
Expand All @@ -17,7 +18,6 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
Expand Down Expand Up @@ -71,6 +71,7 @@ internal fun TimetableList(
onBookmarkClick: (TimetableItem, Boolean) -> Unit,
onTimetableItemClick: (TimetableItem) -> Unit,
contentPadding: PaddingValues,
timetableItemTagsContent: @Composable RowScope.(TimetableItem) -> Unit,
modifier: Modifier = Modifier,
nestedScrollStateHolder: TimetableNestedScrollStateHolder = rememberTimetableNestedScrollStateHolder(true),
highlightWord: String = "",
Expand Down Expand Up @@ -181,12 +182,7 @@ internal fun TimetableList(
tagColor = LocalRoomTheme.current.primaryColor,
modifier = Modifier.background(LocalRoomTheme.current.containerColor),
)
timetableItem.language.labels.forEach { label ->
TimetableItemTag(
tagText = label,
tagColor = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
timetableItemTagsContent(timetableItem)
},
onTimetableItemClick = onTimetableItemClick,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand All @@ -24,6 +25,7 @@ import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import io.github.droidkaigi.confsched.droidkaigiui.component.TimetableItemTag
import io.github.droidkaigi.confsched.droidkaigiui.compositionlocal.LocalClock
import io.github.droidkaigi.confsched.model.DroidKaigi2024Day
import io.github.droidkaigi.confsched.model.TimeLine
Expand Down Expand Up @@ -108,6 +110,14 @@ fun Timetable(
start = contentPadding.calculateStartPadding(layoutDirection),
end = contentPadding.calculateEndPadding(layoutDirection),
),
timetableItemTagsContent = { timetableItem ->
timetableItem.language.labels.forEach { label ->
TimetableItemTag(
tagText = label,
tagColor = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
},
)
}

Expand Down

0 comments on commit f97f1ae

Please sign in to comment.