feat(gift): 상세 재조회와 정책 처리를 추가한다
This commit is contained in:
@@ -28,6 +28,8 @@ class GiftDetailViewModel(private val repository: GiftRepository) : BaseViewMode
|
||||
val finishErrorLiveData: LiveData<ToastMessage?> = mutableFinishError
|
||||
private val mutableInquiry = MutableLiveData(false)
|
||||
val inquiryLiveData: LiveData<Boolean> = mutableInquiry
|
||||
private val mutableToast = MutableLiveData<ToastMessage?>()
|
||||
val toastLiveData: LiveData<ToastMessage?> = mutableToast
|
||||
private var applicationNo: String? = null
|
||||
private var pendingCancellation: GiftCancelResponse? = null
|
||||
|
||||
@@ -47,6 +49,10 @@ class GiftDetailViewModel(private val repository: GiftRepository) : BaseViewMode
|
||||
load(number)
|
||||
}
|
||||
|
||||
fun reloadAfterRecipientAddressSuccess() {
|
||||
retry()
|
||||
}
|
||||
|
||||
fun consumeFinishError(): ToastMessage? = mutableFinishError.value.also { mutableFinishError.value = null }
|
||||
|
||||
fun applyCancellation(cancel: GiftCancelResponse) {
|
||||
@@ -66,6 +72,12 @@ class GiftDetailViewModel(private val repository: GiftRepository) : BaseViewMode
|
||||
mutableInquiry.value = true
|
||||
}
|
||||
|
||||
fun onPolicyClick() {
|
||||
mutableToast.value = ToastMessage(resId = R.string.creator_channel_more_ready)
|
||||
}
|
||||
|
||||
fun consumeToast(): ToastMessage? = mutableToast.value.also { mutableToast.value = null }
|
||||
|
||||
fun consumeInquiryIntent(): Intent? {
|
||||
if (mutableInquiry.value != true) return null
|
||||
mutableInquiry.value = false
|
||||
|
||||
@@ -13,6 +13,7 @@ import io.reactivex.rxjava3.subjects.SingleSubject
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||
import kr.co.vividnext.sodalive.common.ToastMessage
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftApi
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftCancelResponse
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftDeliveryResponse
|
||||
@@ -223,6 +224,39 @@ class GiftDetailViewModelTest {
|
||||
assertEquals(false, viewModel.inquiryLiveData.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `배송지 입력 성공 재조회는 최초 조회 후 같은 신청으로만 실행하고 로딩 중 중복하지 않는다`() {
|
||||
viewModel.reloadAfterRecipientAddressSuccess()
|
||||
assertTrue(api.requests.isEmpty())
|
||||
api.responses.add(Single.just(ApiResponse(true, detail(), null)))
|
||||
val pending = SingleSubject.create<ApiResponse<GiftDetailResponse>>()
|
||||
api.responses.add(pending)
|
||||
viewModel.loadInitial("test-gift")
|
||||
|
||||
viewModel.reloadAfterRecipientAddressSuccess()
|
||||
viewModel.reloadAfterRecipientAddressSuccess()
|
||||
|
||||
assertEquals(GiftDetailUiState.Loading, viewModel.state.value)
|
||||
assertEquals(
|
||||
listOf("test-gift" to "Bearer test-token", "test-gift" to "Bearer test-token"),
|
||||
api.requests
|
||||
)
|
||||
pending.onSuccess(ApiResponse(true, detail("TRACKING_REGISTERED"), null))
|
||||
assertEquals(GiftDetailUiState.Content(detail("TRACKING_REGISTERED")), viewModel.state.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `선물 정책 action은 외부 intent 없이 준비 중 toast를 한 번만 보낸다`() {
|
||||
assertNull(viewModel.consumeToast())
|
||||
|
||||
viewModel.onPolicyClick()
|
||||
|
||||
assertEquals(ToastMessage(resId = R.string.creator_channel_more_ready), viewModel.toastLiveData.value)
|
||||
assertEquals(ToastMessage(resId = R.string.creator_channel_more_ready), viewModel.consumeToast())
|
||||
assertNull(viewModel.consumeToast())
|
||||
assertNull(viewModel.consumeInquiryIntent())
|
||||
}
|
||||
|
||||
private fun detail(status: String = "RECEIVED") = GiftDetailResponse(
|
||||
applicationNo = "test-gift", direction = "SENT", status = status, statusName = "상태",
|
||||
giftInfo = GiftDetailInfoResponse("가상 크리에이터", null, "소형", "도서", "test-gift", 100, null, null),
|
||||
|
||||
Reference in New Issue
Block a user