From 9b5e5617a1a06e3a68422077a1cf0c8c8de7b1c0 Mon Sep 17 00:00:00 2001 From: Martin Felber Date: Sat, 21 Dec 2024 12:07:50 +0100 Subject: [PATCH] Cleaned up tests; default all post actions rights to false --- .../metis/conversation/BaseChatUITest.kt | 10 +- .../ui/post/ConversationBottomSheetUiTest.kt | 109 ++++++++++++------ 2 files changed, 77 insertions(+), 42 deletions(-) diff --git a/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/BaseChatUITest.kt b/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/BaseChatUITest.kt index fb0967466..eb8b3d39b 100644 --- a/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/BaseChatUITest.kt +++ b/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/BaseChatUITest.kt @@ -82,9 +82,9 @@ abstract class BaseChatUITest : BaseComposeTest() { post: IStandalonePost, onResolvePost: ((IBasePost) -> Deferred)? = { CompletableDeferred() }, onPinPost: ((IBasePost) -> Deferred)? = { CompletableDeferred() }, - isAbleToPin: Boolean = true, + isAbleToPin: Boolean = false, isAtLeastTutorInCourse: Boolean = false, - hasModerationRights: Boolean = true, + hasModerationRights: Boolean = false, ) { composeTestRule.setContent { MetisThreadUi( @@ -118,6 +118,8 @@ abstract class BaseChatUITest : BaseComposeTest() { fun setupChatUi( posts: List, currentUser: User = User(id = clientId), + isAbleToPin: Boolean = false, + isAtLeastTutorInCourse: Boolean = false, hasModerationRights: Boolean = false, onPinPost: (IStandalonePost) -> Deferred = { CompletableDeferred() } ) { @@ -129,8 +131,8 @@ abstract class BaseChatUITest : BaseComposeTest() { posts = PostsDataState.Loaded.WithList(list, PostsDataState.NotLoading), clientId = currentUser.id, postActionFlags = PostActionFlags( - isAbleToPin = true, - isAtLeastTutorInCourse = false, + isAbleToPin = isAbleToPin, + isAtLeastTutorInCourse = isAtLeastTutorInCourse, hasModerationRights = hasModerationRights, ), listContentPadding = PaddingValues(), diff --git a/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/ui/post/ConversationBottomSheetUiTest.kt b/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/ui/post/ConversationBottomSheetUiTest.kt index f3ec11891..be84d472e 100644 --- a/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/ui/post/ConversationBottomSheetUiTest.kt +++ b/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/ui/post/ConversationBottomSheetUiTest.kt @@ -28,15 +28,12 @@ class ConversationBottomSheetUiTest : BaseChatUITest() { private val postContent = "Post content" private val answerContent = "Answer content" + // ###################################### EDIT ########################################### + @Test fun `test GIVEN a post WHEN long pressing the post THEN Edit action is shown`() { setupChatUi( - posts = listOf(StandalonePost( - id = 1, - author = currentUser, - content = postContent, - )), - currentUser = currentUser + posts = listOf(simplePost(currentUser)), ) composeTestRule.assertPostActionVisibility(R.string.post_edit, isVisible = true) @@ -44,29 +41,22 @@ class ConversationBottomSheetUiTest : BaseChatUITest() { @Test - fun `test GIVEN a user with moderation-rights WHEN long pressing the post THEN Edit action is not shown`() { + fun `test GIVEN a user with moderation-rights WHEN long pressing the other's post THEN Edit action is not shown`() { setupChatUi( - posts = listOf(StandalonePost( - id = 1, - author = otherUser, - content = postContent, - )), - currentUser = currentUser, + posts = listOf(simplePost(otherUser)), hasModerationRights = true ) composeTestRule.assertPostActionVisibility(R.string.post_edit, isVisible = false) } + + // ###################################### DELETE ########################################### + @Test - fun `test GIVEN a user with moderation-rights WHEN long pressing the post THEN delete option is shown`() { + fun `test GIVEN a user with moderation-rights WHEN long pressing other's post THEN delete option is shown`() { setupChatUi( - posts = listOf(StandalonePost( - id = 1, - author = otherUser, - content = postContent, - )), - currentUser = currentUser, + posts = listOf(simplePost(otherUser)), hasModerationRights = true ) @@ -76,31 +66,24 @@ class ConversationBottomSheetUiTest : BaseChatUITest() { @Test fun `test GIVEN a post WHEN long pressing the post as the post author THEN delete option is shown`() { setupChatUi( - posts = listOf(StandalonePost( - id = 1, - author = currentUser, - content = postContent, - )), - currentUser = currentUser + posts = listOf(simplePost(currentUser)), ) composeTestRule.assertPostActionVisibility(R.string.post_delete, isVisible = true) } @Test - fun `test GIVEN a post WHEN long pressing the post as non-moderator THEN delete option is not shown`() { + fun `test GIVEN a post WHEN long pressing the other's post as non-moderator THEN delete option is not shown`() { setupChatUi( - posts = listOf(StandalonePost( - id = 1, - author = otherUser, - content = postContent, - )), - currentUser = currentUser + posts = listOf(simplePost(otherUser)), ) composeTestRule.assertPostActionVisibility(R.string.post_delete, isVisible = false) } + + // ###################################### RESOLVE ########################################### + @Test fun `test GIVEN a basePost from user WHEN long pressing on another user's answer THEN resolve option is shown`() { setupThreadUi( @@ -150,15 +133,65 @@ class ConversationBottomSheetUiTest : BaseChatUITest() { ) } + + // ###################################### PIN ########################################### + + @Test + fun `test GIVEN other's post WHEN long pressing with pin rights THEN pin option is shown`() { + setupChatUi( + posts = listOf(StandalonePost( + id = 1, + author = otherUser, + content = postContent, + )), + isAbleToPin = true + ) + + composeTestRule.assertPostActionVisibility(R.string.post_pin, isVisible = true) + } + + @Test + fun `test GIVEN a post WHEN long pressing without pin rights THEN pin option is not shown`() { + setupChatUi( + posts = listOf(simplePost(otherUser)), + ) + + composeTestRule.assertPostActionVisibility(R.string.post_pin, isVisible = false) + } + + @Test + fun `test GIVEN a answer to a post WHEN long pressing the answer with pin abilities THEN pin option is not shown`() { + setupThreadUi( + post = simpleThreadPostWithAnswer( + postAuthor = currentUser, + answerAuthor = currentUser + ), + isAbleToPin = true + ) + + composeTestRule.assertPostActionVisibility( + R.string.post_pin, + isVisible = false, + postContentToClick = answerContent + ) + } + + + // ###################################### UTIL METHODS ########################################### + + private fun simplePost( + postAuthor: User, + ): StandalonePost = StandalonePost( + id = 1, + author = postAuthor, + content = postContent, + ) + private fun simpleThreadPostWithAnswer( postAuthor: User, answerAuthor: User, ): StandalonePost { - val basePost = StandalonePost( - id = 1, - author = postAuthor, - content = postContent, - ) + val basePost = simplePost(postAuthor) val answerPost = AnswerPost( id = 2, author = answerAuthor,