Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [ANDROAPP-6315] adapt List card mappers to new mobile ui key val… #3722

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ProgramEventTest : BaseTest() {
clickOnCompleteButton()
}
programEventsRobot(composeTestRule) {
checkEventWasCreatedAndClosed(eventOrgUnit)
checkEventWasCreatedAndClosed()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@ package org.dhis2.usescases.programevent.robot

import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasAnyDescendant
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withTagValue
import androidx.test.espresso.matcher.ViewMatchers.withText
import org.dhis2.R
import org.dhis2.common.BaseRobot
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.anyOf
import org.hamcrest.CoreMatchers.equalTo

fun programEventsRobot(
composeTestRule: ComposeContentTestRule,
Expand All @@ -45,26 +41,28 @@ class ProgramEventsRobot(val composeTestRule: ComposeContentTestRule) : BaseRobo
onView(withId(R.id.navigation_map_view)).perform(click())
}

fun checkEventWasCreatedAndClosed(eventName: String) {
waitForView(
allOf(
withId(R.id.recycler),
hasDescendant(withText(eventName)),
hasDescendant(
withTagValue(
anyOf(
equalTo(R.drawable.ic_event_status_complete),
equalTo(R.drawable.ic_event_status_complete_read)
)


@OptIn(ExperimentalTestApi::class)
fun checkEventWasCreatedAndClosed() {
composeTestRule.waitUntilAtLeastOneExists(hasTestTag("EVENT_ITEM"))
composeTestRule.onNode(
hasTestTag("EVENT_ITEM")
and
hasAnyDescendant(
hasText("Event completed", true)
)
)
)
).check(matches(isDisplayed()))
and
hasAnyDescendant(
hasText("View only", true)
),
useUnmergedTree = true
).assertIsDisplayed()
}

@OptIn(ExperimentalTestApi::class)
fun checkEventIsComplete(eventDate: String) {
composeTestRule.waitUntilAtLeastOneExists(hasText("Event completed"))
composeTestRule.waitUntilAtLeastOneExists(hasText("Event completed"), 2500)
composeTestRule.onNodeWithText(eventDate).assertIsDisplayed()
composeTestRule.onNodeWithText("Event completed").assertIsDisplayed()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class SearchTETest : BaseTest() {
clickOnSearch()
checkListOfSearchTEI(
title = "First name: $firstName",
attributes = mapOf("Last name:" to lastName)
attributes = mapOf("Last name" to lastName),
)
}
}
Expand Down Expand Up @@ -112,7 +112,7 @@ class SearchTETest : BaseTest() {
composeTestRule.waitForIdle()
checkListOfSearchTEI(
title = "First name: $firstName",
attributes = mapOf("Last name:" to lastName)
attributes = mapOf("Last name" to lastName),
)
}
}
Expand Down Expand Up @@ -171,6 +171,7 @@ class SearchTETest : BaseTest() {
checkFilterCounter(totalFilterCount)
checkCountAtFilter(enrollmentStatusFilter, filterCount)
clickOnFilter()
waitToDebounce(2000)
checkTEIsAreOpen()
}
}
Expand All @@ -197,7 +198,7 @@ class SearchTETest : BaseTest() {
composeTestRule.onNodeWithTag(SECONDARY_BUTTON_TAG).performClick()
pressBack()
}

composeTestRule.waitForIdle()
filterRobot {
clickOnFilter()
clickOnFilterBy(eventStatusFilter)
Expand Down Expand Up @@ -337,7 +338,10 @@ class SearchTETest : BaseTest() {
clickOnOpenSearch()
openNextSearchParameter("First name")
typeOnNextSearchTextParameter(name)
waitToDebounce(2000)
clickOnSearch()
composeTestRule.waitForIdle()

}

filterRobot {
Expand All @@ -354,7 +358,7 @@ class SearchTETest : BaseTest() {
searchTeiRobot(composeTestRule) {
checkListOfSearchTEI(
title = "First name: $name",
attributes = mapOf("Last name:" to lastName)
attributes = mapOf("Last name" to lastName)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ class SearchTeiRobot(val composeTestRule: ComposeTestRule) : BaseRobot() {
//Checks title and all attributes are displayed
composeTestRule.onNodeWithText(title).assertIsDisplayed()
attributes.forEach { item ->
item.key?.let { composeTestRule.onNodeWithText(it).assertIsDisplayed() }
item.key?.let { composeTestRule.onNodeWithText("$it:",true).assertIsDisplayed() }
composeTestRule.onNode(
hasParent(hasTestTag("LIST_CARD_ADDITIONAL_INFO_COLUMN"))
and hasText(item.value), useUnmergedTree = true
and hasText(item.value,true), useUnmergedTree = true
).assertIsDisplayed()
}
}
Expand Down Expand Up @@ -151,17 +151,16 @@ class SearchTeiRobot(val composeTestRule: ComposeTestRule) : BaseRobot() {
//Given the title is the first attribute
val title = "First name: ${displayListFieldsUIModel.name}"
val displayedAttributes = createAttributesList(displayListFieldsUIModel)

//When we expand all attribute list
composeTestRule.onNodeWithText("Show more").performClick()

composeTestRule.onNodeWithText("Show more", true).performClick()
composeTestRule.waitForIdle()
//Then The title and all attributes are displayed
composeTestRule.onNodeWithText(title).assertIsDisplayed()
displayedAttributes.forEach { item ->
item.key?.let { composeTestRule.onNodeWithText(it).assertIsDisplayed() }
item.key?.let { composeTestRule.onNodeWithText("$it:", true).assertIsDisplayed() }
composeTestRule.onNode(
hasParent(hasTestTag("LIST_CARD_ADDITIONAL_INFO_COLUMN"))
and hasText(item.value), useUnmergedTree = true
and hasText(item.value,true), useUnmergedTree = true
).assertIsDisplayed()
}
}
Expand All @@ -183,21 +182,30 @@ class SearchTeiRobot(val composeTestRule: ComposeTestRule) : BaseRobot() {
onView(withId(R.id.createButton)).perform(click())
}

fun checkListOfSearchTEIWithAdditionalInfo(title: String, additionalText: String) {
composeTestRule.onNodeWithText(title).assertIsDisplayed()
composeTestRule.onNode(
hasParent(hasTestTag("LIST_CARD_ADDITIONAL_INFO_COLUMN"))
and hasText(additionalText, true),
useUnmergedTree = true,
).assertIsDisplayed()
}

private fun createAttributesList(displayListFieldsUIModel: DisplayListFieldsUIModel) = listOf(
AdditionalInfoItem(
key = "Last name:",
key = "Last name",
value = displayListFieldsUIModel.lastName,
),
AdditionalInfoItem(
key = "Email:",
key = "Email",
value = displayListFieldsUIModel.email,
),
AdditionalInfoItem(
key = "Date of birth:",
key = "Date of birth",
value = displayListFieldsUIModel.birthday,
),
AdditionalInfoItem(
key = "Address:",
key = "Address",
value = displayListFieldsUIModel.address,
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class TeiDashboardTest : BaseTest() {
}

enrollmentRobot(composeTestRule) {
composeTestRule.waitForIdle()
clickOnAProgramForEnrollment(composeTestRule, womanProgram)
clickOnAcceptInDatePicker()
openFormSection(personAttribute)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dhis2.usescases.teidashboard.robot

import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasAnySibling
import androidx.compose.ui.test.hasTestTag
Expand Down Expand Up @@ -81,7 +82,9 @@ class EventRobot(val composeTestRule: ComposeTestRule) : BaseRobot() {
composeTestRule.onNode(hasText(date, true)).performClick()
}

@OptIn(ExperimentalTestApi::class)
fun typeOnDateParameter(dateValue: String) {
composeTestRule.waitUntilAtLeastOneExists(hasTestTag("INPUT_DATE_TIME_TEXT_FIELD"),2000)
composeTestRule.apply {
onNodeWithTag("INPUT_DATE_TIME_TEXT_FIELD").performClick()
onNodeWithTag("INPUT_DATE_TIME_TEXT_FIELD").performTextInput(dateValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ class EventCapturePresenterImpl(
.defaultSubscribe(
schedulerProvider,
onNext = {
EventIdlingResourceSingleton.decrement()
if (addNew) {
view.restartDataEntry()
} else {
preferences.setValue(Preference.PREF_COMPLETED_EVENT, eventUid)
view.finishDataEntry()
}
EventIdlingResourceSingleton.decrement()
},
onError = {
EventIdlingResourceSingleton.decrement()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class EventCardMapper(
!it.second.isNullOrEmpty()
}?.map {
AdditionalInfoItem(
key = "${it.first}:",
value = it.second ?: "",
key = it.first,
value = it.second ?: "-",
)
}?.toMutableList() ?: mutableListOf()

Expand Down Expand Up @@ -144,7 +144,7 @@ class EventCardMapper(
) {
list.add(
AdditionalInfoItem(
key = "${event.nameCategoryOptionCombo}:",
key = event.nameCategoryOptionCombo,
value = event.catComboName ?: "",
isConstantItem = true,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class SearchTEIViewModel(
private val _legacyInteraction = MutableLiveData<LegacyInteraction?>()
val legacyInteraction: LiveData<LegacyInteraction?> = _legacyInteraction

val filterManager: FilterManager = FilterManager.getInstance()

private val _refreshData = MutableLiveData(Unit)
val refreshData: LiveData<Unit> = _refreshData

Expand Down Expand Up @@ -326,20 +328,20 @@ class SearchTEIViewModel(
withContext(dispatchers.io()) {
if (
searching && networkUtils.isOnline() &&
FilterManager.getInstance().stateFilters.isEmpty()
filterManager.stateFilters.isEmpty()
) {
searchRepository.transform(
item,
searchParametersModel.selectedProgram,
false,
FilterManager.getInstance().sortingItem,
filterManager.sortingItem,
)
} else {
searchRepository.transform(
item,
searchParametersModel.selectedProgram,
true,
FilterManager.getInstance().sortingItem,
filterManager.sortingItem,
)
}
}
Expand All @@ -364,7 +366,7 @@ class SearchTEIViewModel(
item,
searchParametersModel.selectedProgram,
true,
FilterManager.getInstance().sortingItem,
filterManager.sortingItem,
)
}
}
Expand All @@ -387,20 +389,20 @@ class SearchTEIViewModel(
withContext(dispatchers.io()) {
if (
searching && networkUtils.isOnline() &&
FilterManager.getInstance().stateFilters.isEmpty()
filterManager.stateFilters.isEmpty()
) {
searchRepository.transform(
item,
searchParametersModel.selectedProgram,
false,
FilterManager.getInstance().sortingItem,
filterManager.sortingItem,
)
} else {
searchRepository.transform(
item,
searchParametersModel.selectedProgram,
true,
FilterManager.getInstance().sortingItem,
filterManager.sortingItem,
)
}
}
Expand Down Expand Up @@ -445,7 +447,12 @@ class SearchTEIViewModel(
SearchScreenState.LIST -> {
SearchIdlingResourceSingleton.increment()
setListScreen()
_refreshData.postValue(Unit)
fetchListResults { flow ->
flow?.let {
_refreshData.postValue(Unit)
SearchIdlingResourceSingleton.decrement()
}
}
}

SearchScreenState.MAP -> {
Expand Down Expand Up @@ -888,9 +895,9 @@ class SearchTEIViewModel(
/* selectedProgram = */
searchParametersModel.selectedProgram,
/* offlineOnly = */
!(isOnline && FilterManager.getInstance().stateFilters.isEmpty()),
!(isOnline && filterManager.stateFilters.isEmpty()),
/* sortingItem = */
FilterManager.getInstance().sortingItem,
filterManager.sortingItem,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ class TEICardMapper(
private fun getAdditionalInfoList(searchTEIModel: SearchTeiModel): List<AdditionalInfoItem> {
val attributeList = searchTEIModel.attributeValues.map {
AdditionalInfoItem(
key = "${it.key}:",
value = it.value.value() ?: "",
key = it.key,
value = it.value.value() ?: "-",
)
}.toMutableList()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ class TEIEventCardMapper(
!it.second.isNullOrEmpty() && it.second != "-"
}?.map {
AdditionalInfoItem(
key = "${it.first}:",
value = it.second ?: "",
key = it.first,
value = it.second ?: "-",
)
}?.toMutableList() ?: mutableListOf()

Expand Down Expand Up @@ -161,8 +161,8 @@ class TEIEventCardMapper(
) {
list.add(
AdditionalInfoItem(
key = "${event.nameCategoryOptionCombo}:",
value = event.catComboName ?: "",
key = event.nameCategoryOptionCombo,
value = event.catComboName ?: "-",
isConstantItem = true,
),
)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_dashboard_program.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
app:layout_constraintEnd_toStartOf="@id/enrolledOrgUnit"
app:layout_constraintStart_toEndOf="@id/program_image"
app:layout_constraintTop_toBottomOf="@id/program_name"
tools:text="enrolled in:" />
tools:text="enrolled in" />

<TextView
android:id="@+id/enrolledOrgUnit"
Expand Down
Loading
Loading