Skip to content

Commit

Permalink
Cleaned up tests; default all post actions rights to false
Browse files Browse the repository at this point in the history
  • Loading branch information
FelberMartin committed Dec 21, 2024
1 parent bba5065 commit 9b5e561
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ abstract class BaseChatUITest : BaseComposeTest() {
post: IStandalonePost,
onResolvePost: ((IBasePost) -> Deferred<MetisModificationFailure>)? = { CompletableDeferred() },
onPinPost: ((IBasePost) -> Deferred<MetisModificationFailure>)? = { CompletableDeferred() },
isAbleToPin: Boolean = true,
isAbleToPin: Boolean = false,
isAtLeastTutorInCourse: Boolean = false,
hasModerationRights: Boolean = true,
hasModerationRights: Boolean = false,
) {
composeTestRule.setContent {
MetisThreadUi(
Expand Down Expand Up @@ -118,6 +118,8 @@ abstract class BaseChatUITest : BaseComposeTest() {
fun setupChatUi(
posts: List<IStandalonePost>,
currentUser: User = User(id = clientId),
isAbleToPin: Boolean = false,
isAtLeastTutorInCourse: Boolean = false,
hasModerationRights: Boolean = false,
onPinPost: (IStandalonePost) -> Deferred<MetisModificationFailure> = { CompletableDeferred() }
) {
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,45 +28,35 @@ 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)
}


@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
)

Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9b5e561

Please sign in to comment.