Skip to content

Commit

Permalink
[ANDROAPP-5901] Move create button in timeline view (#3490)
Browse files Browse the repository at this point in the history
  • Loading branch information
Balcan authored Feb 22, 2024
1 parent ea9ef88 commit 1260a1f
Show file tree
Hide file tree
Showing 39 changed files with 1,201 additions and 1,510 deletions.
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ dependencies {
implementation(libs.analytics.customactivityoncrash)
implementation(platform(libs.dispatcher.dispatchBOM))
implementation(libs.dispatcher.dispatchCore)
implementation(libs.dhis2.mobile.designsystem)

coreLibraryDesugaring(libs.desugar)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.junit4.ComposeTestRule
import org.dhis2.common.BaseRobot
import org.dhis2.usescases.flow.teiFlow.entity.DateRegistrationUIModel
import org.dhis2.usescases.searchte.robot.searchTeiRobot
import org.dhis2.usescases.flow.teiFlow.entity.EnrollmentListUIModel
import org.dhis2.usescases.flow.teiFlow.entity.RegisterTEIUIModel
import org.dhis2.usescases.searchte.robot.searchTeiRobot
import org.dhis2.usescases.teidashboard.robot.enrollmentRobot
import org.dhis2.usescases.teidashboard.robot.eventRobot
import org.dhis2.usescases.teidashboard.robot.teiDashboardRobot
Expand Down Expand Up @@ -77,23 +77,31 @@ class TeiFlowRobot : BaseRobot() {

teiDashboardRobot {
checkCompleteStateInfoBarIsDisplay(composeTestRule)
checkCanNotAddEvent()
checkCanNotAddEvent(composeTestRule)
checkAllEventsAreClosed(totalEvents)
}
}

fun closeEnrollmentAndCheckEvents(totalEvents: Int) {
fun closeEnrollmentAndCheckEvents(
composeTestRule: ComposeContentTestRule,
totalEvents: Int
) {
teiDashboardRobot {
clickOnMenuMoreOptions()
clickOnTimelineEvents()
clickOnMenuMoreOptions()
clickOnMenuComplete()
checkCanNotAddEvent()
checkCanNotAddEvent(composeTestRule)
checkAllEventsAreClosed(totalEvents)
}
}

fun changeDueDate(date: DateRegistrationUIModel, programStage: String, orgUnit: String, composeTestRule: ComposeTestRule) {
fun changeDueDate(
date: DateRegistrationUIModel,
programStage: String,
orgUnit: String,
composeTestRule: ComposeTestRule
) {
teiDashboardRobot {
clickOnStageGroup(programStage)
clickOnEventGroupByStageUsingOU(orgUnit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TeiFlowTest: BaseTest() {

teiFlowRobot {
registerTEI(registerTeiDetails)
closeEnrollmentAndCheckEvents(totalEventsPerEnrollment)
closeEnrollmentAndCheckEvents(composeTestRule,totalEventsPerEnrollment)
enrollToProgram(composeTestRule, ADULT_WOMAN_PROGRAM)
checkActiveAndPastEnrollmentDetails(enrollmentListDetails)
checkPastEventsAreClosed(composeTestRule, totalEventsPerEnrollment, pastProgramPosition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,32 @@ package org.dhis2.usescases.teidashboard
import android.view.View
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.rules.activityScenarioRule
import dhis2.org.analytics.charts.Charts
import io.reactivex.Observable
import java.util.Calendar
import org.dhis2.R
import org.dhis2.android.rtsm.utils.NetworkUtils
import org.dhis2.commons.date.DateUtils
import org.dhis2.commons.filters.FilterManager
import org.dhis2.commons.prefs.PreferenceProvider
import org.dhis2.commons.resources.ResourceManager
import org.dhis2.commons.viewmodel.DispatcherProvider
import org.dhis2.ui.ThemeManager
import org.dhis2.usescases.eventsWithoutRegistration.eventDetails.EventInitialTest
import org.dhis2.usescases.eventsWithoutRegistration.eventDetails.data.EventDetailsRepository
import org.dhis2.usescases.main.program.ProgramPresenter
import org.dhis2.usescases.teiDashboard.DashboardRepositoryImpl
import org.dhis2.usescases.teiDashboard.DashboardViewModel
import org.dhis2.usescases.teiDashboard.TeiAttributesProvider
import org.dhis2.usescases.teiDashboard.TeiDashboardContracts
import org.dhis2.usescases.teiDashboard.TeiDashboardMobileActivity
import org.dhis2.utils.analytics.AnalyticsHelper
import org.hisp.dhis.android.core.D2
import org.hisp.dhis.android.core.event.EventEditableStatus
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance
import org.hisp.dhis.android.core.trackedentity.TrackedEntityType
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.ArgumentMatchers
import org.mockito.Mockito
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.doReturnConsecutively
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import java.util.Calendar

class TeiDashboardMobileActivityTest {

Expand All @@ -55,18 +45,23 @@ class TeiDashboardMobileActivityTest {
private val resources: ResourceManager = mock()
private val charts: Charts = mock()
private val teiAttributesProvider: TeiAttributesProvider = mock()
private val preferences: PreferenceProvider = mock()


private var repository: DashboardRepositoryImpl = mock {

}
var tei = Observable.just(TrackedEntityInstance.builder()
.uid(TEI_Uid)
.created(Calendar.getInstance().time)
.lastUpdated(Calendar.getInstance().time)
.organisationUnit(ORG_UNIT_UID)
.trackedEntityType(TETYPE_NAME)
.build())

private var dispatcher:DispatcherProvider = mock()
var tei = Observable.just(
TrackedEntityInstance.builder()
.uid(TEI_Uid)
.created(Calendar.getInstance().time)
.lastUpdated(Calendar.getInstance().time)
.organisationUnit(ORG_UNIT_UID)
.trackedEntityType(TETYPE_NAME)
.build()
)

private val teType: TrackedEntityType = mock()

Expand All @@ -93,9 +88,10 @@ class TeiDashboardMobileActivityTest {
}

private fun initViewModel() {
viewModel = DashboardViewModel(
repository ,
analyticsHelper
viewModel = DashboardViewModel(
repository,
analyticsHelper,
dispatcher,
)

}
Expand All @@ -112,8 +108,8 @@ class TeiDashboardMobileActivityTest {
TEI_Uid,
PROGRAM_UID,
ENROLLMENT_UID,
resources,
teiAttributesProvider,
preferences,
)


Expand All @@ -123,58 +119,73 @@ class TeiDashboardMobileActivityTest {
@Test
fun shouldSuccessfullyInitializeTeiDashBoardMobileActivity() {
setUp()
whenever (repository.getTETypeName()) doReturn TETYPE_NAME
whenever ( repository.getTrackedEntityInstance("") ) doReturn mock()
whenever {repository.getTrackedEntityInstance("").flatMap { tei: TrackedEntityInstance ->
d2.trackedEntityModule().trackedEntityTypes()
.uid(tei.trackedEntityType())
.get()
.toObservable()
} } doReturn mock()
whenever {repository.getTrackedEntityInstance("").flatMap { tei: TrackedEntityInstance ->
d2.trackedEntityModule().trackedEntityTypes()
.uid(tei.trackedEntityType())
.get()
.toObservable()
}.blockingFirst() } doReturn { teType }
whenever(repository.getTETypeName()) doReturn TETYPE_NAME
whenever(repository.getTrackedEntityInstance("")) doReturn mock()
whenever {
repository.getTrackedEntityInstance("").flatMap { tei: TrackedEntityInstance ->
d2.trackedEntityModule().trackedEntityTypes()
.uid(tei.trackedEntityType())
.get()
.toObservable()
}
} doReturn mock()
whenever {
repository.getTrackedEntityInstance("").flatMap { tei: TrackedEntityInstance ->
d2.trackedEntityModule().trackedEntityTypes()
.uid(tei.trackedEntityType())
.get()
.toObservable()
}.blockingFirst()
} doReturn { teType }
whenever(
presenter.teType
) doReturn TETYPE_NAME
) doReturn TETYPE_NAME

whenever(
repository.getTETypeName()
) doReturn TETYPE_NAME
) doReturn TETYPE_NAME
whenever(
d2.trackedEntityModule() ) doReturn mock()
d2.trackedEntityModule()
) doReturn mock()
whenever(
d2.trackedEntityModule().trackedEntityInstances() ) doReturn mock()
d2.trackedEntityModule().trackedEntityInstances()
) doReturn mock()
whenever(
d2.trackedEntityModule().trackedEntityInstances().byUid() ) doReturn mock()
d2.trackedEntityModule().trackedEntityInstances().byUid()
) doReturn mock()
whenever(
d2.trackedEntityModule().trackedEntityInstances().byUid().eq("") ) doReturn mock()
d2.trackedEntityModule().trackedEntityInstances().byUid().eq("")
) doReturn mock()
whenever(
d2.trackedEntityModule().trackedEntityInstances().byUid().eq("").one() ) doReturn mock()
d2.trackedEntityModule().trackedEntityInstances().byUid().eq("").one()
) doReturn mock()
whenever(
d2.trackedEntityModule().trackedEntityInstances().byUid().eq("").one()
.blockingGet() ) doReturn mock()
.blockingGet()
) doReturn mock()

whenever(
d2.trackedEntityModule().trackedEntityTypes() ) doReturn mock()
d2.trackedEntityModule().trackedEntityTypes()
) doReturn mock()
whenever(
d2.trackedEntityModule().trackedEntityTypes().uid("") ) doReturn mock()
d2.trackedEntityModule().trackedEntityTypes().uid("")
) doReturn mock()
whenever(
d2.trackedEntityModule().trackedEntityTypes().uid("").get() ) doReturn mock()
d2.trackedEntityModule().trackedEntityTypes().uid("").get()
) doReturn mock()
whenever(
d2.trackedEntityModule().trackedEntityTypes().uid("").get().toObservable() ) doReturn mock()
d2.trackedEntityModule().trackedEntityTypes().uid("").get().toObservable()
) doReturn mock()
whenever(
d2.trackedEntityModule().trackedEntityTypes().uid("").get().toObservable() ) doReturn mock()
d2.trackedEntityModule().trackedEntityTypes().uid("").get().toObservable()
) doReturn mock()




ActivityScenario.launch(TeiDashboardMobileActivity::class.java).onActivity { activity ->

val showMoreOptions = activity.findViewById<View>(R.id.moreOptions)
val showMoreOptions = activity.findViewById<View>(R.id.moreOptions)
showMoreOptions.performClick()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.dhis2.usescases.teidashboard.robot.eventRobot
import org.dhis2.usescases.teidashboard.robot.indicatorsRobot
import org.dhis2.usescases.teidashboard.robot.noteRobot
import org.dhis2.usescases.teidashboard.robot.teiDashboardRobot
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -103,7 +104,7 @@ class TeiDashboardTest : BaseTest() {
clickOnMenuMoreOptions()
clickOnMenuDeactivate()
checkCancelledStateInfoBarIsDisplay(composeTestRule)
checkCanNotAddEvent()
checkCanNotAddEvent(composeTestRule)
checkAllEventsAreInactive(1)
}
}
Expand All @@ -118,7 +119,7 @@ class TeiDashboardTest : BaseTest() {
clickOnMenuMoreOptions()
clickOnMenuComplete()
checkCompleteStateInfoBarIsDisplay(composeTestRule)
checkCanNotAddEvent()
checkCanNotAddEvent(composeTestRule)
checkAllEventsAreClosed(1)
}
}
Expand All @@ -141,8 +142,8 @@ class TeiDashboardTest : BaseTest() {
teiDashboardRobot {
clickOnMenuMoreOptions()
clickOnTimelineEvents()
clickOnFab()
clickOnReferral()
clickOnFab(composeTestRule)
clickOnReferral(composeTestRule)
clickOnFirstReferralEvent()
clickOnReferralOption(
composeTestRule,
Expand All @@ -160,8 +161,8 @@ class TeiDashboardTest : BaseTest() {
teiDashboardRobot {
clickOnMenuMoreOptions()
clickOnTimelineEvents()
clickOnFab()
clickOnScheduleNew()
clickOnFab(composeTestRule)
clickOnScheduleNew(composeTestRule)
clickOnFirstReferralEvent()
clickOnReferralNextButton()
checkEventWasCreatedWithDate(LAB_MONITORING, LAB_MONITORING_SCHEDULE_DATE)
Expand All @@ -188,6 +189,7 @@ class TeiDashboardTest : BaseTest() {
}
}

@Ignore("This is checking xml instead of compose. Update mobile library with test tags.")
@Test
fun shouldShowCorrectInfoWhenOpenTEI() {
prepareTeiCompletedProgrammeAndLaunchActivity(rule)
Expand Down
Loading

0 comments on commit 1260a1f

Please sign in to comment.