Skip to content

Commit

Permalink
test(association-manager): add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurelien9Code committed Dec 20, 2024
1 parent e3699ee commit 27ca2a6
Show file tree
Hide file tree
Showing 2 changed files with 266 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ package com.android.unio.end2end

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.isDisplayed
import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onFirst
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import androidx.compose.ui.test.performTextInput
import androidx.test.espresso.Espresso
import androidx.test.filters.LargeTest
import com.android.unio.R
import com.android.unio.assertDisplayComponentInScroll
import com.android.unio.model.association.PermissionType
import com.android.unio.model.strings.test_tags.association.AssociationProfileActionsTestTags
import com.android.unio.model.strings.test_tags.association.AssociationProfileTestTags
import com.android.unio.model.strings.test_tags.explore.ExploreTestTags
import com.android.unio.model.strings.test_tags.home.HomeTestTags
Expand Down Expand Up @@ -61,9 +69,247 @@ class AssociationProfileE2ETest : EndToEndTest() {

composeTestRule.onNodeWithTag(AssociationProfileTestTags.GO_BACK_BUTTON).performClick()

// had to go back mutliple times in order to sign out (because we need to be inside of one of
// the
// principal screens to sign out)
signOutWithUser(composeTestRule)
}

@Test
fun testUserWithoutAccessIsOnlyOnOverview() {
signInWithUser(composeTestRule, JohnDoe.EMAIL, JohnDoe.PASSWORD)

composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(HomeTestTags.SCREEN).isDisplayed()
}

composeTestRule.onNodeWithTag(BottomNavBarTestTags.EXPLORE).assertIsDisplayed()
composeTestRule.onNodeWithTag(BottomNavBarTestTags.EXPLORE).performClick()

composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(ExploreTestTags.EXPLORE_SCAFFOLD_TITLE).isDisplayed()
}

composeTestRule.onNodeWithText(ASSOCIATION_NAME).assertDisplayComponentInScroll()
composeTestRule.onNodeWithText(ASSOCIATION_NAME).performClick()

composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.SCREEN).isDisplayed()
}
Thread.sleep(1000)
composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.CONTACT_MEMBERS_TITLE).isDisplayed()
}
composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.GO_BACK_BUTTON).isDisplayed()
}

composeTestRule.onNodeWithTag(AssociationProfileTestTags.GO_BACK_BUTTON).performClick()

signOutWithUser(composeTestRule)
}

@Test
fun testUserWithAccessCreateRole() {
signInWithUser(composeTestRule, Admin.EMAIL, Admin.PASSWORD)

composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(HomeTestTags.SCREEN).isDisplayed()
}

composeTestRule.onNodeWithTag(BottomNavBarTestTags.EXPLORE).assertIsDisplayed()
composeTestRule.onNodeWithTag(BottomNavBarTestTags.EXPLORE).performClick()

composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(ExploreTestTags.EXPLORE_SCAFFOLD_TITLE).isDisplayed()
}

composeTestRule.onNodeWithText(ASSOCIATION_NAME).assertDisplayComponentInScroll()
composeTestRule.onNodeWithText(ASSOCIATION_NAME).performClick()

composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.SCREEN).isDisplayed()
}
Thread.sleep(1000)
composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.YOUR_ROLE_TEXT).isDisplayed()
}
composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.ACTIONS_PAGE).isDisplayed()
}
composeTestRule.onNodeWithTag(AssociationProfileTestTags.ACTIONS_PAGE).performClick()

composeTestRule.onNodeWithTag(AssociationProfileActionsTestTags.CREATE_ROLE).performScrollTo()
composeTestRule.onNodeWithTag(AssociationProfileActionsTestTags.CREATE_ROLE).performClick()

composeTestRule.waitUntil(40000) {
composeTestRule
.onNodeWithTag(AssociationProfileActionsTestTags.CREATE_ROLE_DISPLAY_NAME)
.isDisplayed()
}

// Enter role display name
val roleDisplayName = "Test Role"
composeTestRule
.onNodeWithTag(AssociationProfileActionsTestTags.CREATE_ROLE_DISPLAY_NAME)
.performTextInput(roleDisplayName)

// Pick a color using the color picker (assuming this involves some interaction like a tap)

// Select some permissions
composeTestRule
.onAllNodesWithText(PermissionType.values()[0].stringName)
.onFirst()
.performClick() // Select the first permission
composeTestRule
.onAllNodesWithText(PermissionType.values()[1].stringName)
.onFirst()
.performClick() // Select the second permission

// Confirm the role creation
composeTestRule
.onNodeWithText(
composeTestRule.activity.getString(
R.string.association_profile_save_role_dialog_create))
.performClick()

// Verify the role was created
composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithText(roleDisplayName).isDisplayed()
}

composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.OVERVIEW_PAGE).isDisplayed()
}
composeTestRule.onNodeWithTag(AssociationProfileTestTags.OVERVIEW_PAGE).performClick()

composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.GO_BACK_BUTTON).isDisplayed()
}

composeTestRule.onNodeWithTag(AssociationProfileTestTags.GO_BACK_BUTTON).performClick()

signOutWithUser(composeTestRule)
}

@Test
fun testUserWithAccessEditRole() {
signInWithUser(composeTestRule, Admin.EMAIL, Admin.PASSWORD)

composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(HomeTestTags.SCREEN).isDisplayed()
}

composeTestRule.onNodeWithTag(BottomNavBarTestTags.EXPLORE).assertIsDisplayed()
composeTestRule.onNodeWithTag(BottomNavBarTestTags.EXPLORE).performClick()

composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(ExploreTestTags.EXPLORE_SCAFFOLD_TITLE).isDisplayed()
}

composeTestRule.onNodeWithText(ASSOCIATION_NAME).assertDisplayComponentInScroll()
composeTestRule.onNodeWithText(ASSOCIATION_NAME).performClick()

composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.SCREEN).isDisplayed()
}
Thread.sleep(1000)
composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.YOUR_ROLE_TEXT).isDisplayed()
}
composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.ACTIONS_PAGE).isDisplayed()
}
composeTestRule.onNodeWithTag(AssociationProfileTestTags.ACTIONS_PAGE).performClick()

composeTestRule.onNodeWithTag(AssociationProfileActionsTestTags.EDIT_ROLE + "Test Role").performScrollTo()
composeTestRule.onNodeWithTag(AssociationProfileActionsTestTags.EDIT_ROLE + "Test Role").performClick()

composeTestRule.waitUntil(40000) {
composeTestRule
.onNodeWithTag(AssociationProfileActionsTestTags.CREATE_ROLE_DISPLAY_NAME)
.isDisplayed()
}

// Enter role display name
val roleDisplayName = "Edited Test Role"
composeTestRule
.onNodeWithTag(AssociationProfileActionsTestTags.CREATE_ROLE_DISPLAY_NAME)
.performTextInput("Edited ")

Espresso.closeSoftKeyboard()

// Confirm the role creation
composeTestRule
.onNodeWithText(
composeTestRule.activity.getString(
R.string.association_profile_save_role_dialog_save))
.performClick()



// Verify the role was created
composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithText(roleDisplayName).isDisplayed()
}

composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.OVERVIEW_PAGE).isDisplayed()
}
composeTestRule.onNodeWithTag(AssociationProfileTestTags.OVERVIEW_PAGE).performClick()

composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.GO_BACK_BUTTON).isDisplayed()
}

composeTestRule.onNodeWithTag(AssociationProfileTestTags.GO_BACK_BUTTON).performClick()

signOutWithUser(composeTestRule)
}

@Test
fun testUserWithAccessDeleteRole() {
signInWithUser(composeTestRule, Admin.EMAIL, Admin.PASSWORD)

composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(HomeTestTags.SCREEN).isDisplayed()
}

composeTestRule.onNodeWithTag(BottomNavBarTestTags.EXPLORE).assertIsDisplayed()
composeTestRule.onNodeWithTag(BottomNavBarTestTags.EXPLORE).performClick()

composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(ExploreTestTags.EXPLORE_SCAFFOLD_TITLE).isDisplayed()
}

composeTestRule.onNodeWithText(ASSOCIATION_NAME).assertDisplayComponentInScroll()
composeTestRule.onNodeWithText(ASSOCIATION_NAME).performClick()

composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.SCREEN).isDisplayed()
}
Thread.sleep(1000)
composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.YOUR_ROLE_TEXT).isDisplayed()
}
composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.ACTIONS_PAGE).isDisplayed()
}
composeTestRule.onNodeWithTag(AssociationProfileTestTags.ACTIONS_PAGE).performClick()

composeTestRule.onNodeWithTag(AssociationProfileActionsTestTags.DELETE_ROLE + "Edited Test Role").performScrollTo()
composeTestRule.onNodeWithTag(AssociationProfileActionsTestTags.DELETE_ROLE + "Edited Test Role").performClick()



composeTestRule.waitUntil(50000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.OVERVIEW_PAGE).isDisplayed()
}
composeTestRule.onNodeWithTag(AssociationProfileTestTags.OVERVIEW_PAGE).performClick()

composeTestRule.waitUntil(10000) {
composeTestRule.onNodeWithTag(AssociationProfileTestTags.GO_BACK_BUTTON).isDisplayed()
}

composeTestRule.onNodeWithTag(AssociationProfileTestTags.GO_BACK_BUTTON).performClick()

signOutWithUser(composeTestRule)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ import com.android.unio.model.strings.test_tags.association.AssociationProfileTe
import com.android.unio.model.user.User
import com.android.unio.model.user.UserViewModel
import com.android.unio.model.utils.NetworkUtils
import com.android.unio.ui.components.EventSearchBar
import com.android.unio.ui.components.MemberSearchBar
import com.android.unio.ui.components.NotificationSender
import com.android.unio.ui.components.RoleBadge
import com.android.unio.ui.components.SearchPagerSection
Expand Down Expand Up @@ -239,7 +237,9 @@ fun AssociationProfileScaffold(
" " +
userRole.displayName,
color = Color.White,
modifier = Modifier.align(Alignment.Center))
modifier =
Modifier.align(Alignment.Center)
.testTag(AssociationProfileTestTags.YOUR_ROLE_TEXT))
}

Box(modifier = Modifier.fillMaxSize().padding(top = 50.dp)) {
Expand Down Expand Up @@ -642,23 +642,6 @@ private fun AssociationActionsMembers(
val pagerState = rememberPagerState(initialPage = 0) { members?.size ?: 0 }
val coroutineScope = rememberCoroutineScope()

val searchBar: @Composable () -> Unit = {
association?.let {
MemberSearchBar(
searchViewModel = searchViewModel,
associationUid = it.uid,
userUid = userUid,
onMemberSelected = { selectedMember ->
val targetPage = members?.indexOfFirst { it.uid == selectedMember.uid }
if (targetPage != null && targetPage >= 0) {
coroutineScope.launch { pagerState.animateScrollToPage(targetPage) }
}
},
shouldCloseExpandable = false,
onOutsideClickHandled = {})
}
}

val cardContent: @Composable (Member) -> Unit = { member ->
val user by associationViewModel.getUserFromMember(member).collectAsState()
Box(
Expand Down Expand Up @@ -711,7 +694,6 @@ private fun AssociationActionsMembers(
SearchPagerSection(
items = members,
cardContent = { cardContent(it) },
searchBar = searchBar,
pagerState = pagerState)

association?.let {
Expand All @@ -733,6 +715,8 @@ private fun AssociationActionsMembers(
fun RolesManagementScreen(roles: List<Role>, associationViewModel: AssociationViewModel) {
var showCreateRoleDialog by remember { mutableStateOf(false) }

val context = LocalContext.current

Column(Modifier.fillMaxSize().padding(16.dp)) {
Text(text = "Roles", style = MaterialTheme.typography.headlineMedium)

Expand All @@ -742,7 +726,11 @@ fun RolesManagementScreen(roles: List<Role>, associationViewModel: AssociationVi

Spacer(modifier = Modifier.height(16.dp))

Button(onClick = { showCreateRoleDialog = true }) { Text(text = "Create New Role") }
Button(
onClick = { showCreateRoleDialog = true },
modifier = Modifier.testTag(AssociationProfileActionsTestTags.CREATE_ROLE)) {
Text(text = context.getString(R.string.association_profile_create_role))
}

// Show dialog for creating a new role
if (showCreateRoleDialog) {
Expand Down Expand Up @@ -790,14 +778,14 @@ fun RoleCard(role: Role, associationViewModel: AssociationViewModel) {
imageVector = Icons.Default.Edit,
contentDescription =
context.getString(R.string.association_profile_role_card_edit_role),
modifier = Modifier.size(24.dp).clickable { showEditDialog = true }.padding(4.dp))
modifier = Modifier.size(24.dp).clickable { showEditDialog = true }.padding(4.dp).testTag(AssociationProfileActionsTestTags.EDIT_ROLE + role.displayName))

Icon(
imageVector = Icons.Default.Delete,
contentDescription =
context.getString(R.string.association_profile_role_card_delete_role),
modifier =
Modifier.size(24.dp).clickable { showDeleteDialog = true }.padding(4.dp))
Modifier.size(24.dp).clickable { showDeleteDialog = true }.padding(4.dp).testTag(AssociationProfileActionsTestTags.DELETE_ROLE + role.displayName))
}
}

Expand Down Expand Up @@ -948,7 +936,11 @@ fun SaveRoleDialog(
BasicTextField(
value = displayName,
onValueChange = { displayName = it },
modifier = Modifier.fillMaxWidth().background(Color.LightGray).padding(8.dp))
modifier =
Modifier.fillMaxWidth()
.background(Color.LightGray)
.padding(8.dp)
.testTag(AssociationProfileActionsTestTags.CREATE_ROLE_DISPLAY_NAME))
}

Column(Modifier.fillMaxWidth().padding(vertical = 16.dp)) {
Expand Down Expand Up @@ -1133,18 +1125,6 @@ private fun AssociationActionsEvents(
eventViewModel = eventViewModel,
shouldBeEditable = hasAddEventsPermission)
},
searchBar = {
EventSearchBar(
searchViewModel = searchViewModel,
onEventSelected = { selectedEvent ->
val targetPage = sortedEvents.indexOfFirst { it.uid == selectedEvent.uid }
if (targetPage >= 0) {
coroutineScope.launch { pagerState.animateScrollToPage(targetPage) }
}
},
shouldCloseExpandable = false,
onOutsideClickHandled = {})
},
pagerState = pagerState)
}
}
Expand Down

0 comments on commit 27ca2a6

Please sign in to comment.