Skip to content

Commit

Permalink
feat: add ability to sort by rating (#690)
Browse files Browse the repository at this point in the history
* feat: add ability to sort by rating

* test: fix copy/paste error on sort by rating function name
  • Loading branch information
tlaporte authored Dec 6, 2021
1 parent 676bfcf commit 5d0cafe
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,27 @@ class SortTests : UITest() {
)
}
}

@Test
fun sortOptionRatingSortsInRatingOrder() {
launchActivity()

seriesList {
sortSeries {
open()
selectByRating()
}
} validate {
isInOrder(
listOf(
seriesData.series2.title,
seriesData.series1.title,
seriesData.series3.title,
seriesData.series0.title
)
)
}
}
}

// Make an initial set of series items to compare sort with.
Expand All @@ -145,7 +166,8 @@ private data class InitialSortSeriesData(
seriesType = SeriesType.Anime,
userSeriesStatus = UserSeriesStatus.Current,
startDate = "320/01/01",
endDate = "220/02/02"
endDate = "220/02/02",
rating = 10
),
val series1: SeriesEntity = createSeriesEntity(
id = 1,
Expand All @@ -154,7 +176,8 @@ private data class InitialSortSeriesData(
seriesType = SeriesType.Anime,
userSeriesStatus = UserSeriesStatus.Current,
startDate = "021/01/01",
endDate = "121/02/02"
endDate = "121/02/02",
rating = 8
),
val series2: SeriesEntity = createSeriesEntity(
id = 2,
Expand All @@ -163,7 +186,8 @@ private data class InitialSortSeriesData(
seriesType = SeriesType.Anime,
userSeriesStatus = UserSeriesStatus.Current,
startDate = "122/01/01",
endDate = "022/02/02"
endDate = "022/02/02",
rating = 7
),
val series3: SeriesEntity = createSeriesEntity(
id = 3,
Expand All @@ -172,7 +196,8 @@ private data class InitialSortSeriesData(
seriesType = SeriesType.Anime,
userSeriesStatus = UserSeriesStatus.Current,
startDate = "223/01/01",
endDate = "323/02/02"
endDate = "323/02/02",
rating = 9
)
) {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class SortOptionRobot {
*/
fun selectByEndDate() = clickOn(R.string.sort_by_end_date)

/**
* Pick the "Rating" option, requires first calling [open].
*/
fun selectByRating() = clickOn(R.string.sort_by_rating)

/**
* Executes validation steps.
* Requires opening the dialog, performing the check.
Expand Down Expand Up @@ -68,5 +73,6 @@ class SortOptionResultsRobot {
assertDisplayedAtPosition(R.id.md_recyclerview_content, 1, R.string.sort_by_title)
assertDisplayedAtPosition(R.id.md_recyclerview_content, 2, R.string.sort_by_start_date)
assertDisplayedAtPosition(R.id.md_recyclerview_content, 3, R.string.sort_by_end_date)
assertDisplayedAtPosition(R.id.md_recyclerview_content, 4, R.string.sort_by_rating)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class SeriesAdapter(
SortOption.Title -> compareBy { it.title }
SortOption.StartDate -> compareBy { it.startDate }
SortOption.EndDate -> compareBy { it.endDate }
SortOption.Rating -> compareBy { it.rating }
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ enum class SortOption(val index: Int, @StringRes val stringId: Int) {
Default(0, R.string.sort_by_default),
Title(1, R.string.sort_by_title),
StartDate(2, R.string.sort_by_start_date),
EndDate(3, R.string.sort_by_end_date);
EndDate(3, R.string.sort_by_end_date),
Rating(4, R.string.sort_by_rating);

companion object {
/**
Expand Down
1 change: 1 addition & 0 deletions libraries/core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<string name="sort_by_title">Title</string>
<string name="sort_by_start_date">Start date</string>
<string name="sort_by_end_date">End date</string>
<string name="sort_by_rating">Rating</string>

<string name="filter_dialog_title">Filter by</string>
<string name="filter_dialog_cancel">Cancel</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ class SortOptionTests {
fun `forIndex SortOption#EndDate returns expected value`() {
assertEquals(SortOption.EndDate, SortOption.forIndex(3))
}

@Test
fun `forIndex SortOption#Rating returns expected value`() {
assertEquals(SortOption.Rating, SortOption.forIndex(4))
}
}

0 comments on commit 5d0cafe

Please sign in to comment.