Skip to content

Commit

Permalink
fix: [ANDROAPP-6194] Add mockedWebServer response to mock get tracked…
Browse files Browse the repository at this point in the history
… entity instances

Signed-off-by: andresmr <[email protected]>
  • Loading branch information
andresmr committed Jun 6, 2024
1 parent 55b9148 commit b9cee8b
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 392 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ class MockWebServerRobot(private val dhis2MockServer: Dhis2MockServer) {
fun addResponse(method: String, path: String, sdkResource: String, responseCode: Int = 200) {
dhis2MockServer.addResponse(method, path, sdkResource, responseCode)
}

companion object {
const val API_OLD_TRACKED_ENTITY_PATH = "/api/trackedEntityInstances/query?.*"
const val API_OLD_TRACKED_ENTITY_RESPONSE =
"mocks/teilist/old_tracked_entity_empty_response.json"

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import androidx.compose.ui.text.intl.Locale
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import org.dhis2.R
import org.dhis2.common.mockwebserver.MockWebServerRobot.Companion.API_OLD_TRACKED_ENTITY_PATH
import org.dhis2.common.mockwebserver.MockWebServerRobot.Companion.API_OLD_TRACKED_ENTITY_RESPONSE
import org.dhis2.usescases.BaseTest
import org.dhis2.usescases.flow.teiFlow.entity.DateRegistrationUIModel
import org.dhis2.usescases.flow.teiFlow.entity.RegisterTEIUIModel
import org.dhis2.usescases.flow.teiFlow.teiFlowRobot
import org.dhis2.usescases.searchTrackEntity.SearchTEActivity
import org.hisp.dhis.android.core.mockwebserver.ResponseController
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -28,8 +31,19 @@ class SearchFlowTest : BaseTest() {
private val dateRegistration = createFirstSpecificDate()
private val dateEnrollment = createEnrollmentDate()

override fun setUp() {
super.setUp()
setupMockServer()
}

@Test
fun shouldCreateTEIAndFilterByEnrollment() {
mockWebServerRobot.addResponse(
ResponseController.GET,
API_OLD_TRACKED_ENTITY_PATH,
API_OLD_TRACKED_ENTITY_RESPONSE,
)

setDatePicker()
val registerTEIDetails = createRegisterTEI()
val enrollmentStatus = context.getString(R.string.filters_title_enrollment_status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import android.content.Intent
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import org.dhis2.common.mockwebserver.MockWebServerRobot.Companion.API_OLD_TRACKED_ENTITY_PATH
import org.dhis2.common.mockwebserver.MockWebServerRobot.Companion.API_OLD_TRACKED_ENTITY_RESPONSE
import org.dhis2.usescases.BaseTest
import org.dhis2.usescases.flow.teiFlow.entity.DateRegistrationUIModel
import org.dhis2.usescases.flow.teiFlow.entity.EnrollmentListUIModel
import org.dhis2.usescases.flow.teiFlow.entity.RegisterTEIUIModel
import org.dhis2.usescases.searchTrackEntity.SearchTEActivity
import org.dhis2.usescases.teiDashboard.TeiDashboardMobileActivity
import org.hisp.dhis.android.core.mockwebserver.ResponseController
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -33,8 +36,19 @@ class TeiFlowTest : BaseTest() {
private val dateEnrollment = createEnrollmentDate()
private val currentDate = getCurrentDate()

override fun setUp() {
super.setUp()
setupMockServer()
}

@Test
fun shouldEnrollToSameProgramAfterClosingIt() {
mockWebServerRobot.addResponse(
ResponseController.GET,
API_OLD_TRACKED_ENTITY_PATH,
API_OLD_TRACKED_ENTITY_RESPONSE,
)

val totalEventsPerEnrollment = 3
val enrollmentListDetails = createEnrollmentList()
val registerTeiDetails = createRegisterTEI()
Expand Down Expand Up @@ -105,6 +119,5 @@ class TeiFlowTest : BaseTest() {

const val DATE_FORMAT = "dd/M/yyyy"
const val DATE_PICKER_FORMAT = ", d MMMM"

}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.dhis2.usescases.searchte

import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.text.capitalize
import androidx.compose.ui.text.intl.Locale
Expand All @@ -19,6 +17,8 @@ import dispatch.android.espresso.IdlingDispatcherProviderRule
import org.dhis2.R
import org.dhis2.bindings.app
import org.dhis2.common.idlingresources.MapIdlingResource
import org.dhis2.common.mockwebserver.MockWebServerRobot.Companion.API_OLD_TRACKED_ENTITY_PATH
import org.dhis2.common.mockwebserver.MockWebServerRobot.Companion.API_OLD_TRACKED_ENTITY_RESPONSE
import org.dhis2.commons.date.DateUtils.SIMPLE_DATE_FORMAT
import org.dhis2.lazyActivityScenarioRule
import org.dhis2.ui.dialogs.bottomsheet.SECONDARY_BUTTON_TAG
Expand All @@ -32,6 +32,7 @@ import org.dhis2.usescases.searchte.entity.DisplayListFieldsUIModel
import org.dhis2.usescases.searchte.robot.filterRobot
import org.dhis2.usescases.searchte.robot.searchTeiRobot
import org.dhis2.usescases.teidashboard.robot.teiDashboardRobot
import org.hisp.dhis.android.core.mockwebserver.ResponseController
import org.junit.After
import org.junit.Ignore
import org.junit.Rule
Expand Down Expand Up @@ -61,8 +62,19 @@ class SearchTETest : BaseTest() {
@get:Rule
val composeTestRule = createComposeRule()

override fun setUp() {
super.setUp()
setupMockServer()
}

@Test
fun shouldSuccessfullySearchByName() {
mockWebServerRobot.addResponse(
ResponseController.GET,
API_OLD_TRACKED_ENTITY_PATH,
API_OLD_TRACKED_ENTITY_RESPONSE,
)

val firstName = "Tim"
val lastName = "Johnson"

Expand All @@ -82,6 +94,12 @@ class SearchTETest : BaseTest() {

@Test
fun shouldShowErrorWhenCanNotFindSearchResult() {
mockWebServerRobot.addResponse(
ResponseController.GET,
API_OLD_TRACKED_ENTITY_PATH,
API_OLD_TRACKED_ENTITY_RESPONSE,
)

val firstName = "asdssds"

prepareTestProgramRulesProgrammeIntentAndLaunchActivity(rule)
Expand All @@ -97,6 +115,12 @@ class SearchTETest : BaseTest() {

@Test
fun shouldSuccessfullySearchUsingMoreThanOneField() {
mockWebServerRobot.addResponse(
ResponseController.GET,
API_OLD_TRACKED_ENTITY_PATH,
API_OLD_TRACKED_ENTITY_RESPONSE,
)

val firstName = "Anna"
val lastName = "Jones"

Expand Down Expand Up @@ -133,6 +157,12 @@ class SearchTETest : BaseTest() {

@Test
fun shouldCheckDisplayInList() {
mockWebServerRobot.addResponse(
ResponseController.GET,
API_OLD_TRACKED_ENTITY_PATH,
API_OLD_TRACKED_ENTITY_RESPONSE,
)

val displayInListData = createDisplayListFields()

prepareTestAdultWomanProgrammeIntentAndLaunchActivity(rule)
Expand Down Expand Up @@ -286,6 +316,12 @@ class SearchTETest : BaseTest() {

@Test
fun shouldSuccessfullyFilterBySync() {
mockWebServerRobot.addResponse(
ResponseController.GET,
API_OLD_TRACKED_ENTITY_PATH,
API_OLD_TRACKED_ENTITY_RESPONSE,
)

val teiName = "Frank"
val teiLastName = "Fjordsen"
val syncFilter = context.getString(R.string.action_sync)
Expand Down Expand Up @@ -321,6 +357,12 @@ class SearchTETest : BaseTest() {

@Test
fun shouldSuccessfullySearchAndFilter() {
mockWebServerRobot.addResponse(
ResponseController.GET,
API_OLD_TRACKED_ENTITY_PATH,
API_OLD_TRACKED_ENTITY_RESPONSE,
)

val name = "Anna"
val lastName = "Jones"
val enrollmentStatus = context.getString(R.string.filters_title_enrollment_status)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"headers": [
{
"name": "instance",
"column": "Instance",
"type": "java.lang.String",
"hidden": false,
"meta": false
},
{
"name": "created",
"column": "Created",
"type": "java.lang.String",
"hidden": false,
"meta": false
},
{
"name": "lastupdated",
"column": "Last updated",
"type": "java.lang.String",
"hidden": false,
"meta": false
},
{
"name": "ou",
"column": "Organisation unit",
"type": "java.lang.String",
"hidden": false,
"meta": false
},
{
"name": "ouname",
"column": "Organisation unit name",
"type": "java.lang.String",
"hidden": false,
"meta": false
},
{
"name": "te",
"column": "Tracked entity type",
"type": "java.lang.String",
"hidden": false,
"meta": false
},
{
"name": "inactive",
"column": "Inactive",
"type": "java.lang.String",
"hidden": false,
"meta": false
}
],
"metaData": {
"names": {
"nEenWmSyUEp": "Person"
}
},
"width": 9,
"height": 0,
"rows": [
]
}
Loading

0 comments on commit b9cee8b

Please sign in to comment.