feat(creator): 커뮤니티 구매와 메뉴 동작을 정리한다

This commit is contained in:
2026-08-11 00:10:46 +09:00
parent 02cd583f56
commit 8b8b384b29
31 changed files with 1055 additions and 410 deletions
@@ -44,13 +44,4 @@ class CommunityChangeTest {
assertEquals(List(CommunityActivityResultSource.entries.size) { CommunityChange.Ignored }, changes)
}
@Test
fun `삭제와 고정 변경은 post ID를 가진 명시적 변경으로 표현한다`() {
val deleted = CommunityChange.Deleted(postId = 31L)
val pinChanged = CommunityChange.PinChanged(postId = 32L)
assertEquals(31L, deleted.postId)
assertEquals(32L, pinChanged.postId)
}
}
@@ -119,6 +119,164 @@ class CreatorChannelActivitySourceTest {
assertTrue(source.contains("private fun handleCommunityChange(change: CommunityChange)"))
}
@Test
fun `홈과 커뮤니티 list 더보기는 동일 menu item을 Activity Host까지 전달한다`() {
val adapter = projectFile(
"app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/ui/CreatorChannelHomeSectionAdapter.kt"
).readText()
val homeFragment = projectFile(
"app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/CreatorChannelHomeFragment.kt"
).readText()
val communityFragment = projectFile(
"app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/community/CreatorChannelCommunityFragment.kt"
).readText()
val activity = projectFile(
"app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/CreatorChannelActivity.kt"
).readText()
assertTrue(
adapter.contains("private val onCommunityMoreClick: (CreatorChannelCommunityMenuItem) -> Unit = {}")
)
assertTrue(adapter.contains("currentUserId = item.currentMemberId"))
assertTrue(adapter.contains("showMore = menuItem.showMore"))
assertTrue(adapter.contains("setOnMoreClick { onCommunityMoreClick(menuItem) }"))
assertTrue(adapter.contains("row.setOnClickListener { onCommunityClick(community.postId) }"))
assertTrue(homeFragment.contains("onCommunityMoreClick = ::onCommunityMoreClicked"))
assertTrue(homeFragment.contains("host.onCreatorChannelCommunityMoreClicked(item)"))
assertTrue(
homeFragment.contains("fun onCreatorChannelCommunityMoreClicked(item: CreatorChannelCommunityMenuItem)")
)
assertTrue(communityFragment.contains("host.onCreatorChannelCommunityMoreClicked(item)"))
assertTrue(
communityFragment.contains("fun onCreatorChannelCommunityMoreClicked(item: CreatorChannelCommunityMenuItem)")
)
assertTrue(
activity.contains(
"override fun onCreatorChannelCommunityMoreClicked(item: CreatorChannelCommunityMenuItem)"
)
)
}
@Test
fun `커뮤니티 더보기는 하나의 Activity callback에서 권한별 기존 메뉴와 수정 결과를 연결한다`() {
val source = projectFile(
"app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/CreatorChannelActivity.kt"
).readText()
val handlerSource = sourceSection(
source = source,
startMarker = "override fun onCreatorChannelCommunityMoreClicked(item: CreatorChannelCommunityMenuItem)",
endMarker = "override fun onCreatorChannelFanTalkContentChanged"
)
assertEquals(
1,
Regex(
Regex.escape(
"override fun onCreatorChannelCommunityMoreClicked(item: CreatorChannelCommunityMenuItem)"
)
)
.findAll(source)
.count()
)
assertTrue(handlerSource.contains("if (!item.showMore) return"))
assertTrue(handlerSource.contains("CreatorCommunityPostMenuBottomSheetDialog("))
assertTrue(handlerSource.contains("isFixed = item.isPinned"))
assertTrue(handlerSource.contains("isCreator = item.isOwner"))
assertTrue(handlerSource.contains("onClickPin = { updateCreatorChannelCommunityPostFixed(item) }"))
assertTrue(handlerSource.contains("onClickDelete = { showDeleteCreatorChannelCommunityPostDialog(item) }"))
assertTrue(handlerSource.contains("CreatorCommunityReportDialog("))
assertTrue(handlerSource.contains("if (item.isOwner)"))
assertFalse(handlerSource.contains("isCreatorChannelOwner()"))
assertTrue(source.contains("private val communityModifyLauncher = registerForActivityResult"))
assertTrue(source.contains("CommunityActivityResultSource.Modify"))
assertTrue(source.contains("CreatorCommunityModifyActivity::class.java"))
assertTrue(source.contains("putExtra(Constants.EXTRA_COMMUNITY_POST_ID, item.postId)"))
}
@Test
fun `커뮤니티 고정과 삭제 mutation은 역할과 중복을 재확인하고 성공만 목록을 갱신한다`() {
val source = projectFile(
"app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/CreatorChannelActivity.kt"
).readText()
val pinSource = sourceSection(
source = source,
startMarker = "private fun updateCreatorChannelCommunityPostFixed(item: CreatorChannelCommunityMenuItem)",
endMarker = "private fun showDeleteCreatorChannelCommunityPostDialog"
)
val deleteSource = sourceSection(
source = source,
startMarker = "private fun deleteCreatorChannelCommunityPost(item: CreatorChannelCommunityMenuItem)",
endMarker = "private fun reportCreatorChannelCommunityPost"
)
val deleteDialogSource = sourceSection(
source = source,
startMarker = "private fun showDeleteCreatorChannelCommunityPostDialog",
endMarker = "private fun deleteCreatorChannelCommunityPost"
)
listOf(pinSource, deleteSource).forEach { mutationSource ->
assertTrue(
mutationSource.contains(
"if (!item.isOwner || isCommunityPostMutating) return"
)
)
assertFalse(mutationSource.contains("isCreatorChannelOwner()"))
assertTrue(mutationSource.contains("isCommunityPostMutating = true"))
assertEquals(2, "isCommunityPostMutating = false".toRegex().findAll(mutationSource).count())
assertTrue(mutationSource.contains("if (response.success)"))
assertTrue(mutationSource.contains("handleCommunityChange(CommunityChange.Updated)"))
assertTrue(mutationSource.contains("showCommunityMutationFailureToast"))
}
assertTrue(
pinSource.contains(
"creatorCommunityRepository.updateCommunityPostFixed(item.postId, !item.isPinned, authToken())"
)
)
assertTrue(deleteDialogSource.contains("if (!item.isOwner) return"))
assertFalse(deleteDialogSource.contains("isCreatorChannelOwner()"))
assertTrue(deleteSource.contains("ModifyCommunityPostRequest("))
assertTrue(deleteSource.contains("creatorCommunityId = item.postId"))
assertTrue(deleteSource.contains("isActive = false"))
assertTrue(deleteSource.contains("Gson().toJson"))
assertTrue(deleteSource.contains("toRequestBody(\"text/plain\".toMediaType())"))
assertTrue(
deleteSource.contains(
"creatorCommunityRepository.modifyCommunityPost(postImage = null, request = request, token = authToken())"
)
)
}
@Test
fun `커뮤니티 신고 mutation은 방문자 역할과 중복을 재확인하고 성공 토스트만 표시한다`() {
val source = projectFile(
"app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/CreatorChannelActivity.kt"
).readText()
val reportSource = sourceSection(
source = source,
startMarker = "private fun reportCreatorChannelCommunityPost(",
endMarker = "private fun showCommunityMutationFailureToast"
)
assertTrue(
reportSource.contains(
"if (item.isOwner || !item.showMore || reason.isBlank() || " +
"isCommunityPostMutating) return"
)
)
assertFalse(reportSource.contains("isCreatorChannelOwner()"))
assertTrue(reportSource.contains("isCommunityPostMutating = true"))
assertEquals(2, "isCommunityPostMutating = false".toRegex().findAll(reportSource).count())
assertTrue(
reportSource.contains(
"creatorChannelRepository.reportCommunityPost(item.postId, reason, authToken())"
)
)
assertTrue(reportSource.contains("response.message.isNullOrBlank()"))
assertTrue(reportSource.contains("R.string.character_comment_report_submitted"))
assertTrue(reportSource.contains("showCommunityMutationFailureToast"))
assertFalse(reportSource.contains("handleCommunityChange("))
}
@Test
fun `follow notify source는 Phase 11 직접 팔로우 알림 액션을 연결한다`() {
val source = projectFile(
@@ -653,80 +811,12 @@ class CreatorChannelActivitySourceTest {
assertTrue(source.contains("iconResId = R.drawable.ic_new_upload_community_post"))
assertTrue(source.contains("textResId = R.string.creator_channel_owner_fab_community"))
assertTrue(source.contains("CreatorChannelTab.Community.ordinal -> onOwnerFabCommunityClicked()"))
assertTrue(source.contains("private val communityPostModifyLauncher"))
assertTrue(source.contains("CreatorCommunityModifyActivity::class.java"))
assertTrue(source.contains("putExtra(Constants.EXTRA_COMMUNITY_POST_ID, item.postId)"))
assertTrue(source.contains("creatorCommunityRepository.updateCommunityPostFixed("))
assertTrue(source.contains("isFixed = !item.isPinned"))
assertTrue(source.contains("creatorCommunityRepository.modifyCommunityPost("))
assertTrue(source.contains("isActive = false"))
assertFalse(source.contains("communityPostModifyLauncher"))
assertFalse(source.contains("onCreatorChannelCommunityOwnerMoreClicked"))
assertTrue(source.contains("findCommunityFragment()?.onCreatorChannelCommunityRefreshRequested()"))
assertFalse(source.contains("onCreatorChannelCommunityOwnerMoreClicked(postId: Long)"))
assertFalse(fragment.contains("onCreatorChannelCommunityOwnerMoreClicked(item.postId)"))
assertFalse(source.contains("onClickPin = {},"))
assertFalse(source.contains("onClickModify = {},"))
assertFalse(source.contains("onClickDelete = {},"))
assertTrue(fragment.contains("fun onCreatorChannelCommunityRefreshRequested()"))
assertTrue(
fragment.contains(
"CreatorCommunityMediaPlayerManager(requireContext()) { listAdapter.notifyDataSetChanged() }"
)
)
assertTrue(fragment.contains("mediaPlayerManager?.toggleContent(CreatorCommunityContentItem(item.postId, audioUrl))"))
assertTrue(fragment.contains("mediaPlayerManager?.stopContent()"))
}
@Test
fun `커뮤니티 고정 성공은 실제 post id로 단일 변경 handler를 호출한다`() {
val source = projectFile(
"app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/CreatorChannelActivity.kt"
).readText()
val fixedSource = sourceSection(
source = source,
startMarker = "private fun updateCreatorChannelCommunityPostFixed",
endMarker = "private fun deleteCreatorChannelCommunityPost"
)
val successMarker = "if (response.success)"
val beforeSuccessSource = fixedSource.substring(0, fixedSource.indexOf(successMarker))
val successSource = fixedSource.substring(
fixedSource.indexOf(successMarker),
fixedSource.indexOf("} else", fixedSource.indexOf(successMarker))
)
assertTrue(fixedSource.contains("postId = item.postId"))
assertTrue(fixedSource.contains("isFixed = !item.isPinned"))
assertTrue(successSource.contains("handleCommunityChange(CommunityChange.PinChanged(item.postId))"))
assertFalse(beforeSuccessSource.contains("CommunityChange.PinChanged"))
assertEquals(1, fixedSource.split("CommunityChange.PinChanged").size - 1)
assertFalse(fixedSource.contains("CommunityChange.PinChanged(creatorId)"))
assertFalse(fixedSource.contains("refreshCreatorChannelCommunity()"))
}
@Test
fun `커뮤니티 삭제 성공은 실제 post id로 단일 변경 handler를 호출한다`() {
val source = projectFile(
"app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/CreatorChannelActivity.kt"
).readText()
val deleteSource = sourceSection(
source = source,
startMarker = "private fun deleteCreatorChannelCommunityPost",
endMarker = "private fun authToken()"
)
val successMarker = "if (response.success)"
val beforeSuccessSource = deleteSource.substring(0, deleteSource.indexOf(successMarker))
val successSource = deleteSource.substring(
deleteSource.indexOf(successMarker),
deleteSource.indexOf("} else", deleteSource.indexOf(successMarker))
)
assertTrue(deleteSource.contains("creatorCommunityId = item.postId"))
assertTrue(deleteSource.contains("isActive = false"))
assertTrue(successSource.contains("handleCommunityChange(CommunityChange.Deleted(item.postId))"))
assertFalse(beforeSuccessSource.contains("CommunityChange.Deleted"))
assertEquals(1, deleteSource.split("CommunityChange.Deleted").size - 1)
assertFalse(deleteSource.contains("CommunityChange.Deleted(creatorId)"))
assertFalse(deleteSource.contains("refreshCreatorChannelCommunity()"))
assertFalse(fragment.contains("CreatorCommunityMediaPlayerManager"))
assertFalse(fragment.contains("toggleCommunityAudio"))
}
@Test
@@ -743,18 +833,14 @@ class CreatorChannelActivitySourceTest {
handlerSource.indexOf("CommunityChange.Created"),
handlerSource.indexOf("CommunityChange.Updated")
)
val mutationSource = handlerSource.substring(handlerSource.indexOf("CommunityChange.Updated"))
val updatedSource = handlerSource.substring(handlerSource.indexOf("CommunityChange.Updated"))
assertTrue(createdSource.contains("homeActionDelegate?.refreshHome()"))
assertTrue(createdSource.contains("refreshCreatorChannelCommunity()"))
assertTrue(
mutationSource.contains(
"CommunityChange.Updated,\n" +
" is CommunityChange.Deleted,\n" +
" is CommunityChange.PinChanged -> refreshCreatorChannelCommunity()"
)
)
assertFalse(mutationSource.contains("homeActionDelegate?.refreshHome()"))
assertTrue(updatedSource.contains("homeActionDelegate?.refreshHome()"))
assertTrue(updatedSource.contains("refreshCreatorChannelCommunity()"))
assertFalse(updatedSource.contains("CommunityChange.Deleted"))
assertFalse(updatedSource.contains("CommunityChange.PinChanged"))
}
@Test
@@ -2003,7 +2089,7 @@ class CreatorChannelActivitySourceTest {
assertTrue(adapter.contains("val communityWidthDp = calculateCreatorChannelCommunityCardWidthDp("))
assertTrue(adapter.contains("rootWidthDp = communityWidthDp"))
assertTrue(adapter.contains("setHideEmptyTextRows(true)"))
assertTrue(adapter.contains("bind(community.toFeedCommunityItem())"))
assertTrue(adapter.contains("bind(community.toFeedCommunityItem(showMore = menuItem.showMore))"))
assertTrue(adapter.contains("bindCommunityImages(row, community)"))
assertTrue(adapter.contains("BlurTransformation(itemView.context, 25f, 2.5f)"))
assertTrue(adapter.contains("row.layoutParams = LinearLayout.LayoutParams("))
@@ -61,6 +61,16 @@ class CreatorChannelHomeMapperTest {
assertFalse(visitorContent.sections.filterIsInstance<CreatorChannelHomeSection.Donations>().single().isOwner)
}
@Test
fun `현재 회원 id를 커뮤니티 section에 보존한다`() {
val communities = response().toUiContent(currentMemberId = 77L)
.sections
.filterIsInstance<CreatorChannelHomeSection.Communities>()
.single()
assertEquals(77L, communities.currentMemberId)
}
@Test
fun `null 단건 콘텐츠와 빈 리스트와 blank SNS는 후원 empty와 팬Talk empty section을 생성한다`() {
val content = response(
@@ -267,7 +277,9 @@ class CreatorChannelHomeMapperTest {
dateUtc = "2026-06-11T12:00:00Z",
existOrdered = false,
likeCount = 1,
commentCount = 2
commentCount = 2,
isPinned = false,
isCommentAvailable = true
)
private fun fanTalk() = CreatorChannelFanTalkSummaryResponse(
@@ -4,7 +4,9 @@ import com.google.gson.Gson
import kr.co.vividnext.sodalive.v2.common.CreatorActivityType
import kr.co.vividnext.sodalive.v2.creator.channel.data.CreatorChannelHomeResponse
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
class CreatorChannelHomeModelsTest {
@@ -36,6 +38,15 @@ class CreatorChannelHomeModelsTest {
assertEquals("https://x.example", response.sns.xUrl)
}
@Test
fun `home response preserves community pinned and comment availability`() {
val response = gson.fromJson(homeJson(scheduleType = "AUDIO"), CreatorChannelHomeResponse::class.java)
val community = response.communities.single()
assertTrue(community.isPinned)
assertFalse(community.isCommentAvailable)
}
private fun homeJson(scheduleType: String): String = """
{
"creator": {
@@ -63,7 +74,24 @@ class CreatorChannelHomeModelsTest {
],
"audioContents": [],
"series": [],
"communities": [],
"communities": [
{
"postId": 21,
"creatorId": 1,
"creatorNickname": "creator",
"creatorProfileUrl": "https://example.com/profile.png",
"imageUrl": null,
"audioUrl": null,
"content": "community",
"price": 0,
"dateUtc": "2026-06-12T00:00:00Z",
"existOrdered": false,
"likeCount": 6,
"commentCount": 5,
"isPinned": true,
"isCommentAvailable": false
}
],
"fanTalk": {
"totalCount": 0,
"latestFanTalk": null
@@ -11,6 +11,7 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ApplicationProvider
import kr.co.vividnext.sodalive.R
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Test
@@ -29,6 +30,7 @@ class CreatorChannelCommunityDetailReplyUiContractTest {
val reply = inflateView(R.layout.activity_creator_channel_community_reply)
assertNotNull(detail.findViewById<ImageButton>(R.id.btn_creator_channel_community_detail_back))
assertNotNull(detail.findViewById<ImageButton>(R.id.btn_creator_channel_community_detail_more))
assertNotNull(detail.findViewById<TextView>(R.id.tv_creator_channel_community_detail_comment_header))
assertNotNull(detail.findViewById<RecyclerView>(R.id.rv_creator_channel_community_detail_comments))
assertNotNull(detail.findViewById<View>(R.id.layout_creator_channel_community_detail_paywall))
@@ -39,6 +41,9 @@ class CreatorChannelCommunityDetailReplyUiContractTest {
assertNotNull(detail.findViewById<ImageButton>(R.id.btn_creator_channel_community_detail_send))
assertNotNull(detail.findViewById<ImageButton>(R.id.btn_creator_channel_community_detail_edit_cancel))
assertRemovedId("tv_creator_channel_community_detail_title")
assertRemovedId("layout_creator_channel_community_detail_price")
assertRemovedId("tv_creator_channel_community_detail_price")
assertRemovedId("tv_creator_channel_community_detail_purchased")
assertRemovedId("tv_creator_channel_community_detail_comment_unavailable")
assertNotNull(reply.findViewById<ImageButton>(R.id.btn_creator_channel_community_reply_back))
@@ -156,6 +161,23 @@ class CreatorChannelCommunityDetailReplyUiContractTest {
assertTrue(detailActivity.contains("btn_audio_content_play"))
}
@Test
fun `상세 게시글 더보기는 기존 관리 신고 UI와 수정 launcher를 재사용한다`() {
val detailActivity = projectFile(
"app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/community/detail/" +
"CreatorChannelCommunityDetailActivity.kt"
).readText()
assertTrue(detailActivity.contains("CreatorCommunityPostMenuBottomSheetDialog"))
assertTrue(detailActivity.contains("CreatorCommunityReportDialog"))
assertTrue(detailActivity.contains("CreatorCommunityModifyActivity"))
assertTrue(detailActivity.contains("modifyLauncher"))
assertTrue(detailActivity.contains("Constants.EXTRA_COMMUNITY_POST_ID"))
assertTrue(detailActivity.contains("btnCreatorChannelCommunityDetailMore"))
assertFalse(detailActivity.contains("layoutCreatorChannelCommunityDetailPrice"))
assertFalse(detailActivity.contains("tvCreatorChannelCommunityDetailPurchased"))
}
@Test
fun `댓글 답글 Adapter는 PopupMenu 대신 regular font popup을 사용한다`() {
val commentAdapter = projectFile(
@@ -31,6 +31,8 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.argThat
import org.mockito.kotlin.eq
import org.mockito.kotlin.isNull
import org.mockito.kotlin.never
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
@@ -469,6 +471,99 @@ class CreatorChannelCommunityDetailViewModelTest {
verify(repository, times(2)).getCommunityPostDetail(POST_ID, AUTH_TOKEN)
}
@Test
fun `게시글 더보기는 작성자 또는 무료 또는 구매 완료일 때만 표시한다`() {
SharedPreferenceManager.userId = 10L
val cases = listOf(
detailResponse(isCommentAvailable = false, creatorId = 10L, price = 300, existOrdered = false),
detailResponse(isCommentAvailable = false, creatorId = 999L, price = 0, existOrdered = false),
detailResponse(isCommentAvailable = false, creatorId = 999L, price = 300, existOrdered = true),
detailResponse(isCommentAvailable = false, creatorId = 999L, price = 300, existOrdered = false)
)
val results = cases.map { response ->
stubDetail(response)
viewModel.loadDetail(POST_ID)
(viewModel.detailStateLiveData.requireValue() as CreatorChannelCommunityDetailUiState.Content).post
}
assertTrue(results[0].isOwner)
assertTrue(results[0].showMore)
assertFalse(results[1].isOwner)
assertTrue(results[1].showMore)
assertTrue(results[2].showMore)
assertFalse(results[3].showMore)
}
@Test
fun `게시글 고정 성공은 반전 값을 요청하고 상세 재조회와 변경 이벤트를 노출한다`() {
whenever(repository.getCommunityPostDetail(POST_ID, AUTH_TOKEN)).thenReturn(
Single.just(ApiResponse(true, detailResponse(isCommentAvailable = false, creatorId = 10L, isPinned = false), null)),
Single.just(ApiResponse(true, detailResponse(isCommentAvailable = false, creatorId = 10L, isPinned = true), null))
)
whenever(legacyRepository.updateCommunityPostFixed(POST_ID, true, AUTH_TOKEN))
.thenReturn(Single.just(ApiResponse(true, Any(), null)))
viewModel.loadDetail(POST_ID)
viewModel.updateCommunityPostFixed()
val state = viewModel.detailStateLiveData.requireValue() as CreatorChannelCommunityDetailUiState.Content
assertTrue(state.post.isPinned)
assertTrue(viewModel.postChangedEventLiveData.requireValue() == true)
verify(legacyRepository).updateCommunityPostFixed(POST_ID, true, AUTH_TOKEN)
verify(repository, times(2)).getCommunityPostDetail(POST_ID, AUTH_TOKEN)
}
@Test
fun `게시글 삭제 성공은 삭제 이벤트를 노출한다`() {
stubDetail(detailResponse(isCommentAvailable = false, creatorId = 10L))
whenever(legacyRepository.modifyCommunityPost(isNull(), any(), eq(AUTH_TOKEN)))
.thenReturn(Single.just(ApiResponse(true, Any(), null)))
viewModel.loadDetail(POST_ID)
viewModel.deleteCommunityPost()
assertTrue(viewModel.postDeletedEventLiveData.requireValue() == true)
verify(legacyRepository).modifyCommunityPost(
isNull(),
argThat { requestBody ->
okio.Buffer().also(requestBody::writeTo).readUtf8().contains("\"isActive\":false")
},
eq(AUTH_TOKEN)
)
}
@Test
fun `게시글 신고 성공은 repository 호출과 toast만 노출한다`() {
stubDetail(detailResponse(isCommentAvailable = false, creatorId = 999L))
whenever(repository.reportCommunityPost(POST_ID, "스팸", AUTH_TOKEN))
.thenReturn(Single.just(ApiResponse(true, Any(), "접수됨")))
viewModel.loadDetail(POST_ID)
viewModel.reportCommunityPost("스팸")
verify(repository).reportCommunityPost(POST_ID, "스팸", AUTH_TOKEN)
assertEquals("접수됨", viewModel.toastLiveData.requireValue()?.consume()?.message)
assertFalse(viewModel.postChangedEventLiveData.requireValue() == true)
}
@Test
fun `게시글 mutation 진행 중에는 중복 요청을 막고 실패 시 성공 이벤트를 노출하지 않는다`() {
stubDetail(detailResponse(isCommentAvailable = false, creatorId = 10L))
val subject = PublishSubject.create<ApiResponse<Any>>()
whenever(legacyRepository.updateCommunityPostFixed(POST_ID, true, AUTH_TOKEN))
.thenReturn(subject.firstOrError())
viewModel.loadDetail(POST_ID)
viewModel.updateCommunityPostFixed()
viewModel.updateCommunityPostFixed()
subject.onNext(ApiResponse(false, null, "고정 실패"))
verify(legacyRepository, times(1)).updateCommunityPostFixed(POST_ID, true, AUTH_TOKEN)
assertEquals("고정 실패", viewModel.toastLiveData.requireValue()?.consume()?.message)
assertFalse(viewModel.postChangedEventLiveData.requireValue() == true)
}
@Test
fun `댓글 UI 모델은 답글 화면 재포맷을 위해 원본 createdAtUtc를 보존한다`() {
stubDetail(detailResponse(isCommentAvailable = true, commentIds = listOf(11L)))
@@ -571,7 +666,8 @@ class CreatorChannelCommunityDetailViewModelTest {
existOrdered: Boolean = true,
creatorId: Long = 100L,
commentIds: List<Long> = emptyList(),
commentsHasNext: Boolean = false
commentsHasNext: Boolean = false,
isPinned: Boolean = false
) = CreatorChannelCommunityPostDetailResponse(
postId = POST_ID,
creatorId = creatorId,
@@ -587,7 +683,7 @@ class CreatorChannelCommunityDetailViewModelTest {
likeCount = likeCount,
commentCount = 2,
isLiked = isLiked,
isPinned = false,
isPinned = isPinned,
comments = commentsResponse(ids = commentIds, hasNext = commentsHasNext)
)
@@ -11,6 +11,7 @@ import androidx.test.core.app.ApplicationProvider
import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.v2.creator.channel.community.ui.calculateCreatorChannelCommunityGridItemSize
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertSame
import org.junit.Assert.assertTrue
@@ -62,7 +63,7 @@ class CreatorChannelCommunityFragmentLayoutTest {
}
@Test
fun `커뮤니티 list item layout은 프로필 본문 이미지 잠금 재생 반응 owner 영역을 제공한다`() {
fun `커뮤니티 list item layout은 프로필 본문 이미지 잠금 반응과 작성자 금액을 제공한다`() {
val item = inflateView(R.layout.item_creator_channel_community_list)
val itemLayout = projectFile("app/src/main/res/layout/item_creator_channel_community_list.xml").readText()
val imageContainer = requireNotNull(item.findViewById<View>(R.id.layout_creator_channel_community_list_image_container))
@@ -77,24 +78,29 @@ class CreatorChannelCommunityFragmentLayoutTest {
assertNotNull(item.findViewById<ImageView>(R.id.iv_creator_channel_community_list_image))
assertNotNull(item.findViewById<View>(R.id.layout_creator_channel_community_list_locked_overlay))
assertNotNull(item.findViewById<TextView>(R.id.tv_creator_channel_community_list_locked_price))
assertNotNull(item.findViewById<ImageView>(R.id.iv_creator_channel_community_list_play))
assertNotNull(item.findViewById<TextView>(R.id.tv_creator_channel_community_list_comment_count))
assertNotNull(item.findViewById<TextView>(R.id.tv_creator_channel_community_list_like_count))
assertNotNull(item.findViewById<View>(R.id.layout_creator_channel_community_list_top_actions))
assertNotNull(item.findViewById<View>(R.id.layout_creator_channel_community_list_top_price))
assertNotNull(item.findViewById<ImageView>(R.id.iv_creator_channel_community_list_owner_more))
assertNotNull(item.findViewById<TextView>(R.id.tv_creator_channel_community_list_top_price))
val moreButton = requireNotNull(item.findViewById<View>(R.id.btn_creator_channel_community_list_more))
assertSame(imageContainer, (lockIcon.parent as View).parent)
assertSame(imageContainer, (lockedPrice.parent as View).parent)
assertSame(imageContainer, ((lockedPrice.parent as View).parent as View).parent)
assertSame(
item.findViewById<View>(R.id.layout_creator_channel_community_list_top_actions),
item.findViewById<View>(R.id.layout_creator_channel_community_list_top_price).parent
)
assertSame(
item.findViewById<View>(R.id.layout_creator_channel_community_list_top_actions),
moreButton.parent
)
assertTrue(itemLayout.contains("android:id=\"@+id/layout_creator_channel_community_list_locked_overlay\""))
assertTrue(itemLayout.contains("android:id=\"@+id/tv_creator_channel_community_list_locked_price\""))
assertTrue(itemLayout.contains("android:background=\"@drawable/bg_creator_channel_community_price\""))
assertTrue(itemLayout.contains("android:drawableStart=\"@drawable/ic_bar_cash\""))
assertTrue(itemLayout.contains("android:id=\"@+id/iv_creator_channel_community_list_play\""))
assertFalse(itemLayout.contains("android:drawableStart=\"@drawable/ic_bar_cash\""))
assertTrue(itemLayout.contains("android:src=\"@drawable/ic_bar_cash\""))
assertFalse(itemLayout.contains("iv_creator_channel_community_list_play"))
assertFalse(itemLayout.contains("iv_creator_channel_community_list_owner_more"))
}
@Test
@@ -138,7 +144,7 @@ class CreatorChannelCommunityFragmentLayoutTest {
}
@Test
fun `커뮤니티 fragment source는 pagination view mode owner padding stopContent 계약을 사용한다`() {
fun `커뮤니티 fragment source는 pagination view mode owner padding과 상세 이동 계약을 사용한다`() {
val fragment = projectFile(
"app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/community/CreatorChannelCommunityFragment.kt"
).readText()
@@ -161,8 +167,10 @@ class CreatorChannelCommunityFragmentLayoutTest {
assertTrue(fragment.contains("calculateCreatorChannelCommunityGridItemSize("))
assertTrue(fragment.contains("viewModel.consumePaginationErrorMessage()"))
assertTrue(fragment.contains("applyOwnerCtaPadding"))
assertTrue(fragment.contains("pauseContent"))
assertTrue(fragment.contains("stopContent"))
assertFalse(fragment.contains("CreatorCommunityMediaPlayerManager"))
assertFalse(fragment.contains("toggleCommunityAudio"))
assertFalse(fragment.contains("onPlayClick"))
assertFalse(fragment.contains("onCreatorChannelCommunityOwnerMoreClicked"))
}
@Test
@@ -181,19 +189,25 @@ class CreatorChannelCommunityFragmentLayoutTest {
assertTrue(listAdapter.contains("showComment") && listAdapter.contains("isVisible = item.showComment"))
assertTrue(listAdapter.contains("isLocked"))
assertTrue(gridAdapter.contains("isLocked"))
assertTrue(listAdapter.contains("showPlayButton"))
assertTrue(listAdapter.contains("showOwnerMore"))
assertTrue(listAdapter.contains("isPlayingContent"))
assertTrue(listAdapter.contains("R.drawable.ic_player_pause"))
assertTrue(listAdapter.contains("R.drawable.ic_new_player_play"))
assertTrue(listAdapter.contains("private val onPostClick: (CreatorChannelCommunityPostUiModel) -> Unit = {}"))
assertTrue(listAdapter.contains("private val onMoreClick: (CreatorChannelCommunityMenuItem) -> Unit = {}"))
assertTrue(listAdapter.contains("root.setOnClickListener { onPostClick(item) }"))
assertTrue(listAdapter.contains("ivCreatorChannelCommunityListPlay.setOnClickListener { onPlayClick(item) }"))
assertTrue(listAdapter.contains("onOwnerMoreClick(item)"))
assertTrue(listAdapter.contains("ivCreatorChannelCommunityListOwnerMore.setOnClickListener { onOwnerMoreClick(item) }"))
assertTrue(
listAdapter.contains(
"btnCreatorChannelCommunityListMore.setOnClickListener { onMoreClick(item.menuItem) }"
)
)
assertTrue(listAdapter.contains("item.showOwnerTopPrice || item.menuItem.showMore"))
assertFalse(listAdapter.contains("onPlayClick"))
assertFalse(listAdapter.contains("onOwnerMoreClick"))
assertFalse(listAdapter.contains("isPlayingContent"))
assertFalse(listAdapter.contains("showPlayButton"))
assertFalse(listAdapter.contains("showOwnerMore"))
assertTrue(gridAdapter.contains("private val onPostClick: (CreatorChannelCommunityPostUiModel) -> Unit = {}"))
assertTrue(gridAdapter.contains("root.setOnClickListener { onPostClick(item) }"))
assertTrue(listAdapter.contains("tvCreatorChannelCommunityListLockedPrice.isVisible = item.isLocked"))
assertFalse(gridAdapter.contains("onMoreClick"))
assertFalse(gridAdapter.contains("CreatorChannelCommunityMenuItem"))
assertTrue(listAdapter.contains("layoutCreatorChannelCommunityListLockedPrice.isVisible = item.isLocked"))
assertTrue(listAdapter.contains("layoutCreatorChannelCommunityListTopPrice.isVisible = item.showOwnerTopPrice"))
assertTrue(!listAdapter.contains("item.isLocked || item.showOwnerTopPrice"))
assertTrue(gridAdapter.contains(".asBitmap()"))
@@ -211,8 +225,17 @@ class CreatorChannelCommunityFragmentLayoutTest {
).readText()
assertTrue(fragment.contains("onPostClick = { item -> host.onCreatorChannelCommunityPostClicked(item.postId) }"))
assertTrue(fragment.contains("onMoreClick = { item -> host.onCreatorChannelCommunityMoreClicked(item) }"))
assertTrue(fragment.contains("private val gridAdapter = CreatorChannelCommunityGridAdapter("))
assertTrue(fragment.contains("fun onCreatorChannelCommunityPostClicked(postId: Long)"))
assertTrue(fragment.contains("fun onCreatorChannelCommunityMoreClicked(item: CreatorChannelCommunityMenuItem)"))
assertFalse(fragment.contains("onPlayClick"))
assertFalse(fragment.contains("onCreatorChannelCommunityOwnerMoreClicked"))
assertFalse(
fragment.substringAfter("private val gridAdapter = CreatorChannelCommunityGridAdapter(")
.substringBefore(")\n private var currentContentState")
.contains("onMoreClick")
)
}
@Test
@@ -66,7 +66,7 @@ class CreatorChannelCommunityMapperTest {
}
@Test
fun `유료 미구매 타인 게시글은 잠금 상태이고 play button을 숨긴다`() {
fun `유료 미구매 타인 게시글은 잠금 상태이고 이미지를 숨긴다`() {
val item = listOf(
communityPost(price = 100, existOrdered = false, imageUrl = "image.png", audioUrl = "audio.mp3")
).toCommunityPostUiModels(relativeTimeTextFormatter, isOwner = false, currentUserId = 99L).single()
@@ -74,7 +74,6 @@ class CreatorChannelCommunityMapperTest {
assertTrue(item.isLocked)
assertNull(item.imageUrl)
assertEquals(CreatorChannelCommunityImageMode.LockedGray, item.imageMode)
assertFalse(item.showPlayButton)
}
@Test
@@ -93,7 +92,7 @@ class CreatorChannelCommunityMapperTest {
}
@Test
fun `고정 게시글 여부는 owner more 정책에서 사용할 수 있도록 UI 모델에 보존한다`() {
fun `고정 게시글 여부는 UI 모델에 보존한다`() {
val pinnedItem = listOf(communityPost(isPinned = true))
.toCommunityPostUiModels(relativeTimeTextFormatter, isOwner = true, currentUserId = 10L)
.single()
@@ -108,33 +107,32 @@ class CreatorChannelCommunityMapperTest {
}
@Test
fun `본인 또는 구매한 사용자는 이미지와 오디오가 있으면 play button을 표시한다`() {
val ownerItem = listOf(
communityPost(price = 100, existOrdered = false, imageUrl = "image.png", audioUrl = "audio.mp3")
).toCommunityPostUiModels(relativeTimeTextFormatter, isOwner = true, currentUserId = 10L).single()
val orderedItem = listOf(
communityPost(price = 100, existOrdered = true, imageUrl = "image.png", audioUrl = "audio.mp3")
).toCommunityPostUiModels(relativeTimeTextFormatter, isOwner = false, currentUserId = 99L).single()
fun `메뉴 권한은 작성자 무료 구매 여부에 따라 계산하고 고정 상태를 보존한다`() {
val authorPaidNotOrdered = listOf(communityPost(price = 100, existOrdered = false, isPinned = true))
.toCommunityPostUiModels(relativeTimeTextFormatter, isOwner = false, currentUserId = 10L)
.single()
val visitorFree = listOf(communityPost(price = 0, existOrdered = false))
.toCommunityPostUiModels(relativeTimeTextFormatter, isOwner = false, currentUserId = 99L)
.single()
val visitorPaidOrdered = listOf(communityPost(price = 100, existOrdered = true))
.toCommunityPostUiModels(relativeTimeTextFormatter, isOwner = false, currentUserId = 99L)
.single()
val visitorPaidNotOrdered = listOf(communityPost(price = 100, existOrdered = false))
.toCommunityPostUiModels(relativeTimeTextFormatter, isOwner = false, currentUserId = 99L)
.single()
assertFalse(ownerItem.isLocked)
assertTrue(ownerItem.showPlayButton)
assertFalse(orderedItem.isLocked)
assertTrue(orderedItem.showPlayButton)
assertTrue(authorPaidNotOrdered.menuItem.isOwner)
assertTrue(authorPaidNotOrdered.menuItem.showMore)
assertTrue(authorPaidNotOrdered.menuItem.isPinned)
assertTrue(authorPaidNotOrdered.isPinned)
assertTrue(visitorFree.menuItem.showMore)
assertTrue(visitorPaidOrdered.menuItem.showMore)
assertFalse(visitorPaidNotOrdered.menuItem.isOwner)
assertFalse(visitorPaidNotOrdered.menuItem.showMore)
}
@Test
fun `오디오 또는 이미지가 없으면 play button을 숨긴다`() {
val items = listOf(
communityPost(postId = 1L, imageUrl = null, audioUrl = "audio.mp3"),
communityPost(postId = 2L, imageUrl = "image.png", audioUrl = null),
communityPost(postId = 3L, imageUrl = "image.png", audioUrl = " ")
).toCommunityPostUiModels(relativeTimeTextFormatter, isOwner = false, currentUserId = 99L)
assertEquals(listOf(false, false, false), items.map { it.showPlayButton })
}
@Test
fun `본인 채널에 본인이 쓴 게시글에서만 owner more와 유료 top price를 표시한다`() {
fun `본인 채널에 본인이 쓴 유료 게시글에서만 top price를 표시한다`() {
val ownerPaid = listOf(communityPost(price = 100, creatorId = 10L))
.toCommunityPostUiModels(relativeTimeTextFormatter, isOwner = true, currentUserId = 10L)
.single()
@@ -148,13 +146,9 @@ class CreatorChannelCommunityMapperTest {
.toCommunityPostUiModels(relativeTimeTextFormatter, isOwner = false, currentUserId = 10L)
.single()
assertTrue(ownerPaid.showOwnerMore)
assertTrue(ownerPaid.showOwnerTopPrice)
assertTrue(ownerFree.showOwnerMore)
assertFalse(ownerFree.showOwnerTopPrice)
assertFalse(otherCreator.showOwnerMore)
assertFalse(otherCreator.showOwnerTopPrice)
assertFalse(otherChannel.showOwnerMore)
assertFalse(otherChannel.showOwnerTopPrice)
}
@@ -3,7 +3,6 @@ package kr.co.vividnext.sodalive.v2.main.home
import android.app.Application
import android.content.Context
import android.content.res.Configuration
import android.graphics.drawable.ColorDrawable
import android.text.Spanned
import android.text.TextUtils
import android.text.style.ClickableSpan
@@ -659,6 +658,19 @@ class HomeMainFragmentLayoutTest {
assertEquals("https://example.com/audio.m4a", item.toUiModel().item.audioUrl)
}
@Test
fun `popular community mapper preserves locked item reactions`() {
val item = popularCommunityData(
audioUrl = null,
price = 100,
existOrdered = false
).toUiModel().item
assertTrue(item.isLocked)
assertTrue(item.showReaction)
assertTrue(item.showComment)
}
@Test
fun `home relative time formatter converts active creator utc timestamp to relative time text`() {
val context = ApplicationProvider.getApplicationContext<Context>()
@@ -1509,7 +1521,9 @@ class HomeMainFragmentLayoutTest {
private fun popularCommunityData(
audioUrl: String?,
createdAt: String = "2분 전"
createdAt: String = "2분 전",
price: Int = 0,
existOrdered: Boolean = false
): HomePopularCommunityPostItem {
return HomePopularCommunityPostItem(
postId = 1L,
@@ -1519,11 +1533,11 @@ class HomeMainFragmentLayoutTest {
imageUrl = null,
audioUrl = audioUrl,
content = "본문",
price = 0,
price = price,
createdAt = createdAt,
likeCount = 6L,
commentCount = 5L,
existOrdered = false
existOrdered = existOrdered
)
}
@@ -1,6 +1,8 @@
package kr.co.vividnext.sodalive.v2.widget.feed
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import kr.co.vividnext.sodalive.R
import org.junit.Test
@@ -102,4 +104,71 @@ class FeedItemTest {
assertEquals(5, item.commentCount)
assertEquals(6, item.likeCount)
}
@Test
fun `locked paid community item hides reactions and comments`() {
val item = communityItem(
price = 100,
existOrdered = false,
hideReactionWhenLocked = true
)
assertTrue(item.isLocked)
assertFalse(item.showReaction)
assertFalse(item.showComment)
}
@Test
fun `locked paid community item preserves reactions by default`() {
val item = communityItem(price = 100, existOrdered = false)
assertTrue(item.isLocked)
assertTrue(item.showReaction)
assertTrue(item.showComment)
}
@Test
fun `free community item with comments disabled keeps likes only`() {
val item = communityItem(price = 0, isCommentAvailable = false)
assertFalse(item.isLocked)
assertTrue(item.showReaction)
assertFalse(item.showComment)
}
@Test
fun `community item preserves pinned state`() {
val item = communityItem(isPinned = true)
assertTrue(item.isPinned)
}
@Test
fun `community item hides more action by default`() {
assertFalse(communityItem().showMore)
}
private fun communityItem(
price: Int = 0,
existOrdered: Boolean = false,
isPinned: Boolean = false,
isCommentAvailable: Boolean = true,
hideReactionWhenLocked: Boolean = false
) = FeedItem.Community(
feedId = "feed-community-policy",
creatorId = "creator-1",
creatorName = "크리에이터 이름",
creatorImageUrl = "https://example.com/profile.png",
postId = "post-policy",
bodyText = "커뮤니티 본문",
keywordText = "",
createdAtText = "2분 전",
commentCount = 5,
likeCount = 6,
price = price,
existOrdered = existOrdered,
isPinned = isPinned,
isCommentAvailable = isCommentAvailable,
hideReactionWhenLocked = hideReactionWhenLocked
)
}
@@ -63,6 +63,28 @@ class FeedViewTest {
assertEquals(View.GONE, view.findViewById<TextView>(R.id.tv_feed_community_body).visibility)
}
@Test
fun `community more click은 현재 bind된 item만 전달한다`() {
val view = inflateView<FeedCommunityView>(R.layout.view_feed_community)
val first = sampleCommunityItem(bodyText = "첫 번째", keywordText = "", showMore = true)
val second = sampleCommunityItem(bodyText = "두 번째", keywordText = "", showMore = true)
var clickedItem: FeedItem.Community? = null
var rootClickedItem: FeedItem? = null
view.setOnMoreClick { clickedItem = it }
view.setOnFeedClick { rootClickedItem = it }
view.bind(first)
view.bind(second)
view.findViewById<View>(R.id.btn_feed_community_more).performClick()
assertSame(second, clickedItem)
assertEquals(null, rootClickedItem)
view.performClick()
assertSame(second, rootClickedItem)
}
@Test
fun `community layout uses runtime image height instead of fixed crop height`() {
val view = inflateView<FeedCommunityView>(R.layout.view_feed_community)
@@ -201,7 +223,8 @@ class FeedViewTest {
audioUrl: String? = null,
price: Int = 0,
existOrdered: Boolean = false,
showKeyword: Boolean = true
showKeyword: Boolean = true,
showMore: Boolean = false
) = FeedItem.Community(
feedId = "feed-community-1",
creatorId = "creator-1",
@@ -217,7 +240,8 @@ class FeedViewTest {
audioUrl = audioUrl,
price = price,
existOrdered = existOrdered,
showKeyword = showKeyword
showKeyword = showKeyword,
showMore = showMore
)
private fun Int.dpToPx(): Int {