Skip to content

Commit

Permalink
test: adapted tests for location query
Browse files Browse the repository at this point in the history
Adapted test for location query in edit activity screen
  • Loading branch information
appellet committed Dec 12, 2024
1 parent aadeefe commit 09dddd6
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import androidx.compose.ui.test.performTextInput
import com.github.se.travelpouch.model.activity.Activity
import com.github.se.travelpouch.model.activity.ActivityRepository
import com.github.se.travelpouch.model.activity.ActivityViewModel
import com.github.se.travelpouch.model.location.LocationRepository
import com.github.se.travelpouch.model.location.LocationViewModel
import com.github.se.travelpouch.model.travels.Location
import com.github.se.travelpouch.ui.navigation.NavigationActions
import com.google.firebase.Timestamp
Expand All @@ -29,6 +31,8 @@ class EditActivityScreenTest {
private lateinit var mockActivityRepositoryFirebase: ActivityRepository
private lateinit var mockActivityModelView: ActivityViewModel
private lateinit var navigationActions: NavigationActions
private lateinit var locationViewModel: LocationViewModel
private lateinit var locationRepository: LocationRepository

val activity =
Activity(
Expand All @@ -46,14 +50,16 @@ class EditActivityScreenTest {
navigationActions = mock(NavigationActions::class.java)
mockActivityRepositoryFirebase = mock(ActivityRepository::class.java)
mockActivityModelView = ActivityViewModel(mockActivityRepositoryFirebase)
locationRepository = mock(LocationRepository::class.java)
locationViewModel = LocationViewModel(locationRepository)

`when`(mockActivityModelView.getNewUid()).thenReturn("uid")
mockActivityModelView.selectActivity(activity)
}

@Test
fun everythingIsDisplayed() {
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView) }
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView, locationViewModel) }

composeTestRule.onNodeWithTag("EditActivityScreen").isDisplayed()
composeTestRule.onNodeWithTag("titleField").isDisplayed()
Expand All @@ -75,22 +81,22 @@ class EditActivityScreenTest {
composeTestRule.onNodeWithTag("descriptionField").fetchSemanticsNode().config[EditableText]
assert(result.text == activity.description)
result =
composeTestRule.onNodeWithTag("locationField").fetchSemanticsNode().config[EditableText]
assert(result.text == "location")
composeTestRule.onNodeWithTag("inputTravelLocation").fetchSemanticsNode().config[EditableText]
assert(result.text == activity.location.name)
result = composeTestRule.onNodeWithTag("dateField").fetchSemanticsNode().config[EditableText]
assert(result.text == "01/01/1970")
}

@Test
fun deletesCallsDeleteById() {
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView) }
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView, locationViewModel) }
composeTestRule.onNodeWithTag("deleteButton").performClick()
verify(mockActivityRepositoryFirebase).deleteActivityById(anyOrNull(), anyOrNull(), anyOrNull())
}

@Test
fun verifiesDisplayWorksAndModificationPlusSaving() {
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView) }
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView,locationViewModel) }

VerifyFieldsAreCorrect(composeTestRule)

Expand All @@ -108,7 +114,7 @@ class EditActivityScreenTest {
composeTestRule.onNodeWithTag("descriptionField").fetchSemanticsNode().config[EditableText]
assert(result.text == "newDescription")
result =
composeTestRule.onNodeWithTag("locationField").fetchSemanticsNode().config[EditableText]
composeTestRule.onNodeWithTag("inputTravelLocation").fetchSemanticsNode().config[EditableText]
assert(result.text == "location")
result = composeTestRule.onNodeWithTag("dateField").fetchSemanticsNode().config[EditableText]
assert(result.text == "23/06/2025")
Expand All @@ -119,7 +125,7 @@ class EditActivityScreenTest {

@Test
fun dateFormattingWorksCorrectly() {
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView) }
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView, locationViewModel) }
composeTestRule.onNodeWithTag("dateField").performTextClearance()
composeTestRule.onNodeWithTag("dateField").performTextInput("00000000")
val result =
Expand All @@ -129,7 +135,7 @@ class EditActivityScreenTest {

@Test
fun savesWhenFieldsAreCorrect() {
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView) }
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView, locationViewModel) }
VerifyFieldsAreCorrect(composeTestRule)
composeTestRule.onNodeWithTag("dateField").performTextClearance()
composeTestRule.onNodeWithTag("dateField").performTextInput("23122024")
Expand All @@ -140,7 +146,7 @@ class EditActivityScreenTest {

@Test
fun doesNotSaveWhenDateIsWrong() {
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView) }
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView, locationViewModel) }
VerifyFieldsAreCorrect(composeTestRule)
composeTestRule.onNodeWithTag("dateField").performTextClearance()
composeTestRule.onNodeWithTag("dateField").performTextInput("00000000")
Expand All @@ -152,7 +158,7 @@ class EditActivityScreenTest {

@Test
fun noCharacterAllowedInDateField() {
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView) }
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView, locationViewModel) }
composeTestRule.onNodeWithTag("dateField").performTextClearance()
composeTestRule.onNodeWithTag("dateField").performTextInput("mdkdk")
var result =
Expand All @@ -170,7 +176,7 @@ class EditActivityScreenTest {

@Test
fun limitOfEightCharactersInDateField() {
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView) }
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView, locationViewModel) }
composeTestRule.onNodeWithTag("dateField").performTextClearance()
composeTestRule.onNodeWithTag("dateField").performTextInput("01234567")
composeTestRule.onNodeWithTag("dateField").performTextInput("8")
Expand All @@ -181,7 +187,7 @@ class EditActivityScreenTest {

@Test
fun datePickerDialogOpensOnClick() {
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView) }
composeTestRule.setContent { EditActivity(navigationActions, mockActivityModelView, locationViewModel) }

// The date field should be displayed
composeTestRule.onNodeWithTag("datePickerButton").assertIsDisplayed()
Expand Down

0 comments on commit 09dddd6

Please sign in to comment.