.filterNot(Album::isEmpty)
.sortedBy(Album::getTitle)
.also { albums ->
- templateContext["albums"] = albums
- templateContext["albumPagination"] = Pagination(albums, 12).apply { page = request.parameters["page"]?.toIntOrNull() ?: 0 }
+ Pagination(albums, webInterface.core.preferences.imagesPerPage).apply { page = request.parameters["page"]?.toIntOrNull() ?: 0 }.also { pagination ->
+ templateContext["albumPagination"] = pagination
+ templateContext["albums"] = pagination.items
+ }
}
} else {
templateContext["soneRequested"] = true
}
}
+ @Test
+ fun `get request for gallery can show second page`() {
+ core.preferences.imagesPerPage = 2
+ val firstSone = createSone("first album", "second album")
+ addSone("sone1", firstSone)
+ val secondSone = createSone("third album", "fourth album")
+ addSone("sone2", secondSone)
+ addHttpRequestParameter("mode", "gallery")
+ addHttpRequestParameter("page", "1")
+ verifyNoRedirect {
+ assertThat(templateContext["galleryRequested"], equalTo<Any>(true))
+ @Suppress("UNCHECKED_CAST")
+ assertThat(templateContext["albums"] as Iterable<Album>, contains(
+ firstSone.rootAlbum.albums[1],
+ secondSone.rootAlbum.albums[0]
+ ))
+ }
+ }
+
private fun createSone(firstAlbumTitle: String, secondAlbumTitle: String): Sone {
return mock<Sone>().apply {
val rootAlbum = mock<Album>()