1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.test.*
5 import net.pterodactylus.sone.utils.*
6 import net.pterodactylus.sone.web.*
7 import net.pterodactylus.sone.web.page.*
8 import org.hamcrest.MatcherAssert.*
9 import org.hamcrest.Matchers.*
13 * Unit test for [BookmarksPage].
15 class BookmarksPageTest : WebPageTest(::BookmarksPage) {
17 private val post1 = createLoadedPost(1000)
18 private val post2 = createLoadedPost(3000)
19 private val post3 = createLoadedPost(2000)
21 private fun createLoadedPost(time: Long) = mock<Post>().apply {
22 whenever(isLoaded).thenReturn(true)
23 whenever(this.time).thenReturn(time)
27 fun setupBookmarkedPostsAndPagination() {
28 whenever(core.bookmarkedPosts).thenReturn(setOf(post1, post2, post3))
29 core.preferences.newPostsPerPage = 5
33 fun `page returns correct path`() {
34 assertThat(page.path, equalTo("bookmarks.html"))
38 @Suppress("UNCHECKED_CAST")
39 fun `page sets correct posts in template context`() {
41 assertThat(templateContext["posts"] as Collection<Post>, contains(post2, post3, post1))
42 assertThat((templateContext["pagination"] as Pagination<Post>).items, contains(post2, post3, post1))
43 assertThat(templateContext["postsNotLoaded"], equalTo<Any>(false))
48 @Suppress("UNCHECKED_CAST")
49 fun `page does not put unloaded posts in template context but sets a flag`() {
50 whenever(post3.isLoaded).thenReturn(false)
52 assertThat(templateContext["posts"] as Collection<Post>, contains(post2, post1))
53 assertThat((templateContext["pagination"] as Pagination<Post>).items, contains(post2, post1))
54 assertThat(templateContext["postsNotLoaded"], equalTo<Any>(true))
59 fun `bookmarks page can be created by dependency injection`() {
60 assertThat(baseInjector.getInstance<BookmarksPage>(), notNullValue())
64 fun `page is annotated with correct menuname`() {
65 assertThat(page.menuName, equalTo("Bookmarks"))
69 fun `page is annotated with correct template path`() {
70 assertThat(page.templatePath, equalTo("/templates/bookmarks.html"))