Skip to content

Commit

Permalink
Add friends to travel (#249)
Browse files Browse the repository at this point in the history
* feat(friend): Add UI to add friend to a travel

Add UI implementation to add a friend to a travel.

* feat(friend): Add friend to travel logic

Add friend to travel logic.

* test(friend): Add UI test to pass coverage

Add UI test with the add friend entries.
Add an extra test for add friend notification.

* fix(friend): Fix compilation error and dismissal

Fix compilation error due to merge.
Fix dismissal once a friend was invited to the travel.

* feat(friend): Add toast to give user feedback

Add toast to give user a feedback when adding a friend to a travel.

* chore(friend): Fix some stylistic issues and test.

Fix by removing triple dots and renaming test values to something
more boring.

* test(friend): Fix test ParticipantListScreen

Fix ParticipantListScreen test due to merge conflicts.

---------

Co-authored-by: Stefan <[email protected]>
  • Loading branch information
RemIsMyWaifuu and StefanPetersTM authored Dec 11, 2024
1 parent 1b46017 commit 95188cb
Show file tree
Hide file tree
Showing 2 changed files with 307 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.Mockito.doAnswer
import org.mockito.Mockito.doThrow
import org.mockito.Mockito.mock
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when`
Expand Down Expand Up @@ -608,7 +609,6 @@ class ParticipantListScreenTest {
.updateTravel(any(), any(), anyOrNull(), any(), any(), anyOrNull())
composeTestRule.onNodeWithTag("addUserButton").performClick()
verify(profileRepository).getFsUidByEmail(anyOrNull(), anyOrNull(), anyOrNull())
// verify(notificationRepository, never()).addNotification(anyOrNull())
}

@Test
Expand Down Expand Up @@ -669,7 +669,111 @@ class ParticipantListScreenTest {
.updateTravel(any(), any(), anyOrNull(), any(), any(), anyOrNull())
composeTestRule.onNodeWithTag("addUserButton").performClick()
verify(profileRepository).getFsUidByEmail(anyOrNull(), anyOrNull(), anyOrNull())
verify(notificationRepository).addNotification(anyOrNull())

// throw impossible exception
doAnswer { invocation ->
val email = invocation.getArgument<String>(0)
val onSuccess = invocation.getArgument<(fsUid?) -> Unit>(1)
val customUserInfo =
Profile(
fsUid = "qwertzuiopasdfghjklyxcvbnm12",
name = "Custom User",
userTravelList = listOf("00000000000000000000"),
email = email,
username = "username",
friends = emptyMap())
// Call the onSuccess callback with the custom UserInfo

onSuccess(customUserInfo.fsUid)
}
.`when`(profileRepository)
.getFsUidByEmail(any(), any(), any())
doAnswer { "abcdefghijklmnopqrst" }.`when`(notificationRepository).getNewUid()
doNothing().`when`(travelRepository).updateTravel(any(), any(), anyOrNull(), any(), any(),
anyOrNull())
doThrow(RuntimeException("Impossible Exception"))
.`when`(notificationRepository)
.addNotification(anyOrNull())
composeTestRule.onNodeWithTag("addUserFab").performClick()
val randomEmail2 = "[email protected]"
composeTestRule.onNodeWithTag("addUserEmailField").performScrollTo()
composeTestRule.onNodeWithTag("addUserEmailField").assertIsDisplayed().assertTextContains("")
composeTestRule.onNodeWithTag("addUserEmailField").performTextClearance()
composeTestRule.onNodeWithTag("addUserEmailField").performTextInput(randomEmail2)
composeTestRule.onNodeWithTag("addUserButton").performClick()
composeTestRule.waitForIdle()
}

@Test
fun addFriendMenuWithNoFriends() {
val travelContainer = createContainer()
listTravelViewModel.selectTravel(travelContainer)
composeTestRule.setContent {
ParticipantListScreen(
listTravelViewModel, navigationActions, notificationViewModel, profileModelView, eventViewModel)
}
composeTestRule.onNodeWithTag("addUserFab").performClick()
composeTestRule.onNodeWithTag("addViaFriendListButton").performClick()
composeTestRule.waitForIdle()
composeTestRule.onNodeWithTag("friendListDialogBox", useUnmergedTree = true).assertIsDisplayed()
composeTestRule
.onNodeWithTag("friendListDialogTitle", useUnmergedTree = true)
.assertTextContains("Select a Friend")
composeTestRule
.onNodeWithTag("noFriendsDialogText", useUnmergedTree = true)
.assertTextContains("No friends to choose from")
}

@Test
fun addFriendMenuWithFriend() {
val travelContainer = createContainer()
listTravelViewModel.selectTravel(travelContainer)

`when`(profileRepository.getProfileElements(anyOrNull(), anyOrNull())).then {
it.getArgument<(Profile) -> Unit>(0)(
Profile(
fsUid = "abcdefghijklmnopqrstuvwxyz13",
name = "Custom User",
userTravelList = listOf("00000000000000000000"),
email = "[email protected]",
username = "username",
friends = mapOf("[email protected]" to "abcdefghijklmnopqrstuvwxyz12")))
}
profileModelView.getProfile()

composeTestRule.setContent {
ParticipantListScreen(
listTravelViewModel, navigationActions, notificationViewModel, profileModelView, eventViewModel)
}
composeTestRule.onNodeWithTag("addUserFab").performClick()
composeTestRule.onNodeWithTag("addViaFriendListButton").performClick()
composeTestRule.onNodeWithTag("friendListDialogBox", useUnmergedTree = true).assertIsDisplayed()
composeTestRule
.onNodeWithTag("friendListDialogTitle", useUnmergedTree = true)
.assertTextContains("Select a Friend")
doAnswer { invocation ->
val email = invocation.getArgument<String>(0)
val onSuccess = invocation.getArgument<(fsUid?) -> Unit>(1)
val customUserInfo =
Profile(
fsUid = "qwertzuiopasdfghjklyxcvbnm12",
name = "Custom User",
userTravelList = listOf("00000000000000000000"),
email = email,
username = "username",
friends = emptyMap())
// Call the onSuccess callback with the custom UserInfo

onSuccess(customUserInfo.fsUid)
}
.`when`(profileRepository)
.getFsUidByEmail(any(), any(), any())
doAnswer { "abcdefghijklmnopqrst" }.`when`(notificationRepository).getNewUid()
doNothing().`when`(travelRepository).updateTravel(any(), any(), anyOrNull(), any(), any(), anyOrNull())
composeTestRule.onNodeWithTag("friendCard").assertIsDisplayed()
composeTestRule.onNodeWithTag("friendCard").assertTextContains("[email protected]")
composeTestRule.onNodeWithTag("friendCard").performClick()
verify(notificationRepository).addNotification(anyOrNull())
}

Expand Down
Loading

0 comments on commit 95188cb

Please sign in to comment.