Skip to content

Commit

Permalink
testing: use navTestInvokation to help with navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
misterM125 committed Dec 13, 2024
1 parent 3846783 commit c55c06c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ 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.test.performTextClearance
import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.performTouchInput
import androidx.compose.ui.unit.height
import androidx.compose.ui.unit.size
Expand Down Expand Up @@ -68,6 +70,7 @@ import org.mockito.Mockito.`when`
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.any
import org.mockito.kotlin.eq
import org.mockito.kotlin.verify

@RunWith(AndroidJUnit4::class)
class End2EndCreateEvent {
Expand Down Expand Up @@ -202,6 +205,7 @@ class End2EndCreateEvent {
`when`(eventDocument.get("maxParticipants")).thenReturn(event.maxParticipants.toLong())
`when`(eventDocument.get("parkId")).thenReturn(event.parkId)
`when`(eventDocument.get("listParticipants")).thenReturn(event.listParticipants)
`when`(eventDocument.get("status")).thenReturn("CREATED")

// repositories
`when`(parkLocationRepository.search(any(), any(), any(), any())).then {
Expand Down Expand Up @@ -254,7 +258,8 @@ class End2EndCreateEvent {
GoogleAuthService(
"abc",
mock(FirebaseAuth::class.java, RETURNS_DEFAULTS),
context = LocalContext.current))
context = LocalContext.current),
navTestInvokationOnEachRecompose = true)
}

// Wait for the map to be loaded
Expand Down Expand Up @@ -291,44 +296,57 @@ class End2EndCreateEvent {
click(Offset(xClickOffset.toPx(), yClickOffset.toPx() - yOffsetCorr.toPx() - 3))
}

// need to wait before clicking again else the click is considered as a double click
composeTestRule.waitUntil(3000) {
runBlocking { delay(2000) }
true
}

currentScreen = Screen.PARK_OVERVIEW

composeTestRule.waitUntil(5000) {
composeTestRule.onNodeWithTag("parkOverviewScreen").isDisplayed()
}

// create an event
// composeTestRule.onNodeWithTag("createEventButton").assertIsDisplayed().performClick()

/**
* composeTestRule.onNodeWithTag("addEventScreen").assertIsDisplayed()
*
* composeTestRule.onNodeWithTag("titleTag").assertIsDisplayed().performTextClearance()
*
* composeTestRule.onNodeWithTag("titleTag").performTextInput(event.title)
*
* composeTestRule.onNodeWithTag("descriptionTag").assertIsDisplayed().performTextClearance()
*
* composeTestRule.onNodeWithTag("descriptionTag").performTextInput(event.description)
*
* composeTestRule.onNodeWithTag("dateIcon").performClick()
*
* composeTestRule.onNodeWithTag("validateDate").performClick()
*
* composeTestRule.onNodeWithTag("timeIcon").performClick()
*
* composeTestRule.onNodeWithTag("validateTime").performClick()
*
* composeTestRule.onNodeWithTag("addEventButton").assertIsDisplayed().performClick()
*
* verify(eventDocumentRef).set(any())
*
* verify(parkDocumentRef).update(eq("events"), any())
*/
composeTestRule.onNodeWithTag("createEventButton").assertIsDisplayed().performClick()

currentScreen = Screen.ADD_EVENT

composeTestRule.onNodeWithTag("addEventScreen").assertIsDisplayed()

composeTestRule.onNodeWithTag("titleTag").assertIsDisplayed().performTextClearance()

composeTestRule.onNodeWithTag("titleTag").performTextInput(event.title)

composeTestRule.onNodeWithTag("descriptionTag").assertIsDisplayed().performTextClearance()

composeTestRule.onNodeWithTag("descriptionTag").performTextInput(event.description)

composeTestRule.onNodeWithTag("dateIcon").performClick()

composeTestRule.onNodeWithTag("validateDate").performClick()

composeTestRule.onNodeWithTag("timeIcon").performClick()

composeTestRule.onNodeWithTag("validateTime").performClick()

composeTestRule.onNodeWithTag("addEventButton").assertIsDisplayed().performClick()

verify(eventDocumentRef).set(any())

verify(parkDocumentRef).update(eq("events"), any())

currentScreen = Screen.PARK_OVERVIEW

composeTestRule.waitUntil(5000) { composeTestRule.onNodeWithTag("eventButton").isDisplayed() }

composeTestRule.onNodeWithText(event.title).assertIsDisplayed()

composeTestRule.onNodeWithTag("eventButton").assertIsDisplayed().performClick()

currentScreen = Screen.EVENT_OVERVIEW

composeTestRule.waitForIdle()

// navigate to the event overview screen and verify that the event is properly displayed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ class EventRepositoryFirestore(private val db: FirebaseFirestore) : EventReposit

override suspend fun getEventByEid(eid: String): Event? {
require(eid.isNotEmpty())
Log.d("e2eCreateEvent", "getEventByEid: $eid")
return try {
val document = db.collection(COLLECTION_PATH).document(eid).get().await()
documentToEvent(document)
} catch (e: Exception) {
Log.e("e2eCreateEvent", "failed to getEventByEid: $e")
Log.e("FirestoreError", "Error getting event with ID: $eid. Reason: ${e.message}")
null
}
Expand All @@ -48,10 +50,13 @@ class EventRepositoryFirestore(private val db: FirebaseFirestore) : EventReposit
onSuccess: (List<Event>) -> Unit,
onFailure: (Exception) -> Unit
) {
Log.d("e2eCreateEvent", "getEvents: ${park.events}")
try {
val eventList = park.events.mapNotNull { getEventByEid(it) }
Log.d("e2eCreateEvent", "getEvents: ${eventList.first()}")
onSuccess(eventList)
} catch (e: Exception) {
Log.d("e2eCreateEvent", "failed to getEvents: $e")
onFailure(e)
Log.e("FirestoreError", "Error getting events: ${e.message}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ fun MapScreen(
true
},
onInfoWindowClick = {
Log.d("e2eCreateEvent", "Park: ${park.name}")
parkViewModel.setPark(park)
parkViewModel.setParkLocation(park.location)
navigationActions.navigateTo(Screen.PARK_OVERVIEW)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ fun ParkOverviewScreen(
// MVVM calls for park state :
val currentPark = parkViewModel.currentPark.collectAsState()

Log.d("e2eCreateEvent", "ParkOverviewScreen: currentPark=${currentPark.value}")

parkViewModel.park.collectAsState().value?.pid?.let { parkViewModel.loadCurrentPark(it) }

// MVVM calls for event state of the park :
Expand Down

0 comments on commit c55c06c

Please sign in to comment.