Skip to content

Commit

Permalink
Merge pull request #231 from Assocify-Team/mc/217
Browse files Browse the repository at this point in the history
Viewmodel see role in profile
  • Loading branch information
Mai-LinhC authored May 3, 2024
2 parents bc190f1 + c259d5b commit d02b57e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
8 changes: 8 additions & 0 deletions app/src/androidTest/java/com/github/se/assocify/Epic1Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import com.github.se.assocify.model.database.EventAPI
import com.github.se.assocify.model.database.TaskAPI
import com.github.se.assocify.model.database.UserAPI
import com.github.se.assocify.model.entities.Association
import com.github.se.assocify.model.entities.PermissionRole
import com.github.se.assocify.model.entities.RoleType
import com.github.se.assocify.model.entities.User
import com.github.se.assocify.model.localsave.LoginSave
import com.github.se.assocify.navigation.Destination
Expand Down Expand Up @@ -112,6 +114,12 @@ class Epic1Test : TestCase(kaspressoBuilder = Kaspresso.Builder.withComposeSuppo
val onSuccessCallback = firstArg<(List<Association>) -> Unit>()
onSuccessCallback.invoke(listOf(asso))
}

every { getCurrentUserRole(any(), any()) } answers
{
val onSuccessCallback = firstArg<(PermissionRole) -> Unit>()
onSuccessCallback.invoke(PermissionRole("1", "aaa", RoleType.PRESIDENCY))
}
}

private val eventAPI = mockk<EventAPI>() { every { getEvents(any(), any()) } answers {} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertIsDisplayed
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.performScrollTo
import androidx.compose.ui.test.performTextClearance
Expand All @@ -14,6 +15,8 @@ import com.github.se.assocify.model.CurrentUser
import com.github.se.assocify.model.database.AssociationAPI
import com.github.se.assocify.model.database.UserAPI
import com.github.se.assocify.model.entities.Association
import com.github.se.assocify.model.entities.PermissionRole
import com.github.se.assocify.model.entities.RoleType
import com.github.se.assocify.model.entities.User
import com.github.se.assocify.navigation.Destination
import com.github.se.assocify.navigation.NavigationActions
Expand Down Expand Up @@ -72,6 +75,12 @@ class ProfileScreenTest : TestCase(kaspressoBuilder = Kaspresso.Builder.withComp
onSuccessCallback(listOf(asso1, asso2))
}
every { setDisplayName(any(), "newName", any(), any()) } answers {}

every { getCurrentUserRole(any(), any()) } answers
{
val onSuccessCallback = firstArg<(PermissionRole) -> Unit>()
onSuccessCallback(PermissionRole("1", "asso", RoleType.PRESIDENCY))
}
}

private lateinit var mViewmodel: ProfileViewModel
Expand Down Expand Up @@ -143,6 +152,7 @@ class ProfileScreenTest : TestCase(kaspressoBuilder = Kaspresso.Builder.withComp
}
}

// test if you can change association
@Test
fun changeAssociation() {
with(composeTestRule) {
Expand All @@ -153,6 +163,16 @@ class ProfileScreenTest : TestCase(kaspressoBuilder = Kaspresso.Builder.withComp
}
}

// test if correct role is displayed
@Test
fun correctRole() {
with(composeTestRule) {
onNodeWithTag("profileRole").assertIsDisplayed()
onNodeWithText("PRESIDENCY").assertIsDisplayed()
}
}

// test if you can navigate to sub screens (settings)
@Test
fun navigateToSubScreen() {
with(composeTestRule) {
Expand All @@ -173,6 +193,7 @@ class ProfileScreenTest : TestCase(kaspressoBuilder = Kaspresso.Builder.withComp
}
}

// test if you can navigate in the main tabs
@Test
fun navigate() {
with(composeTestRule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ fun ProfileScreen(navActions: NavigationActions, viewmodel: ProfileViewModel) {
}
}

Text("Role", modifier = Modifier.testTag("profileRole"))
Text(state.currentRole.type.name, modifier = Modifier.testTag("profileRole"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import com.github.se.assocify.model.CurrentUser
import com.github.se.assocify.model.database.AssociationAPI
import com.github.se.assocify.model.database.UserAPI
import com.github.se.assocify.model.entities.Association
import com.github.se.assocify.model.entities.PermissionRole
import com.github.se.assocify.model.entities.RoleType
import com.github.se.assocify.navigation.Destination
import com.github.se.assocify.navigation.NavigationActions
import java.time.LocalDate
Expand Down Expand Up @@ -59,6 +61,8 @@ class ProfileViewModel(
_uiState.value =
_uiState.value.copy(selectedAssociation = _uiState.value.myAssociations[0])
})
userAPI.getCurrentUserRole(
{ role -> _uiState.value = _uiState.value.copy(currentRole = role) }, {})
}

/**
Expand Down Expand Up @@ -96,6 +100,8 @@ class ProfileViewModel(
fun setAssociation(association: Association) {
CurrentUser.associationUid = association.uid
_uiState.value = _uiState.value.copy(selectedAssociation = association)
userAPI.getCurrentUserRole(
{ role -> _uiState.value = _uiState.value.copy(currentRole = role) }, {})
}

/**
Expand Down Expand Up @@ -173,7 +179,10 @@ data class ProfileUIState(
// true if the association dropdown should be shown, false if should be hidden
val openAssociationDropdown: Boolean = false,
// the selected (current) association - TODO idk what to do with the temporary association
val selectedAssociation: Association = Association("none", "", "none", LocalDate.now())
val selectedAssociation: Association = Association("none", "", "none", LocalDate.now()),
// current role of the user in the association
val currentRole: PermissionRole =
PermissionRole(CurrentUser.userUid!!, CurrentUser.associationUid!!, RoleType.MEMBER)
)

/**
Expand Down

0 comments on commit d02b57e

Please sign in to comment.