import net.pterodactylus.sone.data.*
import net.pterodactylus.sone.test.*
+import net.pterodactylus.sone.test.Matchers.isPostWithId
import net.pterodactylus.sone.utils.*
import net.pterodactylus.sone.web.*
import net.pterodactylus.sone.web.page.*
@Test
fun `posts are not duplicated when they come from both new posts and new replies notifications`() {
+ unsetCurrentSone()
val extraPost = mock<Post>().withTime(2000)
val posts = asList(mock<Post>().withTime(1000), mock<Post>().withTime(3000))
val postReplies = asList(mock<PostReply>(), mock())
@Test
@Suppress("UNCHECKED_CAST")
fun `posts are paginated properly`() {
+ unsetCurrentSone()
webInterface.core.preferences.newPostsPerPage = 2
val posts = listOf(mock<Post>().withTime(2000), mock<Post>().withTime(3000), mock<Post>().withTime(1000))
whenever(newElements.newPosts()).thenReturn(posts)
@Test
@Suppress("UNCHECKED_CAST")
fun `posts are paginated properly on second page`() {
+ unsetCurrentSone()
webInterface.core.preferences.newPostsPerPage = 2
addHttpRequestParameter("page", "1")
val posts = listOf(mock<Post>().withTime(2000), mock<Post>().withTime(3000), mock<Post>().withTime(1000))
}
@Test
+ fun `posts are unfiltered if no current Sone is set`() {
+ unsetCurrentSone()
+ val posts = listOf(createPost(id = "post1"), createPost(id = "post2"))
+ whenever(newElements.newPosts()).thenReturn(posts)
+ verifyNoRedirect {
+ assertThat(templateContext["posts"] as Collection<Post>, containsInAnyOrder(isPostWithId("post1"), isPostWithId("post2")))
+ }
+ }
+
+ @Test
+ fun `posts are filtered if a current Sone is set`() {
+ val posts = listOf(createPost(id = "post1"), createPost(id = "post2"))
+ whenever(newElements.newPosts(currentSone)).thenReturn(posts.last().asList())
+ verifyNoRedirect {
+ assertThat(templateContext["posts"] as Collection<Post>, contains(isPostWithId("post2")))
+ }
+ }
+
+ @Test
+ fun `replies are unfiltered if no current Sone is set`() {
+ unsetCurrentSone()
+ val replies = listOf(createPostReply(id = "reply1", post = createPost(id = "post1")), createPostReply(id = "reply2", post = createPost(id = "post2")))
+ whenever(newElements.newReplies()).thenReturn(replies)
+ verifyNoRedirect {
+ assertThat(templateContext["posts"] as Collection<Post>, containsInAnyOrder(isPostWithId("post1"), isPostWithId("post2")))
+ }
+ }
+
+ @Test
+ fun `replies are filtered if a current Sone is set`() {
+ val replies = listOf(createPostReply(id = "reply1", post = createPost(id = "post1")), createPostReply(id = "reply2", post = createPost(id = "post2")))
+ whenever(newElements.newReplies(currentSone)).thenReturn(replies.last().asList())
+ verifyNoRedirect {
+ assertThat(templateContext["posts"] as Collection<Post>, contains(isPostWithId("post2")))
+ }
+ }
+
+ @Test
fun `page can be created by dependency injection`() {
assertThat(baseInjector.getInstance<NewPage>(), notNullValue())
}