fix(content): 전체 탭 정렬 값을 보정한다
This commit is contained in:
@@ -17,6 +17,7 @@ import kr.co.vividnext.sodalive.v2.main.content.data.MainContentAllTabResponse
|
||||
import kr.co.vividnext.sodalive.v2.main.content.data.MainContentAllType
|
||||
import kr.co.vividnext.sodalive.v2.main.content.model.MainContentAllTabUiState
|
||||
import kr.co.vividnext.sodalive.v2.main.content.model.currentDeviceDayOfWeek
|
||||
import kr.co.vividnext.sodalive.v2.main.content.model.normalizeContentAllSort
|
||||
import kr.co.vividnext.sodalive.v2.main.content.model.toContent
|
||||
import kr.co.vividnext.sodalive.v2.main.content.model.toUiModel
|
||||
import kr.co.vividnext.sodalive.v2.main.content.model.usesDayOfWeekQuery
|
||||
@@ -54,20 +55,21 @@ class ContentAllTabViewModel(
|
||||
|
||||
fun changeType(type: MainContentAllType) {
|
||||
selectedType = type
|
||||
selectedSort = type.normalizeContentAllSort(selectedSort)
|
||||
selectedDayOfWeek = selectedDayOfWeekFor(type)
|
||||
loadFirstPage(type, selectedSort, selectedDayOfWeek)
|
||||
}
|
||||
|
||||
fun changeSort(sort: ContentSort) {
|
||||
selectedSort = sort
|
||||
loadFirstPage(selectedType, sort, selectedDayOfWeekFor(selectedType))
|
||||
selectedSort = selectedType.normalizeContentAllSort(sort)
|
||||
loadFirstPage(selectedType, selectedSort, selectedDayOfWeekFor(selectedType))
|
||||
}
|
||||
|
||||
fun selectTypeAndSort(type: MainContentAllType, sort: ContentSort) {
|
||||
selectedType = type
|
||||
selectedSort = sort
|
||||
selectedSort = type.normalizeContentAllSort(sort)
|
||||
selectedDayOfWeek = selectedDayOfWeekFor(type)
|
||||
loadFirstPage(type, sort, selectedDayOfWeek)
|
||||
loadFirstPage(type, selectedSort, selectedDayOfWeek)
|
||||
}
|
||||
|
||||
fun changeDayOfWeek(dayOfWeek: SeriesPublishedDaysOfWeek) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package kr.co.vividnext.sodalive.v2.main.content.model
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.v2.common.data.ContentSort
|
||||
import kr.co.vividnext.sodalive.v2.main.content.data.MainContentAllType
|
||||
import kr.co.vividnext.sodalive.v2.widget.AudioContentTag
|
||||
|
||||
@@ -47,3 +48,24 @@ fun MainContentAllType.usesSeriesItems(): Boolean = when (this) {
|
||||
}
|
||||
|
||||
fun MainContentAllType.usesDayOfWeekQuery(): Boolean = this == MainContentAllType.SERIES
|
||||
|
||||
fun MainContentAllType.contentAllSortOptions(): List<ContentSort> = when (this) {
|
||||
MainContentAllType.FREE -> listOf(
|
||||
ContentSort.LATEST,
|
||||
ContentSort.POPULAR
|
||||
)
|
||||
|
||||
MainContentAllType.AUDIO,
|
||||
MainContentAllType.SERIES,
|
||||
MainContentAllType.ORIGINAL,
|
||||
MainContentAllType.POINT -> listOf(
|
||||
ContentSort.LATEST,
|
||||
ContentSort.POPULAR,
|
||||
ContentSort.PRICE_HIGH,
|
||||
ContentSort.PRICE_LOW
|
||||
)
|
||||
}
|
||||
|
||||
fun MainContentAllType.normalizeContentAllSort(sort: ContentSort): ContentSort {
|
||||
return if (sort in contentAllSortOptions()) sort else ContentSort.LATEST
|
||||
}
|
||||
|
||||
@@ -260,6 +260,37 @@ class ContentAllTabViewModelTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `외부 FREE 선택 요청의 가격 정렬은 LATEST로 보정한다`() {
|
||||
stubGetContents(
|
||||
type = MainContentAllType.FREE,
|
||||
sort = ContentSort.LATEST,
|
||||
response = Single.just(
|
||||
ApiResponse(
|
||||
true,
|
||||
response(
|
||||
type = MainContentAllType.FREE,
|
||||
sort = ContentSort.LATEST,
|
||||
audios = listOf(audio(32L))
|
||||
),
|
||||
null
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
viewModel.selectTypeAndSort(MainContentAllType.FREE, ContentSort.PRICE_LOW)
|
||||
|
||||
val state = viewModel.allTabStateLiveData.requireValue() as MainContentAllTabUiState.Content
|
||||
assertEquals(MainContentAllType.FREE, state.selectedType)
|
||||
assertEquals(ContentSort.LATEST, state.selectedSort)
|
||||
verifyGetContents(
|
||||
type = MainContentAllType.FREE,
|
||||
sort = ContentSort.LATEST,
|
||||
page = 0,
|
||||
dayOfWeek = null
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `외부 선택 요청은 ORIGINAL LATEST 첫 페이지를 dayOfWeek 없이 요청한다`() {
|
||||
stubGetContents(
|
||||
@@ -291,6 +322,80 @@ class ContentAllTabViewModelTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `무료 타입 변경은 이전 가격 정렬을 LATEST로 보정한다`() {
|
||||
stubGetContents(
|
||||
sort = ContentSort.PRICE_HIGH,
|
||||
response = Single.just(
|
||||
ApiResponse(
|
||||
true,
|
||||
response(
|
||||
sort = ContentSort.PRICE_HIGH,
|
||||
audios = listOf(audio(33L))
|
||||
),
|
||||
null
|
||||
)
|
||||
)
|
||||
)
|
||||
stubGetContents(
|
||||
type = MainContentAllType.FREE,
|
||||
sort = ContentSort.LATEST,
|
||||
response = Single.just(
|
||||
ApiResponse(
|
||||
true,
|
||||
response(
|
||||
type = MainContentAllType.FREE,
|
||||
sort = ContentSort.LATEST,
|
||||
audios = listOf(audio(34L))
|
||||
),
|
||||
null
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
viewModel.changeSort(ContentSort.PRICE_HIGH)
|
||||
viewModel.changeType(MainContentAllType.FREE)
|
||||
|
||||
val state = viewModel.allTabStateLiveData.requireValue() as MainContentAllTabUiState.Content
|
||||
assertEquals(MainContentAllType.FREE, state.selectedType)
|
||||
assertEquals(ContentSort.LATEST, state.selectedSort)
|
||||
verifyGetContents(
|
||||
type = MainContentAllType.FREE,
|
||||
sort = ContentSort.LATEST,
|
||||
page = 0,
|
||||
dayOfWeek = null
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `소장순 정렬 변경은 LATEST로 보정한다`() {
|
||||
stubGetContents(
|
||||
sort = ContentSort.LATEST,
|
||||
response = Single.just(
|
||||
ApiResponse(
|
||||
true,
|
||||
response(
|
||||
sort = ContentSort.LATEST,
|
||||
audios = listOf(audio(35L))
|
||||
),
|
||||
null
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
viewModel.changeSort(ContentSort.OWNED)
|
||||
|
||||
val state = viewModel.allTabStateLiveData.requireValue() as MainContentAllTabUiState.Content
|
||||
assertEquals(MainContentAllType.AUDIO, state.selectedType)
|
||||
assertEquals(ContentSort.LATEST, state.selectedSort)
|
||||
verifyGetContents(
|
||||
type = MainContentAllType.AUDIO,
|
||||
sort = ContentSort.LATEST,
|
||||
page = 0,
|
||||
dayOfWeek = null
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `SERIES에서 요일 변경은 변경 요일과 page 0으로 요청한다`() {
|
||||
stubGetContents(response = Single.just(ApiResponse(true, response(), null)))
|
||||
|
||||
@@ -6,6 +6,7 @@ import kr.co.vividnext.sodalive.v2.main.content.data.MainContentAllTabResponse
|
||||
import kr.co.vividnext.sodalive.v2.main.content.data.MainContentAllType
|
||||
import kr.co.vividnext.sodalive.v2.main.content.data.MainContentAudioResponse
|
||||
import kr.co.vividnext.sodalive.v2.main.content.data.MainContentSeriesResponse
|
||||
import kr.co.vividnext.sodalive.v2.main.content.model.contentAllSortOptions
|
||||
import kr.co.vividnext.sodalive.v2.main.content.model.toContent
|
||||
import kr.co.vividnext.sodalive.v2.main.content.model.usesDayOfWeekQuery
|
||||
import kr.co.vividnext.sodalive.v2.main.content.model.usesSeriesItems
|
||||
@@ -92,6 +93,21 @@ class MainContentAllTabMapperTest {
|
||||
assertTrue(content.hasNext)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `전체 탭 정렬 옵션은 소장순을 제외한다`() {
|
||||
MainContentAllType.entries.forEach { type ->
|
||||
assertFalse(ContentSort.OWNED in type.contentAllSortOptions())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `무료 타입 정렬 옵션은 가격순을 제외한다`() {
|
||||
assertEquals(
|
||||
listOf(ContentSort.LATEST, ContentSort.POPULAR),
|
||||
MainContentAllType.FREE.contentAllSortOptions()
|
||||
)
|
||||
}
|
||||
|
||||
private fun response(
|
||||
type: MainContentAllType = MainContentAllType.AUDIO,
|
||||
totalCount: Int = 1,
|
||||
|
||||
Reference in New Issue
Block a user