package net.pterodactylus.sone.web.pages
-import net.pterodactylus.sone.data.Post
-import net.pterodactylus.sone.test.mock
-import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.sone.web.pages.WebPageTest
-import net.pterodactylus.sone.web.pages.BookmarksPage
-import net.pterodactylus.util.collection.Pagination
-import org.hamcrest.MatcherAssert.assertThat
-import org.hamcrest.Matchers.contains
-import org.hamcrest.Matchers.equalTo
-import org.junit.Before
-import org.junit.Test
+import net.pterodactylus.sone.data.*
+import net.pterodactylus.sone.test.*
+import net.pterodactylus.sone.utils.*
+import net.pterodactylus.sone.web.*
+import net.pterodactylus.sone.web.page.*
+import org.hamcrest.MatcherAssert.*
+import org.hamcrest.Matchers.*
+import org.junit.*
/**
* Unit test for [BookmarksPage].
*/
-class BookmarksPageTest: WebPageTest() {
+class BookmarksPageTest : WebPageTest(::BookmarksPage) {
- private val page = BookmarksPage(template, webInterface)
private val post1 = createLoadedPost(1000)
private val post2 = createLoadedPost(3000)
private val post3 = createLoadedPost(2000)
@Before
fun setupBookmarkedPostsAndPagination() {
whenever(core.bookmarkedPosts).thenReturn(setOf(post1, post2, post3))
- core.preferences.postsPerPage = 5
+ core.preferences.newPostsPerPage = 5
}
@Test
@Test
@Suppress("UNCHECKED_CAST")
fun `page sets correct posts in template context`() {
- page.processTemplate(freenetRequest, templateContext)
- assertThat(templateContext["posts"] as Collection<Post>, contains(post2, post3, post1))
- assertThat((templateContext["pagination"] as Pagination<Post>).items, contains(post2, post3, post1))
- assertThat(templateContext["postsNotLoaded"], equalTo<Any>(false))
+ verifyNoRedirect {
+ assertThat(templateContext["posts"] as Collection<Post>, contains(post2, post3, post1))
+ assertThat((templateContext["pagination"] as Pagination<Post>).items, contains(post2, post3, post1))
+ assertThat(templateContext["postsNotLoaded"], equalTo<Any>(false))
+ }
}
@Test
@Suppress("UNCHECKED_CAST")
fun `page does not put unloaded posts in template context but sets a flag`() {
whenever(post3.isLoaded).thenReturn(false)
- page.processTemplate(freenetRequest, templateContext)
- assertThat(templateContext["posts"] as Collection<Post>, contains(post2, post1))
- assertThat((templateContext["pagination"] as Pagination<Post>).items, contains(post2, post1))
- assertThat(templateContext["postsNotLoaded"], equalTo<Any>(true))
+ verifyNoRedirect {
+ assertThat(templateContext["posts"] as Collection<Post>, contains(post2, post1))
+ assertThat((templateContext["pagination"] as Pagination<Post>).items, contains(post2, post1))
+ assertThat(templateContext["postsNotLoaded"], equalTo<Any>(true))
+ }
+ }
+
+ @Test
+ fun `bookmarks page can be created by dependency injection`() {
+ assertThat(baseInjector.getInstance<BookmarksPage>(), notNullValue())
+ }
+
+ @Test
+ fun `page is annotated with correct menuname`() {
+ assertThat(page.menuName, equalTo("Bookmarks"))
+ }
+
+ @Test
+ fun `page is annotated with correct template path`() {
+ assertThat(page.templatePath, equalTo("/templates/bookmarks.html"))
}
}