From 82493507c745dafe279ce3ea9cfe7439ba44d8eb Mon Sep 17 00:00:00 2001 From: Mai-LinhC Date: Fri, 3 May 2024 17:19:08 +0200 Subject: [PATCH 1/3] feat: see your role --- .../se/assocify/ui/screens/profile/ProfileScreen.kt | 2 +- .../assocify/ui/screens/profile/ProfileViewModel.kt | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/se/assocify/ui/screens/profile/ProfileScreen.kt b/app/src/main/java/com/github/se/assocify/ui/screens/profile/ProfileScreen.kt index 8fd75bc3a..bb7c66113 100644 --- a/app/src/main/java/com/github/se/assocify/ui/screens/profile/ProfileScreen.kt +++ b/app/src/main/java/com/github/se/assocify/ui/screens/profile/ProfileScreen.kt @@ -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")) } } diff --git a/app/src/main/java/com/github/se/assocify/ui/screens/profile/ProfileViewModel.kt b/app/src/main/java/com/github/se/assocify/ui/screens/profile/ProfileViewModel.kt index 7be11fb61..55238fc97 100644 --- a/app/src/main/java/com/github/se/assocify/ui/screens/profile/ProfileViewModel.kt +++ b/app/src/main/java/com/github/se/assocify/ui/screens/profile/ProfileViewModel.kt @@ -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 @@ -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) }, {}) } /** @@ -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) }, {}) } /** @@ -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) ) /** From 964fcc0091728537d85059fb9601551832646ea3 Mon Sep 17 00:00:00 2001 From: Mai-LinhC Date: Fri, 3 May 2024 17:22:54 +0200 Subject: [PATCH 2/3] feat: little test --- .../screens/profile/ProfileScreenTest.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/src/androidTest/java/com/github/se/assocify/screens/profile/ProfileScreenTest.kt b/app/src/androidTest/java/com/github/se/assocify/screens/profile/ProfileScreenTest.kt index e0f95321d..4b7721997 100644 --- a/app/src/androidTest/java/com/github/se/assocify/screens/profile/ProfileScreenTest.kt +++ b/app/src/androidTest/java/com/github/se/assocify/screens/profile/ProfileScreenTest.kt @@ -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 @@ -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 @@ -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 @@ -143,6 +152,7 @@ class ProfileScreenTest : TestCase(kaspressoBuilder = Kaspresso.Builder.withComp } } + // test if you can change association @Test fun changeAssociation() { with(composeTestRule) { @@ -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) { @@ -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) { From c259d5b4ac45cf0e83ce5877345a761dd3641ab6 Mon Sep 17 00:00:00 2001 From: Mai-LinhC Date: Fri, 3 May 2024 17:39:05 +0200 Subject: [PATCH 3/3] fix: epic --- .../androidTest/java/com/github/se/assocify/Epic1Test.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/androidTest/java/com/github/se/assocify/Epic1Test.kt b/app/src/androidTest/java/com/github/se/assocify/Epic1Test.kt index 4687478da..d03e5f39b 100644 --- a/app/src/androidTest/java/com/github/se/assocify/Epic1Test.kt +++ b/app/src/androidTest/java/com/github/se/assocify/Epic1Test.kt @@ -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 @@ -112,6 +114,12 @@ class Epic1Test : TestCase(kaspressoBuilder = Kaspresso.Builder.withComposeSuppo val onSuccessCallback = firstArg<(List) -> 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() { every { getEvents(any(), any()) } answers {} }