Skip to content

Commit

Permalink
test: fix shouldCheckDisplayInList
Browse files Browse the repository at this point in the history
Signed-off-by: andresmr <[email protected]>
  • Loading branch information
andresmr committed Jul 17, 2024
1 parent 3ea368a commit e8468a6
Showing 1 changed file with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dhis2.usescases.searchte.robot

import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasParent
import androidx.compose.ui.test.hasTestTag
Expand All @@ -14,18 +15,16 @@ import androidx.compose.ui.test.performTextInput
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItem
import androidx.test.espresso.contrib.RecyclerViewActions.scrollTo
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry
import org.dhis2.R
import org.dhis2.common.BaseRobot
import org.dhis2.common.matchers.RecyclerviewMatchers
import org.dhis2.common.matchers.RecyclerviewMatchers.Companion.hasItem
import org.dhis2.common.matchers.RecyclerviewMatchers.Companion.hasNoMoreResultsInProgram
import org.dhis2.common.viewactions.openSpinnerPopup
import org.dhis2.usescases.searchTrackEntity.adapters.SearchTEViewHolder
import org.dhis2.usescases.searchTrackEntity.listView.SearchResult
import org.dhis2.usescases.searchte.entity.DisplayListFieldsUIModel
import org.hamcrest.CoreMatchers.allOf
Expand Down Expand Up @@ -128,14 +127,18 @@ class SearchTeiRobot(val composeTestRule: ComposeTestRule) : BaseRobot() {
}


@OptIn(ExperimentalTestApi::class)
fun checkFieldsFromDisplayList(
displayListFieldsUIModel: DisplayListFieldsUIModel
) {
//Given the title is the first attribute
val title = "First name: ${displayListFieldsUIModel.name}"
val displayedAttributes = createAttributesList(displayListFieldsUIModel)
val showMoreText = InstrumentationRegistry.getInstrumentation()
.targetContext.getString(R.string.show_more)
composeTestRule.waitUntilAtLeastOneExists(hasText(showMoreText))
//When we expand all attribute list
composeTestRule.onNodeWithText("Show more", true).performClick()
composeTestRule.onNodeWithText(showMoreText, true).performClick()
composeTestRule.waitForIdle()
//Then The title and all attributes are displayed
composeTestRule.onNodeWithText(title).assertIsDisplayed()
Expand Down Expand Up @@ -165,15 +168,6 @@ 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",
Expand Down

0 comments on commit e8468a6

Please sign in to comment.