Skip to content

Commit

Permalink
fix: [ANDROAPP-6315] adapt List card mappers to new mobile ui key val… (
Browse files Browse the repository at this point in the history
#3722)

* fix: [ANDROAPP-6315] adapt List card mappers to new mobile ui key value functionality

* fix: [ANDROAPP-6315] fix compose test

* fix: [ANDROAPP-6315] fix compose test

* fix: [ANDROAPP-6315] fix conflict resolution

* fix: [ANDROAPP-6315] fix failing age provider test

* fix: [ANDROAPP-6315] fix failing tests

* fix: [ANDROAPP-6315] fix failing tests

* [ANDROAPP-6315] Remove ":" from TeiDashboardCardMapper

Signed-off-by: andresmr <[email protected]>

* [ANDROAPP-6315] Inject FilterManager into SearchTEIViewModel

Signed-off-by: andresmr <[email protected]>

* fix: [ANDROAPP-6315] fix failing test

* fix: [ANDROAPP-6315] fix  test

---------

Signed-off-by: andresmr <[email protected]>
Co-authored-by: andresmr <[email protected]>
  • Loading branch information
xavimolloy and andresmr authored Jul 16, 2024
1 parent 1f5681b commit 6746dbb
Show file tree
Hide file tree
Showing 22 changed files with 128 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class SyncFlowTest : BaseTest() {
openNextSearchParameter("Last name")
typeOnNextSearchTextParameter(teiLastName)
clickOnSearch()
clickOnTEI(teiName, teiLastName)
clickOnTEI(teiName, composeTestRule)
}

teiDashboardRobot(composeTestRule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SyncFlowRobot(val composeTestRule: ComposeTestRule) : BaseRobot() {
fun checkSyncWasSuccessfully() {
val expectedTitle = InstrumentationRegistry.getInstrumentation()
.targetContext.getString(R.string.sync_dialog_title_synced)
composeTestRule.onNodeWithTag(TITLE, useUnmergedTree = true).assert(hasText(expectedTitle))
composeTestRule.onNodeWithTag(TITLE, useUnmergedTree = true).assert(hasText(expectedTitle, true))
}

fun checkSyncFailed() {
Expand Down
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,28 +41,30 @@ 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.onNodeWithText(eventDate).assertIsDisplayed()
composeTestRule.onNodeWithText("Event completed").assertIsDisplayed()
composeTestRule.waitUntilAtLeastOneExists(hasText("Event completed", true), 2000)
composeTestRule.onNodeWithText(eventDate,true).assertIsDisplayed()
composeTestRule.onNodeWithText("Event completed",true).assertIsDisplayed()
}

fun checkEventWasDeleted(eventDate: String) {
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 @@ -299,7 +300,7 @@ class SearchTETest : BaseTest() {
openNextSearchParameter("Last name")
typeOnNextSearchTextParameter(teiLastName)
clickOnSearch()
clickOnTEI(teiName, teiLastName)
clickOnTEI(teiName, composeTestRule)
}

teiDashboardRobot(composeTestRule) {
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 @@ -44,27 +44,10 @@ fun searchTeiRobot(

class SearchTeiRobot(val composeTestRule: ComposeTestRule) : BaseRobot() {

fun clickOnTEI(teiName: String, teiLastName: String) {
waitForView(
allOf(
withId(R.id.scrollView),
hasDescendant(withText(teiName)),
hasDescendant(withText(teiLastName))
)
).perform(
scrollTo<SearchTEViewHolder>(
allOf(
hasDescendant(withText(teiName)),
hasDescendant(withText(teiLastName))
)
),
actionOnItem<SearchTEViewHolder>(
allOf(
hasDescendant(withText(teiName)),
hasDescendant(withText(teiLastName))
), click()
)
)
fun clickOnTEI(teiName: String, composeTestRule: ComposeTestRule) {
composeTestRule.waitForIdle()
composeTestRule.onNodeWithText("First name: $teiName", true).performClick()
composeTestRule.waitForIdle()
}

fun checkTEIsDelete(teiName: String, teiLastName: String) {
Expand Down Expand Up @@ -109,10 +92,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 +134,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 +165,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
Expand Up @@ -33,7 +33,7 @@ class TeiDashboardTestNoComposable : BaseTest() {
prepareChildProgrammeIntentAndLaunchActivity(ruleSearch)

searchTeiRobot(composeTestRule) {
clickOnTEI(teiName, teiLastName)
clickOnTEI(teiName, composeTestRule)
}

teiDashboardRobot(composeTestRule) {
Expand All @@ -54,7 +54,7 @@ class TeiDashboardTestNoComposable : BaseTest() {
openNextSearchParameter("Last name")
typeOnNextSearchTextParameter(relationshipLastName)
clickOnSearch()
clickOnTEI(relationshipName, relationshipLastName)
clickOnTEI(relationshipName, composeTestRule)
}

relationshipRobot {
Expand All @@ -77,7 +77,7 @@ class TeiDashboardTestNoComposable : BaseTest() {
openNextSearchParameter("Last name")
typeOnNextSearchTextParameter(teiLastName)
clickOnSearch()
clickOnTEI(teiName, teiLastName)
clickOnTEI(teiName, composeTestRule)
}

teiDashboardRobot(composeTestRule) {
Expand Down Expand Up @@ -106,7 +106,7 @@ class TeiDashboardTestNoComposable : BaseTest() {
openNextSearchParameter("Last name")
typeOnNextSearchTextParameter(teiLastName)
clickOnSearch()
clickOnTEI(teiName, teiLastName)
clickOnTEI(teiName, composeTestRule)
}

teiDashboardRobot(composeTestRule) {
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
Loading

0 comments on commit 6746dbb

Please sign in to comment.