feat(gift): 받은 선물 상세 화면을 연결한다
This commit is contained in:
@@ -94,6 +94,7 @@ import kr.co.vividnext.sodalive.home.pushnotification.PushNotificationListViewMo
|
||||
import kr.co.vividnext.sodalive.v2.gift.GiftSendRequestViewModel
|
||||
import kr.co.vividnext.sodalive.v2.gift.GiftInboxViewModel
|
||||
import kr.co.vividnext.sodalive.v2.gift.GiftDetailViewModel
|
||||
import kr.co.vividnext.sodalive.v2.gift.GiftRecipientAddressViewModel
|
||||
import kr.co.vividnext.sodalive.v2.gift.GiftTrackingViewModel
|
||||
import kr.co.vividnext.sodalive.v2.gift.GiftCancelViewModel
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftApi
|
||||
@@ -482,6 +483,7 @@ class AppDI(private val context: Context, isDebugMode: Boolean) {
|
||||
viewModel { GiftSendRequestViewModel(get()) }
|
||||
viewModel { GiftInboxViewModel(get()) }
|
||||
viewModel { GiftDetailViewModel(get()) }
|
||||
viewModel { GiftRecipientAddressViewModel(get()) }
|
||||
viewModel { GiftTrackingViewModel(get()) }
|
||||
viewModel { GiftCancelViewModel(get()) }
|
||||
viewModel { HomeOnAirLiveViewModel(get()) }
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.base.BaseActivity
|
||||
@@ -21,6 +22,22 @@ import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
class GiftDetailActivity : BaseActivity<ActivityGiftDetailBinding>(ActivityGiftDetailBinding::inflate) {
|
||||
private val viewModel: GiftDetailViewModel by viewModel()
|
||||
private val cancelViewModel: GiftCancelViewModel by viewModel()
|
||||
private val recipientViewModel: GiftRecipientAddressViewModel by viewModel()
|
||||
private var bindingRecipientForm = false
|
||||
private var isRecipientFormRendered = false
|
||||
private val postcodeLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
recipientViewModel.formState.value?.let { form ->
|
||||
recipientViewModel.updateForm(
|
||||
form.copy(
|
||||
recipientZipCode = result.data?.getStringExtra(KakaoPostcodeSearchActivity.EXTRA_ZONE_CODE).orEmpty(),
|
||||
recipientAddress = result.data?.getStringExtra(KakaoPostcodeSearchActivity.EXTRA_ADDRESS).orEmpty()
|
||||
)
|
||||
)
|
||||
binding.etDetailAddress.requestFocus()
|
||||
}
|
||||
}
|
||||
}
|
||||
private var cancelDialog: V2ModalDialog? = null
|
||||
private var hasChanged = false
|
||||
private val timelineAdapter = GiftStatusTimelineAdapter()
|
||||
@@ -49,6 +66,9 @@ class GiftDetailActivity : BaseActivity<ActivityGiftDetailBinding>(ActivityGiftD
|
||||
binding.retry.setOnClickListener { viewModel.retry() }
|
||||
binding.inquiry.setOnClickListener { viewModel.onInquiryClick() }
|
||||
binding.undeliverableInquiry.setOnClickListener { viewModel.onInquiryClick() }
|
||||
binding.receivedInquiry.setOnClickListener { viewModel.onInquiryClick() }
|
||||
binding.policy.setOnClickListener { viewModel.onPolicyClick() }
|
||||
setupRecipientForm()
|
||||
binding.timeline.layoutManager = GridLayoutManager(this, 4)
|
||||
binding.timeline.adapter = timelineAdapter
|
||||
binding.tracking.setOnClickListener {
|
||||
@@ -63,6 +83,81 @@ class GiftDetailActivity : BaseActivity<ActivityGiftDetailBinding>(ActivityGiftD
|
||||
|
||||
private fun reload() = viewModel.retry()
|
||||
|
||||
private fun setupRecipientForm() = with(binding) {
|
||||
etRecipientName.filters = arrayOf(GiftSendInputFilters.senderName())
|
||||
etPhoneNumber.filters = arrayOf(GiftSendInputFilters.phoneNumber())
|
||||
listOf(etRecipientName, etPhoneNumber, etDetailAddress).forEach { input ->
|
||||
input.addTextChangedListener { updateRecipientForm() }
|
||||
}
|
||||
listOf(cbTerms, cbPrivacy).forEach { agreement ->
|
||||
agreement.append(getString(R.string.gift_send_required))
|
||||
agreement.setOnCheckedChangeListener { button, checked ->
|
||||
button.isSelected = checked
|
||||
updateRecipientForm()
|
||||
}
|
||||
}
|
||||
btnPostcodeSearch.setOnClickListener {
|
||||
postcodeLauncher.launch(KakaoPostcodeSearchActivity.newIntent(this@GiftDetailActivity))
|
||||
}
|
||||
receive.setOnClickListener {
|
||||
if (isRecipientFormRendered) recipientViewModel.submit(intent.getStringExtra(EXTRA_APPLICATION_NO).orEmpty())
|
||||
}
|
||||
recipientViewModel.formState.observe(this@GiftDetailActivity) { form ->
|
||||
bindingRecipientForm = true
|
||||
listOf(
|
||||
etRecipientName to form.recipientName,
|
||||
etPhoneNumber to form.recipientPhoneNumber,
|
||||
etDetailAddress to form.recipientAddressDetail
|
||||
).forEach { (input, value) -> if (input.text.toString() != value) input.setText(value) }
|
||||
tvPostcode.text = form.recipientZipCode
|
||||
tvAddress.text = form.recipientAddress
|
||||
cbTerms.isChecked = form.recipientTermsAgreed
|
||||
cbPrivacy.isChecked = form.recipientPrivacyAgreed
|
||||
bindingRecipientForm = false
|
||||
updateReceiveButton()
|
||||
}
|
||||
recipientViewModel.isSubmitting.observe(this@GiftDetailActivity) {
|
||||
updateReceiveButton()
|
||||
}
|
||||
recipientViewModel.toastLiveData.observe(this@GiftDetailActivity) { toast ->
|
||||
if (toast != null) {
|
||||
recipientViewModel.consumeToast()?.let {
|
||||
showToast(it.resId?.let(::getString) ?: it.message.orEmpty())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateRecipientForm() = with(binding) {
|
||||
if (bindingRecipientForm) return
|
||||
recipientViewModel.updateForm(
|
||||
GiftRecipientAddressFormState(
|
||||
etRecipientName.text.toString(),
|
||||
etPhoneNumber.text.toString(),
|
||||
tvPostcode.text.toString(),
|
||||
tvAddress.text.toString(),
|
||||
etDetailAddress.text.toString(),
|
||||
cbTerms.isChecked,
|
||||
cbPrivacy.isChecked
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private fun updateReceiveButton() = with(binding.receive) {
|
||||
isVisible = isRecipientFormRendered
|
||||
binding.receiveProgress.isVisible = isRecipientFormRendered && recipientViewModel.isSubmitting.value == true
|
||||
isEnabled = isRecipientFormRendered && recipientViewModel.formState.value?.isSubmitEnabled == true &&
|
||||
recipientViewModel.isSubmitting.value != true
|
||||
setTextColor(getColor(if (isEnabled) R.color.white else R.color.gray_500))
|
||||
setBackgroundResource(
|
||||
if (isEnabled) {
|
||||
R.drawable.bg_creator_channel_fantalk_write_send_enabled
|
||||
} else {
|
||||
R.drawable.bg_creator_channel_fantalk_write_send_disabled
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun showCancelDialog() {
|
||||
val detail = (viewModel.state.value as? GiftDetailUiState.Content)?.detail ?: return
|
||||
if (detail.direction != "SENT" || detail.status != "RECEIVED" || cancelDialog != null) return
|
||||
@@ -104,6 +199,12 @@ class GiftDetailActivity : BaseActivity<ActivityGiftDetailBinding>(ActivityGiftD
|
||||
|
||||
private fun observe() {
|
||||
viewModel.state.observe(this, ::render)
|
||||
recipientViewModel.recipientAddressSuccessLiveData.observe(this) { succeeded ->
|
||||
if (succeeded && recipientViewModel.consumeRecipientAddressSuccessEvent()) {
|
||||
markChanged()
|
||||
viewModel.reloadAfterRecipientAddressSuccess()
|
||||
}
|
||||
}
|
||||
viewModel.finishErrorLiveData.observe(this) { event ->
|
||||
if (event != null) {
|
||||
viewModel.consumeFinishError()?.let { error ->
|
||||
@@ -115,9 +216,17 @@ class GiftDetailActivity : BaseActivity<ActivityGiftDetailBinding>(ActivityGiftD
|
||||
viewModel.inquiryLiveData.observe(this) { requested ->
|
||||
if (requested) viewModel.consumeInquiryIntent()?.let(::startActivity)
|
||||
}
|
||||
viewModel.toastLiveData.observe(this) { toast ->
|
||||
if (toast != null) {
|
||||
viewModel.consumeToast()?.let {
|
||||
showToast(it.resId?.let(::getString) ?: it.message.orEmpty())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun render(state: GiftDetailUiState) {
|
||||
isRecipientFormRendered = false
|
||||
binding.progress.isVisible = state == GiftDetailUiState.Loading
|
||||
binding.error.isVisible = state is GiftDetailUiState.Error
|
||||
binding.content.isVisible = state is GiftDetailUiState.Content || state is GiftDetailUiState.Canceled
|
||||
@@ -134,6 +243,7 @@ class GiftDetailActivity : BaseActivity<ActivityGiftDetailBinding>(ActivityGiftD
|
||||
bind(GiftDetailPresenter.present(state.detail, state.cancel))
|
||||
}
|
||||
}
|
||||
updateReceiveButton()
|
||||
}
|
||||
|
||||
private fun markChanged() {
|
||||
@@ -142,6 +252,10 @@ class GiftDetailActivity : BaseActivity<ActivityGiftDetailBinding>(ActivityGiftD
|
||||
}
|
||||
|
||||
private fun bind(model: GiftDetailUiModel) {
|
||||
binding.giftInfoTitle.isVisible = true
|
||||
binding.giftInfo.isVisible = true
|
||||
binding.normalSections.removeView(binding.sectionSeparator)
|
||||
binding.normalSections.addView(binding.sectionSeparator, binding.normalSections.indexOfChild(binding.giftInfoTitle))
|
||||
val canceled = model.cancellation != null
|
||||
val received = model.status == "RECEIVED"
|
||||
val undeliverable = model.undeliverable != null
|
||||
@@ -192,6 +306,54 @@ class GiftDetailActivity : BaseActivity<ActivityGiftDetailBinding>(ActivityGiftD
|
||||
it.label to resolveGiftDetailText(it.value)
|
||||
}
|
||||
)
|
||||
bindReceived(model)
|
||||
}
|
||||
|
||||
private fun bindReceived(model: GiftDetailUiModel) = with(binding) {
|
||||
val received = model.received
|
||||
val form = received is GiftDetailReceived.AddressForm
|
||||
isRecipientFormRendered = form
|
||||
recipientForm.isVisible = form
|
||||
privacyNotice.isVisible = form
|
||||
receivedActions.isVisible = received != null && !form
|
||||
receivedInquiry.isVisible = received != null && GiftDetailAction.INQUIRY in model.actions
|
||||
policy.isVisible = GiftDetailAction.POLICY in model.actions
|
||||
undeliverableDivider.isVisible = received is GiftDetailReceived.Undeliverable
|
||||
undeliverableReasonHeader.isVisible = received is GiftDetailReceived.Undeliverable
|
||||
recipientGuidance.bindText((received as? GiftDetailReceived.Delivered)?.recipientAddressGuidance)
|
||||
if (received == null) return
|
||||
header.setText(if (form) R.string.gift_recipient_receive else R.string.gift_recipient_detail_title)
|
||||
btnBack.isVisible = true
|
||||
close.isVisible = false
|
||||
inquiry.isVisible = false
|
||||
undeliverableInquiry.isVisible = false
|
||||
val rows = when (received) {
|
||||
is GiftDetailReceived.AddressForm -> received.pendingGiftRows
|
||||
is GiftDetailReceived.AddressCompleted -> received.giftInfoRows
|
||||
is GiftDetailReceived.Delivered -> received.giftInfoRows
|
||||
is GiftDetailReceived.Undeliverable -> emptyList()
|
||||
}
|
||||
giftInfoTitle.isVisible = rows.isNotEmpty()
|
||||
giftInfo.isVisible = rows.isNotEmpty()
|
||||
GiftInfoRows.bind(giftInfo, rows.map { it.label to resolveGiftDetailText(it.value) })
|
||||
sectionSeparator.isVisible = received is GiftDetailReceived.Delivered || received is GiftDetailReceived.Undeliverable
|
||||
if (received is GiftDetailReceived.Undeliverable) {
|
||||
normalSections.removeView(sectionSeparator)
|
||||
normalSections.addView(sectionSeparator, normalSections.indexOfChild(undeliverableReasonHeader))
|
||||
}
|
||||
if (form) {
|
||||
heroChip.isVisible = false
|
||||
heroTitle.isVisible = false
|
||||
heroBody.isVisible = false
|
||||
}
|
||||
val address = when (received) {
|
||||
is GiftDetailReceived.AddressCompleted -> received.recipientAddress
|
||||
is GiftDetailReceived.Delivered -> received.recipientAddress
|
||||
else -> null
|
||||
}
|
||||
recipientSection.isVisible = address != null
|
||||
receivedAddressSeparator.isVisible = address != null
|
||||
bindAddress(recipientAddress, address)
|
||||
}
|
||||
|
||||
private fun giftInfoRows(model: GiftDetailUiModel): List<Pair<Int, String?>> = with(model.giftInfo) {
|
||||
@@ -263,6 +425,9 @@ internal fun Context.resolveGiftDetailText(text: GiftDetailText): String = when
|
||||
Key.CANCELED_TITLE -> R.string.gift_detail_canceled_title
|
||||
Key.CANCELED_BODY -> R.string.gift_detail_canceled_body
|
||||
Key.DISPOSAL_NON_RETURN_GUIDANCE -> R.string.gift_detail_disposal_guidance
|
||||
Key.RECIPIENT_ADDRESS_COMPLETED_TITLE -> R.string.gift_recipient_address_completed_title
|
||||
Key.RECIPIENT_DELIVERED_TITLE -> R.string.gift_recipient_delivered_title
|
||||
Key.RECIPIENT_ADDRESS_REMOVAL_GUIDANCE -> R.string.gift_recipient_address_removal_guidance
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,11 @@ package kr.co.vividnext.sodalive.v2.gift
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.Parcel
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.children
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import io.reactivex.rxjava3.android.plugins.RxAndroidPlugins
|
||||
@@ -20,7 +24,11 @@ import kr.co.vividnext.sodalive.v2.gift.data.GiftAddressResponse
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftDeliveryResponse
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftDetailInfoResponse
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftDetailResponse
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftInboxResponse
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftRepository
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftRecipientAddressRequest
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftRecipientAddressResponse
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftStatusTimelineResponse
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftTrackingRequest
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftTrackingResponse
|
||||
import org.junit.After
|
||||
@@ -29,6 +37,8 @@ import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertSame
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
@@ -46,6 +56,7 @@ import org.koin.dsl.module
|
||||
@Config(sdk = [28], application = Application::class)
|
||||
class GiftNavigationTest {
|
||||
private lateinit var api: NavigationFakeApi
|
||||
private lateinit var inboxApi: InboxFakeApi
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
@@ -55,12 +66,15 @@ class GiftNavigationTest {
|
||||
SharedPreferenceManager.resetForTest()
|
||||
SharedPreferenceManager.init(ApplicationProvider.getApplicationContext())
|
||||
api = NavigationFakeApi()
|
||||
inboxApi = InboxFakeApi()
|
||||
startKoin {
|
||||
modules(
|
||||
module {
|
||||
viewModel { GiftInboxViewModel(GiftRepository(inboxApi)) }
|
||||
viewModel { GiftDetailViewModel(GiftRepository(api)) }
|
||||
viewModel { GiftTrackingViewModel(GiftRepository(api)) }
|
||||
viewModel { GiftCancelViewModel(GiftRepository(api)) }
|
||||
viewModel { GiftRecipientAddressViewModel(GiftRepository(api)) }
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -74,6 +88,312 @@ class GiftNavigationTest {
|
||||
SharedPreferenceManager.resetForTest()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `받은 선물 진입 후 주소 성공은 같은 상세를 한 번 재조회하고 완료 결과로 목록을 갱신한다`() {
|
||||
val item = inboxItem(direction = "RECEIVED", status = "TRACKING_REGISTERED")
|
||||
inboxApi.responses.add(Single.just(ApiResponse(true, GiftInboxResponse(1, listOf(item), 0, 20, false), null)))
|
||||
val parent = Robolectric.buildActivity(GiftInboxActivity::class.java).setup()
|
||||
val inbox = parent.get()
|
||||
ViewModelProvider(inbox)[GiftInboxViewModel::class.java].onCardClick(GiftInboxPresenter.toCard(item))
|
||||
val launched = shadowOf(inbox).nextStartedActivityForResult
|
||||
assertEquals(GiftDetailActivity::class.java.name, launched.intent.component?.className)
|
||||
assertEquals(item.applicationNo, launched.intent.getStringExtra(GiftDetailActivity.EXTRA_APPLICATION_NO))
|
||||
assertEquals(setOf(GiftDetailActivity.EXTRA_APPLICATION_NO), launched.intent.extras?.keySet())
|
||||
api.direction = "RECEIVED"
|
||||
api.detailStatus = "TRACKING_REGISTERED"
|
||||
val controller = Robolectric.buildActivity(GiftDetailActivity::class.java, launched.intent).setup()
|
||||
val activity = controller.get()
|
||||
val detail = ViewModelProvider(activity)[GiftDetailViewModel::class.java]
|
||||
val initial = (detail.state.value as GiftDetailUiState.Content).detail
|
||||
assertTrue(GiftDetailPresenter.present(initial).received is GiftDetailReceived.AddressForm)
|
||||
val recipient = ViewModelProvider(activity)[GiftRecipientAddressViewModel::class.java]
|
||||
recipient.updateForm(GiftRecipientAddressFormState("수령인", "01012345678", "12345", "입력 주소", "상세", true, true))
|
||||
val refreshed = initial.copy(
|
||||
recipientAddressRequired = false,
|
||||
recipientAddress = GiftAddressResponse("서버 수령인", "01087654321", "서버 배송 주소")
|
||||
)
|
||||
val response = SingleSubject.create<ApiResponse<GiftDetailResponse>>()
|
||||
api.nextDetailResponse = response
|
||||
activity.binding.receive.performClick()
|
||||
api.recipientResponse.onSuccess(
|
||||
ApiResponse(true, GiftRecipientAddressResponse(item.applicationNo, "ADDRESS_REGISTERED", "완료", "2026-10-02"), null)
|
||||
)
|
||||
assertEquals(listOf(item.applicationNo, item.applicationNo), api.requests)
|
||||
assertEquals(GiftDetailUiState.Loading, detail.state.value)
|
||||
assertFalse(recipient.recipientAddressSuccessLiveData.value!!)
|
||||
assertFalse(recipient.consumeRecipientAddressSuccessEvent())
|
||||
assertEquals(Activity.RESULT_OK, shadowOf(activity).resultCode)
|
||||
assertNull(shadowOf(activity).resultIntent)
|
||||
response.onSuccess(ApiResponse(true, refreshed, null))
|
||||
assertEquals(GiftDetailUiState.Content(refreshed), detail.state.value)
|
||||
assertTrue(GiftDetailPresenter.present(refreshed).received is GiftDetailReceived.AddressCompleted)
|
||||
assertEquals(
|
||||
listOf("서버 수령인", "01087654321", "서버 배송 주소"),
|
||||
activity.binding.recipientAddress.children.map { it.findViewById<TextView>(R.id.value).text.toString() }.toList()
|
||||
)
|
||||
val savedState = Bundle()
|
||||
controller.saveInstanceState(savedState)
|
||||
assertTrue(savedState.getBoolean("STATE_CHANGED"))
|
||||
assertEquals(setOf("STATE_CHANGED"), savedState.keySet().filterNot { it.startsWith("android") }.toSet())
|
||||
val parcel = Parcel.obtain()
|
||||
try {
|
||||
parcel.writeBundle(savedState)
|
||||
val persisted = String(parcel.marshall(), Charsets.UTF_16LE)
|
||||
listOf("01012345678", "입력 주소", "01087654321", "서버 배송 주소", "GiftDetailResponse", "GiftRecipientAddress")
|
||||
.forEach { assertFalse("개인정보나 DTO를 저장하면 안 된다: $it", persisted.contains(it)) }
|
||||
} finally {
|
||||
parcel.recycle()
|
||||
}
|
||||
val recreated = controller.recreate().get()
|
||||
assertEquals(listOf(item.applicationNo, item.applicationNo), api.requests)
|
||||
assertEquals(1, api.recipientSubmissions.size)
|
||||
recreated.binding.btnBack.performClick()
|
||||
assertEquals(Activity.RESULT_OK, shadowOf(recreated).resultCode)
|
||||
assertNull(shadowOf(recreated).resultIntent)
|
||||
listOf(Activity.RESULT_CANCELED, Activity.RESULT_FIRST_USER).forEach { resultCode ->
|
||||
inbox.activityResultRegistry.dispatchResult(launched.requestCode, resultCode, null)
|
||||
assertEquals(1, inboxApi.requests.size)
|
||||
ViewModelProvider(inbox)[GiftInboxViewModel::class.java].onCardClick(GiftInboxPresenter.toCard(item))
|
||||
assertEquals(launched.requestCode, shadowOf(inbox).nextStartedActivityForResult.requestCode)
|
||||
}
|
||||
inboxApi.responses.add(Single.just(ApiResponse(true, GiftInboxResponse(0, emptyList(), 0, 20, false), null)))
|
||||
inbox.activityResultRegistry.dispatchResult(launched.requestCode, shadowOf(recreated).resultCode, null)
|
||||
assertEquals(listOf(0, 0), inboxApi.requests.map { it.page })
|
||||
assertEquals(GiftInboxUiState.Empty, ViewModelProvider(inbox)[GiftInboxViewModel::class.java].state.value)
|
||||
controller.pause().stop().destroy()
|
||||
parent.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "ko")
|
||||
fun `받은 선물 폼 입력과 동의는 제출되고 실패 뒤 재시도 성공 토스트는 소비된다`() {
|
||||
api.direction = "RECEIVED"
|
||||
api.detailStatus = "TRACKING_REGISTERED"
|
||||
val controller = Robolectric.buildActivity(
|
||||
GiftDetailActivity::class.java,
|
||||
GiftDetailActivity.newIntent(ApplicationProvider.getApplicationContext(), "recipient-gift")
|
||||
).setup()
|
||||
val activity = controller.get()
|
||||
val recipient = ViewModelProvider(activity)[GiftRecipientAddressViewModel::class.java]
|
||||
with(activity.binding) {
|
||||
assertEquals(activity.getString(R.string.gift_recipient_receive), header.text.toString())
|
||||
assertFalse(receive.isEnabled)
|
||||
etRecipientName.setText("수령인")
|
||||
etPhoneNumber.setText("01012345678")
|
||||
etDetailAddress.setText("상세 주소")
|
||||
cbTerms.isChecked = true
|
||||
cbPrivacy.isChecked = true
|
||||
btnPostcodeSearch.performClick()
|
||||
val launched = shadowOf(activity).nextStartedActivityForResult
|
||||
activity.activityResultRegistry.dispatchResult(
|
||||
launched.requestCode,
|
||||
Activity.RESULT_OK,
|
||||
Intent().putExtra(KakaoPostcodeSearchActivity.EXTRA_ZONE_CODE, "12345")
|
||||
.putExtra(KakaoPostcodeSearchActivity.EXTRA_ADDRESS, "배송 주소")
|
||||
)
|
||||
assertTrue(receive.isEnabled)
|
||||
val form = recipient.formState.value!!
|
||||
receive.performClick()
|
||||
assertFalse(receive.isEnabled)
|
||||
assertEquals(listOf("recipient-gift" to form.toRequest()), api.recipientSubmissions)
|
||||
api.recipientResponse.onSuccess(ApiResponse(false, null, "주소 등록 실패"))
|
||||
assertEquals("주소 등록 실패", ShadowToast.getTextOfLatestToast())
|
||||
assertNull(recipient.toastLiveData.value)
|
||||
assertSame(form, recipient.formState.value)
|
||||
assertTrue(receive.isEnabled)
|
||||
assertEquals(listOf("recipient-gift"), api.requests)
|
||||
assertEquals(Activity.RESULT_CANCELED, shadowOf(activity).resultCode)
|
||||
assertNull(shadowOf(activity).resultIntent)
|
||||
assertFalse(recipient.recipientAddressSuccessLiveData.value!!)
|
||||
api.recipientResponse = SingleSubject.create()
|
||||
receive.performClick()
|
||||
api.recipientResponse.onSuccess(
|
||||
ApiResponse(true, GiftRecipientAddressResponse("recipient-gift", "ADDRESS_REGISTERED", "완료", "2026-10-02"), null)
|
||||
)
|
||||
assertEquals(activity.getString(R.string.gift_recipient_address_success), ShadowToast.getTextOfLatestToast())
|
||||
assertNull(recipient.toastLiveData.value)
|
||||
assertFalse(recipient.recipientAddressSuccessLiveData.value!!)
|
||||
}
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `주소 폼에서 로딩과 오류로 전환하면 추가 제출되지 않는다`() {
|
||||
api.direction = "RECEIVED"
|
||||
api.detailStatus = "TRACKING_REGISTERED"
|
||||
val controller = Robolectric.buildActivity(
|
||||
GiftDetailActivity::class.java,
|
||||
GiftDetailActivity.newIntent(ApplicationProvider.getApplicationContext(), "transition-gift")
|
||||
).setup()
|
||||
val activity = controller.get()
|
||||
val recipient = ViewModelProvider(activity)[GiftRecipientAddressViewModel::class.java]
|
||||
recipient.updateForm(GiftRecipientAddressFormState("수령인", "01012345678", "12345", "주소", "상세", true, true))
|
||||
activity.binding.receive.performClick()
|
||||
val response = SingleSubject.create<ApiResponse<GiftDetailResponse>>()
|
||||
api.nextDetailResponse = response
|
||||
ViewModelProvider(activity)[GiftDetailViewModel::class.java].retry()
|
||||
api.recipientResponse.onSuccess(ApiResponse(false, null, "실패"))
|
||||
api.recipientResponse = SingleSubject.create()
|
||||
assertFalse(activity.binding.receive.isEnabled)
|
||||
activity.binding.receive.performClick()
|
||||
assertEquals(1, api.recipientSubmissions.size)
|
||||
response.onSuccess(ApiResponse(false, null, "상세 오류"))
|
||||
recipient.updateForm(recipient.formState.value!!.copy(recipientAddressDetail = "수정"))
|
||||
assertFalse(activity.binding.receive.isEnabled)
|
||||
activity.binding.receive.performClick()
|
||||
assertEquals(1, api.recipientSubmissions.size)
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `전달 불가에서 다른 상세로 전환하면 정보 행과 제목을 복원한다`() {
|
||||
listOf("SENT" to "TRACKING_REGISTERED", "RECEIVED" to "TRACKING_REGISTERED", "RECEIVED" to "DELIVERED").forEach {
|
||||
(direction, status) ->
|
||||
api.direction = "RECEIVED"
|
||||
api.detailStatus = "UNDELIVERABLE"
|
||||
api.recipientAddressRequired = false
|
||||
val controller = Robolectric.buildActivity(
|
||||
GiftDetailActivity::class.java,
|
||||
GiftDetailActivity.newIntent(ApplicationProvider.getApplicationContext(), "transition-gift")
|
||||
).setup()
|
||||
val activity = controller.get()
|
||||
api.direction = direction
|
||||
api.detailStatus = status
|
||||
ViewModelProvider(activity)[GiftDetailViewModel::class.java].retry()
|
||||
assertTrue(activity.binding.giftInfo.children.any { it.findViewById<TextView>(R.id.value).text == "소형" })
|
||||
with(activity.binding) {
|
||||
assertEquals(
|
||||
activity.getString(
|
||||
if (direction == "SENT") R.string.gift_detail_title else R.string.gift_recipient_detail_title
|
||||
),
|
||||
header.text.toString()
|
||||
)
|
||||
}
|
||||
val recipient = ViewModelProvider(activity)[GiftRecipientAddressViewModel::class.java]
|
||||
recipient.updateForm(GiftRecipientAddressFormState("수령인", "01012345678", "12345", "주소", "", true, true))
|
||||
val before = api.recipientSubmissions.size
|
||||
activity.binding.receive.performClick()
|
||||
assertEquals(before, api.recipientSubmissions.size)
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "ko")
|
||||
fun `수신 완료 상세 제목은 선물 상세이며 발신 상세 제목은 신청 상세를 유지한다`() {
|
||||
api.recipientAddressRequired = false
|
||||
listOf("SENT", "RECEIVED").forEach { direction ->
|
||||
api.direction = direction
|
||||
listOf("TRACKING_REGISTERED", "DELIVERED", "UNDELIVERABLE").forEach { status ->
|
||||
api.detailStatus = status
|
||||
val controller = Robolectric.buildActivity(
|
||||
GiftDetailActivity::class.java,
|
||||
GiftDetailActivity.newIntent(ApplicationProvider.getApplicationContext(), "title-gift")
|
||||
).setup()
|
||||
val activity = controller.get()
|
||||
assertEquals(if (direction == "RECEIVED") "선물 상세" else "신청 상세", activity.binding.header.text.toString())
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `받은 선물 완료 상태는 모델의 정보 행과 본인 주소 및 전달 안내를 연결한다`() {
|
||||
api.direction = "RECEIVED"
|
||||
api.recipientAddressRequired = false
|
||||
listOf("TRACKING_REGISTERED", "DELIVERED").forEach { status ->
|
||||
listOf(null, GiftAddressResponse("수령인", "01012345678", "배송 주소")).forEach { address ->
|
||||
api.detailStatus = status
|
||||
api.recipientAddress = address
|
||||
val controller = Robolectric.buildActivity(
|
||||
GiftDetailActivity::class.java,
|
||||
GiftDetailActivity.newIntent(ApplicationProvider.getApplicationContext(), "completed-gift")
|
||||
).setup()
|
||||
val activity = controller.get()
|
||||
val values = activity.binding.giftInfo.children.map {
|
||||
it.findViewById<TextView>(R.id.value).text.toString()
|
||||
}.toList()
|
||||
assertEquals(
|
||||
listOf("보낸 사람", "소형", "도서", "2026.10.01") + if (status == "DELIVERED") listOf("2026.10.02") else emptyList(),
|
||||
values
|
||||
)
|
||||
val addressValues = activity.binding.recipientAddress.children.map {
|
||||
it.findViewById<TextView>(R.id.value).text.toString()
|
||||
}.toList()
|
||||
assertEquals(address?.let { listOf(it.name, it.phoneNumber, it.address) }.orEmpty(), addressValues)
|
||||
assertEquals(
|
||||
if (status == "DELIVERED" && address != null) {
|
||||
activity.getString(R.string.gift_recipient_address_removal_guidance)
|
||||
} else {
|
||||
""
|
||||
},
|
||||
activity.binding.recipientGuidance.text.toString()
|
||||
)
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `받은 선물 전달 불가 정책은 토스트만 표시하고 문의는 기존 경로로 이동한다`() {
|
||||
api.direction = "RECEIVED"
|
||||
api.detailStatus = "UNDELIVERABLE"
|
||||
val controller = Robolectric.buildActivity(
|
||||
GiftDetailActivity::class.java,
|
||||
GiftDetailActivity.newIntent(ApplicationProvider.getApplicationContext(), "undeliverable-gift")
|
||||
).setup()
|
||||
val activity = controller.get()
|
||||
activity.binding.policy.performClick()
|
||||
assertEquals(activity.getString(R.string.creator_channel_more_ready), ShadowToast.getTextOfLatestToast())
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
assertNull(ViewModelProvider(activity)[GiftDetailViewModel::class.java].toastLiveData.value)
|
||||
activity.binding.receivedInquiry.performClick()
|
||||
assertEquals("http://pf.kakao.com/_lkxgxhG/chat", shadowOf(activity).nextStartedActivity.data.toString())
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `받은 선물 우편번호 성공은 주소만 변경하고 상세 주소에 포커스를 요청한다`() {
|
||||
verifyRecipientPostcodeResult(Activity.RESULT_OK)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `받은 선물 우편번호 취소와 실패는 기존 입력과 동의 객체를 유지한다`() {
|
||||
listOf(Activity.RESULT_CANCELED, Activity.RESULT_FIRST_USER).forEach(::verifyRecipientPostcodeResult)
|
||||
}
|
||||
|
||||
private fun verifyRecipientPostcodeResult(resultCode: Int) {
|
||||
api.direction = "RECEIVED"
|
||||
api.detailStatus = "TRACKING_REGISTERED"
|
||||
val controller = Robolectric.buildActivity(
|
||||
GiftDetailActivity::class.java,
|
||||
GiftDetailActivity.newIntent(ApplicationProvider.getApplicationContext(), "recipient-gift")
|
||||
).setup()
|
||||
val activity = controller.get()
|
||||
val search = activity.findViewById<View>(R.id.btn_postcode_search)
|
||||
assertNotNull("받은 선물 주소 검색 연결이 필요하다", search)
|
||||
val recipient = ViewModelProvider(activity)[GiftRecipientAddressViewModel::class.java]
|
||||
val original = GiftRecipientAddressFormState("수령인", "01012345678", "11111", "기존 주소", "상세", true, true)
|
||||
recipient.updateForm(original)
|
||||
search.performClick()
|
||||
val launched = shadowOf(activity).nextStartedActivityForResult
|
||||
assertEquals(KakaoPostcodeSearchActivity::class.java.name, launched.intent.component?.className)
|
||||
assertTrue(launched.intent.extras == null || launched.intent.extras!!.isEmpty)
|
||||
activity.activityResultRegistry.dispatchResult(
|
||||
launched.requestCode,
|
||||
resultCode,
|
||||
Intent().putExtra(KakaoPostcodeSearchActivity.EXTRA_ZONE_CODE, "22222")
|
||||
.putExtra(KakaoPostcodeSearchActivity.EXTRA_ADDRESS, "새 주소")
|
||||
)
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
assertEquals(original.copy(recipientZipCode = "22222", recipientAddress = "새 주소"), recipient.formState.value)
|
||||
assertTrue(activity.findViewById<View>(R.id.et_detail_address).hasFocus())
|
||||
} else {
|
||||
assertSame(original, recipient.formState.value)
|
||||
}
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `양쪽 취소 dialog는 실패를 유지하고 성공만 닫아 취소 결과와 목록 갱신을 전달한다`() {
|
||||
listOf(false, true).forEach { tracking ->
|
||||
@@ -331,6 +651,18 @@ class GiftNavigationTest {
|
||||
val cancelRequests = mutableListOf<String>()
|
||||
var cancelResponse = SingleSubject.create<ApiResponse<GiftCancelResponse>>()
|
||||
var detailStatus = "RECEIVED"
|
||||
var direction = "SENT"
|
||||
var recipientAddressRequired = true
|
||||
var recipientAddress: GiftAddressResponse? = null
|
||||
val recipientSubmissions = mutableListOf<Pair<String, GiftRecipientAddressRequest>>()
|
||||
var recipientResponse = SingleSubject.create<ApiResponse<GiftRecipientAddressResponse>>()
|
||||
override fun registerRecipientAddress(
|
||||
applicationNo: String,
|
||||
request: GiftRecipientAddressRequest,
|
||||
authHeader: String
|
||||
): Single<ApiResponse<GiftRecipientAddressResponse>> = recipientResponse.also {
|
||||
recipientSubmissions.add(applicationNo to request)
|
||||
}
|
||||
var nextDetailResponse: Single<ApiResponse<GiftDetailResponse>>? = null
|
||||
override fun cancelGift(applicationNo: String, authHeader: String): Single<ApiResponse<GiftCancelResponse>> =
|
||||
cancelResponse.also { cancelRequests.add(applicationNo) }
|
||||
@@ -342,11 +674,12 @@ class GiftNavigationTest {
|
||||
ApiResponse(
|
||||
true,
|
||||
GiftDetailResponse(
|
||||
applicationNo, "SENT", detailStatus, "접수 완료",
|
||||
GiftDetailInfoResponse("테스트", null, "소형", "도서", applicationNo, 100, null, null),
|
||||
null, null,
|
||||
applicationNo, direction, detailStatus, "접수 완료",
|
||||
GiftDetailInfoResponse("테스트", "보낸 사람", "소형", "도서", applicationNo, 100, null, "2026-10-01T00:00:00Z"),
|
||||
null, recipientAddress,
|
||||
if (applicationNo == "missing-mailbox") null else GiftAddressResponse("테스트 사서함", "000", "테스트 주소"),
|
||||
true, false, null, GiftDeliveryResponse(null, null, null), emptyList()
|
||||
true, direction == "RECEIVED" && recipientAddressRequired, null, GiftDeliveryResponse(null, null, null),
|
||||
listOf(GiftStatusTimelineResponse("DELIVERED", "전달 완료", "2026-10-02T00:00:00Z"))
|
||||
),
|
||||
null
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user