Skip to content

Commit

Permalink
Search placeholder and QR icon updated (#3584)
Browse files Browse the repository at this point in the history
* Search placeholder and qr icon updated

* Unit Tests
  • Loading branch information
Aleem92 authored Nov 15, 2024
1 parent 4761232 commit 16d027d
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.smartregister.fhircore.engine.domain.model.RuleConfig
data class RegisterContentConfig(
val separator: String? = null,
val display: String? = null,
val placeholderColor: String? = null,
val rules: List<RuleConfig>? = null,
val visible: Boolean? = null,
val computedRules: List<String>? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.junit.Rule
import org.junit.Test
import org.smartregister.fhircore.quest.ui.main.components.LEADING_ICON_TEST_TAG
import org.smartregister.fhircore.quest.ui.main.components.OUTLINED_BOX_TEST_TAG
import org.smartregister.fhircore.quest.ui.main.components.SEARCH_FIELD_TEST_TAG
import org.smartregister.fhircore.quest.ui.main.components.TITLE_ROW_TEST_TAG
import org.smartregister.fhircore.quest.ui.main.components.TOP_ROW_ICON_TEST_TAG
import org.smartregister.fhircore.quest.ui.main.components.TOP_ROW_TEXT_TEST_TAG
Expand Down Expand Up @@ -106,6 +107,50 @@ class TopScreenSectionTest {
.assertIsDisplayed()
}

@Test
fun testTopScreenSectionRendersPlaceholderCorrectly() {
composeTestRule.setContent {
TopScreenSection(
title = "All Clients",
searchQuery = SearchQuery(""),
onSearchTextChanged = listener,
navController = TestNavHostController(LocalContext.current),
isSearchBarVisible = true,
placeholderColor = null,
searchPlaceholder = "Custom placeholder",
onClick = {},
decodeImage = null,
)
}

composeTestRule
.onNodeWithTag(SEARCH_FIELD_TEST_TAG, useUnmergedTree = true)
.assertExists()
.assertIsDisplayed()
}

@Test
fun testTopScreenSectionRendersPlaceholderColorCorrectly() {
composeTestRule.setContent {
TopScreenSection(
title = "All Clients",
searchQuery = SearchQuery(""),
onSearchTextChanged = listener,
navController = TestNavHostController(LocalContext.current),
isSearchBarVisible = true,
placeholderColor = "#FF0000",
searchPlaceholder = "Custom placeholder",
onClick = {},
decodeImage = null,
)
}

composeTestRule
.onNodeWithTag(SEARCH_FIELD_TEST_TAG, useUnmergedTree = true)
.assertExists()
.assertIsDisplayed()
}

@Test
fun testThatTrailingIconClickCallsTheListener() {
var clicked = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import org.smartregister.fhircore.engine.configuration.navigation.NavigationConf
import org.smartregister.fhircore.engine.configuration.navigation.NavigationMenuConfig
import org.smartregister.fhircore.engine.configuration.register.NoResultsConfig
import org.smartregister.fhircore.engine.configuration.register.RegisterConfiguration
import org.smartregister.fhircore.engine.configuration.register.RegisterContentConfig
import org.smartregister.fhircore.engine.configuration.workflow.ActionTrigger
import org.smartregister.fhircore.engine.domain.model.ActionConfig
import org.smartregister.fhircore.engine.domain.model.Language
Expand Down Expand Up @@ -162,6 +163,71 @@ class RegisterScreenTest {
composeTestRule.onAllNodesWithTag(FAB_BUTTON_REGISTER_TEST_TAG, useUnmergedTree = true)
}

@Test
fun testRegisterScreenWithPlaceholderColor() {
val configurationRegistry: ConfigurationRegistry = Faker.buildTestConfigurationRegistry()
val registerUiState =
RegisterUiState(
screenTitle = "Register101",
isFirstTimeSync = false,
registerConfiguration =
configurationRegistry
.retrieveConfiguration<RegisterConfiguration>(ConfigType.Register, "householdRegister")
.copy(
searchBar =
RegisterContentConfig(
visible = true,
display = "Search",
placeholderColor = "#FF0000",
),
),
registerId = "register101",
totalRecordsCount = 1,
filteredRecordsCount = 0,
pagesCount = 0,
progressPercentage = flowOf(0),
isSyncUpload = flowOf(false),
params = emptyList(),
)
val searchText = mutableStateOf(SearchQuery.emptyText)
val currentPage = mutableStateOf(0)

composeTestRule.setContent {
val data = listOf(ResourceData("1", ResourceType.Patient, emptyMap()))
val pagingItems = flowOf(PagingData.from(data)).collectAsLazyPagingItems()

RegisterScreen(
modifier = Modifier,
openDrawer = {},
onEvent = {},
registerUiState = registerUiState,
onAppMainEvent = {},
searchQuery = searchText,
currentPage = currentPage,
pagingItems = pagingItems,
navController = rememberNavController(),
decodeImage = null,
)
}

// Verify that all nodes with the TOP_REGISTER_SCREEN_TEST_TAG exist
composeTestRule
.onAllNodesWithTag(TOP_REGISTER_SCREEN_TEST_TAG, useUnmergedTree = true)
.assertCountEquals(7)

// Verify that the search text exists with correct placeholder
composeTestRule
.onNodeWithText("Search", useUnmergedTree = true)
.assertExists()
.assertIsDisplayed()

// Verify that the screen title is displayed
composeTestRule
.onNodeWithText("Register101", useUnmergedTree = true)
.assertExists()
.assertIsDisplayed()
}

@Test
fun testRegisterCardListIsRendered() {
val configurationRegistry: ConfigurationRegistry = Faker.buildTestConfigurationRegistry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ fun TopScreenSection(
showSearchByQrCode: Boolean = false,
filteredRecordsCount: Long? = null,
searchPlaceholder: String? = null,
placeholderColor: String? = null,
toolBarHomeNavigation: ToolBarHomeNavigation = ToolBarHomeNavigation.OPEN_DRAWER,
onSearchTextChanged: (SearchQuery, Boolean) -> Unit = { _, _ -> },
performSearchOnValueChanged: Boolean = true,
Expand Down Expand Up @@ -206,7 +207,7 @@ fun TopScreenSection(
singleLine = true,
placeholder = {
Text(
color = GreyTextColor,
color = placeholderColor?.parseColor() ?: GreyTextColor,
text = searchPlaceholder ?: stringResource(R.string.search_hint),
modifier = modifier.testTag(SEARCH_FIELD_TEST_TAG),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ fun RegisterScreen(
filteredRecordsCount = registerUiCountState.filteredRecordsCount,
isSearchBarVisible = registerUiState.registerConfiguration?.searchBar?.visible ?: true,
searchPlaceholder = registerUiState.registerConfiguration?.searchBar?.display,
placeholderColor = registerUiState.registerConfiguration?.searchBar?.placeholderColor,
showSearchByQrCode = registerUiState.registerConfiguration?.showSearchByQrCode ?: false,
toolBarHomeNavigation = toolBarHomeNavigation,
onSearchTextChanged = { uiSearchQuery, performSearchOnValueChanged ->
Expand Down
11 changes: 7 additions & 4 deletions android/quest/src/main/res/drawable/ic_qr_code.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
android:viewportWidth="20"
android:viewportHeight="20">
<path
android:pathData="M4.167,9.167C3.708,9.167 3.316,9.003 2.99,8.677C2.663,8.351 2.5,7.958 2.5,7.5V4.167C2.5,3.708 2.663,3.316 2.99,2.99C3.316,2.663 3.708,2.5 4.167,2.5H7.5C7.958,2.5 8.351,2.663 8.677,2.99C9.003,3.316 9.167,3.708 9.167,4.167V7.5C9.167,7.958 9.003,8.351 8.677,8.677C8.351,9.003 7.958,9.167 7.5,9.167H4.167ZM4.167,7.5H7.5V4.167H4.167V7.5ZM4.167,17.5C3.708,17.5 3.316,17.337 2.99,17.01C2.663,16.684 2.5,16.292 2.5,15.833V12.5C2.5,12.042 2.663,11.649 2.99,11.323C3.316,10.997 3.708,10.833 4.167,10.833H7.5C7.958,10.833 8.351,10.997 8.677,11.323C9.003,11.649 9.167,12.042 9.167,12.5V15.833C9.167,16.292 9.003,16.684 8.677,17.01C8.351,17.337 7.958,17.5 7.5,17.5H4.167ZM4.167,15.833H7.5V12.5H4.167V15.833ZM12.5,9.167C12.042,9.167 11.649,9.003 11.323,8.677C10.997,8.351 10.833,7.958 10.833,7.5V4.167C10.833,3.708 10.997,3.316 11.323,2.99C11.649,2.663 12.042,2.5 12.5,2.5H15.833C16.292,2.5 16.684,2.663 17.01,2.99C17.337,3.316 17.5,3.708 17.5,4.167V7.5C17.5,7.958 17.337,8.351 17.01,8.677C16.684,9.003 16.292,9.167 15.833,9.167H12.5ZM12.5,7.5H15.833V4.167H12.5V7.5ZM16.25,17.5C16.139,17.5 16.042,17.458 15.958,17.375C15.875,17.292 15.833,17.194 15.833,17.083V16.25C15.833,16.139 15.875,16.042 15.958,15.958C16.042,15.875 16.139,15.833 16.25,15.833H17.083C17.194,15.833 17.292,15.875 17.375,15.958C17.458,16.042 17.5,16.139 17.5,16.25V17.083C17.5,17.194 17.458,17.292 17.375,17.375C17.292,17.458 17.194,17.5 17.083,17.5H16.25ZM11.25,12.5C11.139,12.5 11.042,12.458 10.958,12.375C10.875,12.292 10.833,12.194 10.833,12.083V11.25C10.833,11.139 10.875,11.042 10.958,10.958C11.042,10.875 11.139,10.833 11.25,10.833H12.083C12.194,10.833 12.292,10.875 12.375,10.958C12.458,11.042 12.5,11.139 12.5,11.25V12.083C12.5,12.194 12.458,12.292 12.375,12.375C12.292,12.458 12.194,12.5 12.083,12.5H11.25ZM12.917,14.167C12.806,14.167 12.708,14.125 12.625,14.042C12.542,13.958 12.5,13.861 12.5,13.75V12.917C12.5,12.806 12.542,12.708 12.625,12.625C12.708,12.542 12.806,12.5 12.917,12.5H13.75C13.861,12.5 13.958,12.542 14.042,12.625C14.125,12.708 14.167,12.806 14.167,12.917V13.75C14.167,13.861 14.125,13.958 14.042,14.042C13.958,14.125 13.861,14.167 13.75,14.167H12.917ZM11.25,15.833C11.139,15.833 11.042,15.792 10.958,15.708C10.875,15.625 10.833,15.528 10.833,15.417V14.583C10.833,14.472 10.875,14.375 10.958,14.292C11.042,14.208 11.139,14.167 11.25,14.167H12.083C12.194,14.167 12.292,14.208 12.375,14.292C12.458,14.375 12.5,14.472 12.5,14.583V15.417C12.5,15.528 12.458,15.625 12.375,15.708C12.292,15.792 12.194,15.833 12.083,15.833H11.25ZM12.917,17.5C12.806,17.5 12.708,17.458 12.625,17.375C12.542,17.292 12.5,17.194 12.5,17.083V16.25C12.5,16.139 12.542,16.042 12.625,15.958C12.708,15.875 12.806,15.833 12.917,15.833H13.75C13.861,15.833 13.958,15.875 14.042,15.958C14.125,16.042 14.167,16.139 14.167,16.25V17.083C14.167,17.194 14.125,17.292 14.042,17.375C13.958,17.458 13.861,17.5 13.75,17.5H12.917ZM14.583,15.833C14.472,15.833 14.375,15.792 14.292,15.708C14.208,15.625 14.167,15.528 14.167,15.417V14.583C14.167,14.472 14.208,14.375 14.292,14.292C14.375,14.208 14.472,14.167 14.583,14.167H15.417C15.528,14.167 15.625,14.208 15.708,14.292C15.792,14.375 15.833,14.472 15.833,14.583V15.417C15.833,15.528 15.792,15.625 15.708,15.708C15.625,15.792 15.528,15.833 15.417,15.833H14.583ZM14.583,12.5C14.472,12.5 14.375,12.458 14.292,12.375C14.208,12.292 14.167,12.194 14.167,12.083V11.25C14.167,11.139 14.208,11.042 14.292,10.958C14.375,10.875 14.472,10.833 14.583,10.833H15.417C15.528,10.833 15.625,10.875 15.708,10.958C15.792,11.042 15.833,11.139 15.833,11.25V12.083C15.833,12.194 15.792,12.292 15.708,12.375C15.625,12.458 15.528,12.5 15.417,12.5H14.583ZM16.25,14.167C16.139,14.167 16.042,14.125 15.958,14.042C15.875,13.958 15.833,13.861 15.833,13.75V12.917C15.833,12.806 15.875,12.708 15.958,12.625C16.042,12.542 16.139,12.5 16.25,12.5H17.083C17.194,12.5 17.292,12.542 17.375,12.625C17.458,12.708 17.5,12.806 17.5,12.917V13.75C17.5,13.861 17.458,13.958 17.375,14.042C17.292,14.125 17.194,14.167 17.083,14.167H16.25Z"
android:fillColor="#282828"/>
<path
android:pathData="M4.167,9.167C3.708,9.167 3.316,9.003 2.99,8.677C2.663,8.351 2.5,7.958 2.5,7.5V4.167C2.5,3.708 2.663,3.316 2.99,2.99C3.316,2.663 3.708,2.5 4.167,2.5H7.5C7.958,2.5 8.351,2.663 8.677,2.99C9.003,3.316 9.167,3.708 9.167,4.167V7.5C9.167,7.958 9.003,8.351 8.677,8.677C8.351,9.003 7.958,9.167 7.5,9.167H4.167ZM4.167,7.5H7.5V4.167H4.167V7.5ZM4.167,17.5C3.708,17.5 3.316,17.337 2.99,17.01C2.663,16.684 2.5,16.292 2.5,15.833V12.5C2.5,12.042 2.663,11.649 2.99,11.323C3.316,10.997 3.708,10.833 4.167,10.833H7.5C7.958,10.833 8.351,10.997 8.677,11.323C9.003,11.649 9.167,12.042 9.167,12.5V15.833C9.167,16.292 9.003,16.684 8.677,17.01C8.351,17.337 7.958,17.5 7.5,17.5H4.167ZM4.167,15.833H7.5V12.5H4.167V15.833ZM12.5,9.167C12.042,9.167 11.649,9.003 11.323,8.677C10.997,8.351 10.833,7.958 10.833,7.5V4.167C10.833,3.708 10.997,3.316 11.323,2.99C11.649,2.663 12.042,2.5 12.5,2.5H15.833C16.292,2.5 16.684,2.663 17.01,2.99C17.337,3.316 17.5,3.708 17.5,4.167V7.5C17.5,7.958 17.337,8.351 17.01,8.677C16.684,9.003 16.292,9.167 15.833,9.167H12.5ZM12.5,7.5H15.833V4.167H12.5V7.5ZM16.25,17.5C16.139,17.5 16.042,17.458 15.958,17.375C15.875,17.292 15.833,17.194 15.833,17.083V16.25C15.833,16.139 15.875,16.042 15.958,15.958C16.042,15.875 16.139,15.833 16.25,15.833H17.083C17.194,15.833 17.292,15.875 17.375,15.958C17.458,16.042 17.5,16.139 17.5,16.25V17.083C17.5,17.194 17.458,17.292 17.375,17.375C17.292,17.458 17.194,17.5 17.083,17.5H16.25ZM11.25,12.5C11.139,12.5 11.042,12.458 10.958,12.375C10.875,12.292 10.833,12.194 10.833,12.083V11.25C10.833,11.139 10.875,11.042 10.958,10.958C11.042,10.875 11.139,10.833 11.25,10.833H12.083C12.194,10.833 12.292,10.875 12.375,10.958C12.458,11.042 12.5,11.139 12.5,11.25V12.083C12.5,12.194 12.458,12.292 12.375,12.375C12.292,12.458 12.194,12.5 12.083,12.5H11.25ZM12.917,14.167C12.806,14.167 12.708,14.125 12.625,14.042C12.542,13.958 12.5,13.861 12.5,13.75V12.917C12.5,12.806 12.542,12.708 12.625,12.625C12.708,12.542 12.806,12.5 12.917,12.5H13.75C13.861,12.5 13.958,12.542 14.042,12.625C14.125,12.708 14.167,12.806 14.167,12.917V13.75C14.167,13.861 14.125,13.958 14.042,14.042C13.958,14.125 13.861,14.167 13.75,14.167H12.917ZM11.25,15.833C11.139,15.833 11.042,15.792 10.958,15.708C10.875,15.625 10.833,15.528 10.833,15.417V14.583C10.833,14.472 10.875,14.375 10.958,14.292C11.042,14.208 11.139,14.167 11.25,14.167H12.083C12.194,14.167 12.292,14.208 12.375,14.292C12.458,14.375 12.5,14.472 12.5,14.583V15.417C12.5,15.528 12.458,15.625 12.375,15.708C12.292,15.792 12.194,15.833 12.083,15.833H11.25ZM12.917,17.5C12.806,17.5 12.708,17.458 12.625,17.375C12.542,17.292 12.5,17.194 12.5,17.083V16.25C12.5,16.139 12.542,16.042 12.625,15.958C12.708,15.875 12.806,15.833 12.917,15.833H13.75C13.861,15.833 13.958,15.875 14.042,15.958C14.125,16.042 14.167,16.139 14.167,16.25V17.083C14.167,17.194 14.125,17.292 14.042,17.375C13.958,17.458 13.861,17.5 13.75,17.5H12.917ZM14.583,15.833C14.472,15.833 14.375,15.792 14.292,15.708C14.208,15.625 14.167,15.528 14.167,15.417V14.583C14.167,14.472 14.208,14.375 14.292,14.292C14.375,14.208 14.472,14.167 14.583,14.167H15.417C15.528,14.167 15.625,14.208 15.708,14.292C15.792,14.375 15.833,14.472 15.833,14.583V15.417C15.833,15.528 15.792,15.625 15.708,15.708C15.625,15.792 15.528,15.833 15.417,15.833H14.583ZM14.583,12.5C14.472,12.5 14.375,12.458 14.292,12.375C14.208,12.292 14.167,12.194 14.167,12.083V11.25C14.167,11.139 14.208,11.042 14.292,10.958C14.375,10.875 14.472,10.833 14.583,10.833H15.417C15.528,10.833 15.625,10.875 15.708,10.958C15.792,11.042 15.833,11.139 15.833,11.25V12.083C15.833,12.194 15.792,12.292 15.708,12.375C15.625,12.458 15.528,12.5 15.417,12.5H14.583ZM16.25,14.167C16.139,14.167 16.042,14.125 15.958,14.042C15.875,13.958 15.833,13.861 15.833,13.75V12.917C15.833,12.806 15.875,12.708 15.958,12.625C16.042,12.542 16.139,12.5 16.25,12.5H17.083C17.194,12.5 17.292,12.542 17.375,12.625C17.458,12.708 17.5,12.806 17.5,12.917V13.75C17.5,13.861 17.458,13.958 17.375,14.042C17.292,14.125 17.194,14.167 17.083,14.167H16.25Z"
android:fillColor="@android:color/white"
android:pathData="M120,440L120,120L440,120L440,440L120,440ZM200,360L360,360L360,200L200,200L200,360ZM120,840L120,520L440,520L440,840L120,840ZM200,760L360,760L360,600L200,600L200,760ZM520,440L520,120L840,120L840,440L520,440ZM600,360L760,360L760,200L600,200L600,360ZM760,840L760,760L840,760L840,840L760,840ZM520,600L520,520L600,520L600,600L520,600ZM600,680L600,600L680,600L680,680L600,680ZM520,760L520,680L600,680L600,760L520,760ZM600,840L600,760L680,760L680,840L600,840ZM680,760L680,680L760,680L760,760L680,760ZM680,600L680,520L760,520L760,600L680,600ZM760,680L760,600L840,600L840,680L760,680Z"/>
android:fillAlpha="0.25"/>
</vector>

0 comments on commit 16d027d

Please sign in to comment.